def test_attributes(self): lang = Nlp('en') treat = lang.attributes("I am a doggy !") assert isinstance(treat, list) assert treat[0] == [0, 1, 2, 3, 4] assert treat[1] == ['I', 'am', 'a', 'doggy', '!'] assert treat[2] == ['nsubj', 'ROOT', 'det', 'attr', 'punct'] assert treat[3] == [True, True, True, True, False] assert treat[4] == [False, False, False, False, True] assert treat[5] == [False, False, False, False, False]
def test_french(self): """Test Nlp.french() returns a list""" lang = Nlp('fr') french = lang.french('Coucou, ça va ?') assert isinstance(french, list)
def test_named_entities(self): lang = Nlp('en') treat = lang.named_entities('I work at Apple and Google') assert treat == [('Apple', 'ORG'), ('Google', 'ORG')]
def test_percentages(self): lang = Nlp('en') treat = lang.check_percentages('hello, 50%') assert treat == 'percentage : 50 %'
def test_get_slice(self): """Test Nlp.get_slice() returns str""" lang = Nlp('en') treat = lang.get_slice('Hello kitty cat', 1, 4) assert isinstance(treat, str) assert treat == 'kitty cat'
def test_get_index(self): """Test Nlp.get_index() returns str""" lang = Nlp('en') treat = lang.get_index('hi i am a kitty') assert isinstance(treat, str)
def test_english(self): """Test Nlp.english() returns a list""" lang = Nlp('en') en = lang.english('hello, whats up ?') assert isinstance(en, list)
from helloworld import Nlp from match import Match if __name__ == '__main__': # init class with english or french language # 'fr' or 'en' nlp = Nlp(lang='en') nlp_matcher = Match() if nlp.lang == 'fr': print(nlp.french('Bonjour, je suis un chaton')) print(nlp.get_index("Chaton très mignon !")) print(nlp.get_slice("Chaton très mignon !", 1, 4)) else: print(nlp.english('Hi ! Im Abd')) print(nlp.get_index("Cute Kitten !")) print(nlp.get_slice("Cute Kitten !", 1, 4)) print(nlp.attributes("I am a doggy !")) print(nlp.check_percentages('There is 90% of population that...')) print(nlp.named_entities('I work at Google')) nlp_matcher.process_pattern_on_input( 'Hello, I love to listen to Nina Simone !', [{ 'TEXT': 'Nina' }, { 'TEXT': 'Simone' }]) nlp_matcher.match_lexical_attr('2018 FIFA World Cup: France won!')