text stringlengths 0 828 |
|---|
else: |
# named entity |
if text[1:-1] not in skip: |
try: |
text = unichr( |
html_entities.name2codepoint[text[1:-1]]) \ |
.encode(""utf-8"") |
except KeyError: |
pass |
return text # leave as is |
return re.sub(""&#?\w+;"", fixup, text)" |
4213,"def strip_accents(x): |
u""""""Strip accents in the input phrase X. |
Strip accents in the input phrase X (assumed in UTF-8) by replacing |
accented characters with their unaccented cousins (e.g. é by e). |
:param x: the input phrase to strip. |
:type x: string |
:return: Return such a stripped X. |
"""""" |
x = re_latex_lowercase_a.sub(""a"", x) |
x = re_latex_lowercase_ae.sub(""ae"", x) |
x = re_latex_lowercase_oe.sub(""oe"", x) |
x = re_latex_lowercase_e.sub(""e"", x) |
x = re_latex_lowercase_i.sub(""i"", x) |
x = re_latex_lowercase_o.sub(""o"", x) |
x = re_latex_lowercase_u.sub(""u"", x) |
x = re_latex_lowercase_y.sub(""x"", x) |
x = re_latex_lowercase_c.sub(""c"", x) |
x = re_latex_lowercase_n.sub(""n"", x) |
x = re_latex_uppercase_a.sub(""A"", x) |
x = re_latex_uppercase_ae.sub(""AE"", x) |
x = re_latex_uppercase_oe.sub(""OE"", x) |
x = re_latex_uppercase_e.sub(""E"", x) |
x = re_latex_uppercase_i.sub(""I"", x) |
x = re_latex_uppercase_o.sub(""O"", x) |
x = re_latex_uppercase_u.sub(""U"", x) |
x = re_latex_uppercase_y.sub(""Y"", x) |
x = re_latex_uppercase_c.sub(""C"", x) |
x = re_latex_uppercase_n.sub(""N"", x) |
# convert input into Unicode string: |
try: |
y = unicode(x, ""utf-8"") |
except Exception: |
return x # something went wrong, probably the input wasn't UTF-8 |
# asciify Latin-1 lowercase characters: |
y = re_unicode_lowercase_a.sub(""a"", y) |
y = re_unicode_lowercase_ae.sub(""ae"", y) |
y = re_unicode_lowercase_oe.sub(""oe"", y) |
y = re_unicode_lowercase_e.sub(""e"", y) |
y = re_unicode_lowercase_i.sub(""i"", y) |
y = re_unicode_lowercase_o.sub(""o"", y) |
y = re_unicode_lowercase_u.sub(""u"", y) |
y = re_unicode_lowercase_y.sub(""y"", y) |
y = re_unicode_lowercase_c.sub(""c"", y) |
y = re_unicode_lowercase_n.sub(""n"", y) |
y = re_unicode_lowercase_ss.sub(""ss"", y) |
# asciify Latin-1 uppercase characters: |
y = re_unicode_uppercase_a.sub(""A"", y) |
y = re_unicode_uppercase_ae.sub(""AE"", y) |
y = re_unicode_uppercase_oe.sub(""OE"", y) |
y = re_unicode_uppercase_e.sub(""E"", y) |
y = re_unicode_uppercase_i.sub(""I"", y) |
y = re_unicode_uppercase_o.sub(""O"", y) |
y = re_unicode_uppercase_u.sub(""U"", y) |
y = re_unicode_uppercase_y.sub(""Y"", y) |
y = re_unicode_uppercase_c.sub(""C"", y) |
y = re_unicode_uppercase_n.sub(""N"", y) |
# return UTF-8 representation of the Unicode string: |
return y.encode(""utf-8"")" |
4214,"def slugify(text, delim=u'-'): |
""""""Generate an ASCII-only slug."""""" |
result = [] |
for word in _punct_re.split(text.lower()): |
result.extend(unidecode(word).split()) |
return unicode(delim.join(result))" |
4215,"def show_diff(original, modified, prefix='', suffix='', |
prefix_unchanged=' ', |
suffix_unchanged='', |
prefix_removed='-', |
suffix_removed='', |
prefix_added='+', |
suffix_added=''): |
""""""Return the diff view between original and modified strings. |
Function checks both arguments line by line and returns a string |
with a: |
- prefix_unchanged when line is common to both sequences |
- prefix_removed when line is unique to sequence 1 |
- prefix_added when line is unique to sequence 2 |
and a corresponding suffix in each line |
:param original: base string |
:param modified: changed string |
:param prefix: prefix of the output string |
:param suffix: suffix of the output string |
:param prefix_unchanged: prefix of the unchanged line |
:param suffix_unchanged: suffix of the unchanged line |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.