Esempio n. 1
0

# Word replacing using synonym yaml file
from replacers import YamlWordReplacer
replacer = YamlWordReplacer('synonyms.yaml')
print replacer.replace('bday')
print replacer.replace('happy')
print replacer.replace('hbd')
print replacer.replace('ttyl')


# Replacing antonyms
from replacers import AntonymReplacer
replacer = AntonymReplacer()
print replacer.replace('good')
print replacer.replace('uglify')
sent = "let's not uglify our code"
print " ".join(replacer.replace_negations(sent.split()))


# Replacing antonyms using word map
from replacers import AntonymWordReplacer
replacer = AntonymWordReplacer({'evil': 'good'})
sent = 'good is not evil'
print " ".join(replacer.replace_negations(sent.split()))





Esempio n. 2
0
dPWL = enchant.DictWithPWL('en_US', 'mywords.txt')
replacer = CustomSpellingReplacer(dPWL)

print(not dUS.check('nltk'))
print(dPWL.check('nltk'))
print(replacer.replace('nltk') == 'nltk')

print('=================================')
print('Replacing Negations with Antonyms')
print('=================================')

replacer = AntonymReplacer()
print(replacer.replace('good') is None)
print(replacer.replace('uglify') == 'beautify')
sent = ["let's", 'not', 'uglify', 'our', 'code']
print(replacer.replace_negations(sent) == ["let's", 'beautify', 'our', 'code'])

replacer = AntonymWordReplacer({'evil': 'good'})
print(
    replacer.replace_negations(['good', 'is', 'not', 'evil']) ==
    ['good', 'is', 'good'])

# NLP_w_Python Ch 9

print('============================================')
print('Detecting and Converting Character Encodings')
print('============================================')

print(
    unicodedata.normalize('NFKD', u'abcd\xe9').encode('ascii', 'ignore') ==
    b'abcde')