-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from LuminosoInsight/gender-neutral-at
Recognize "@" in gender-neutral word endings as part of the token
- Loading branch information
Showing
56 changed files
with
36,676 additions
and
35,956 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
|
||
setup( | ||
name="wordfreq", | ||
version='2.1.0', | ||
version='2.2.0', | ||
maintainer='Luminoso Technologies, Inc.', | ||
maintainer_email='[email protected]', | ||
url='http://github.com/LuminosoInsight/wordfreq/', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from wordfreq import tokenize, lossy_tokenize, word_frequency | ||
|
||
|
||
def test_gender_neutral_at(): | ||
# Recognize the gender-neutral @ in Spanish as part of the word | ||
text = "La protección de los derechos de tod@s l@s trabajador@s migrantes" | ||
assert tokenize(text, "es") == [ | ||
"la", | ||
"protección", | ||
"de", | ||
"los", | ||
"derechos", | ||
"de", | ||
"tod@s", | ||
"l@s", | ||
"trabajador@s", | ||
"migrantes" | ||
] | ||
|
||
text = "el distrito 22@ de Barcelona" | ||
assert tokenize(text, 'es') == ["el", "distrito", "22@", "de", "barcelona"] | ||
assert lossy_tokenize(text, 'es') == ["el", "distrito", "00@", "de", "barcelona"] | ||
|
||
# It also appears in Portuguese | ||
text = "direitos e deveres para @s membr@s da comunidade virtual" | ||
assert tokenize(text, "pt") == [ | ||
"direitos", | ||
"e", | ||
"deveres", | ||
"para", | ||
"@s", | ||
"membr@s", | ||
"da", | ||
"comunidade", | ||
"virtual" | ||
] | ||
|
||
# Because this is part of our tokenization, the language code doesn't | ||
# actually matter, as long as it's a language with Unicode tokenization | ||
text = "@s membr@s da comunidade virtual" | ||
assert tokenize(text, "en") == ["@s", "membr@s", "da", "comunidade", "virtual"] | ||
|
||
|
||
def test_at_in_corpus(): | ||
# We have a word frequency for "l@s" | ||
assert word_frequency('l@s', 'es') > 0 | ||
|
||
# It's not just treated as a word break | ||
assert word_frequency('l@s', 'es') < word_frequency('l s', 'es') | ||
|
||
|
||
def test_punctuation_at(): | ||
# If the @ appears alone in a word, we consider it to be punctuation | ||
text = "operadores de canal, que são aqueles que têm um @ ao lado do nick" | ||
assert tokenize(text, "pt") == [ | ||
"operadores", | ||
"de", | ||
"canal", | ||
"que", | ||
"são", | ||
"aqueles", | ||
"que", | ||
"têm", | ||
"um", | ||
"ao", | ||
"lado", | ||
"do", | ||
"nick" | ||
] | ||
|
||
assert tokenize(text, "pt", include_punctuation=True) == [ | ||
"operadores", | ||
"de", | ||
"canal", | ||
",", | ||
"que", | ||
"são", | ||
"aqueles", | ||
"que", | ||
"têm", | ||
"um", | ||
"@", | ||
"ao", | ||
"lado", | ||
"do", | ||
"nick" | ||
] | ||
|
||
# If the @ is not at the end of the word or part of the word ending '@s', | ||
# it is also punctuation | ||
text = "un archivo hosts.deny que contiene la línea ALL:ALL@ALL" | ||
assert tokenize(text, "es") == [ | ||
"un", | ||
"archivo", | ||
"hosts.deny", | ||
"que", | ||
"contiene", | ||
"la", | ||
"línea", | ||
"all:all", | ||
"all" | ||
] | ||
|
||
# Make sure not to catch e-mail addresses | ||
text = "[email protected]" | ||
assert tokenize(text, "en") == [ | ||
"info", | ||
"something.example" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.