Ejemplo n.º 1
0
 def test_parse_pb(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     assert sentence.text == u"Barack Hussein Obama is an American politician who is the 44th and current President of the United States."
     assert len(sentence) == 19
     assert sentence[1].word == "Hussein"
     assert sentence[1].ner == "PERSON"
Ejemplo n.º 2
0
 def test_parse_pb(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     assert sentence.text == u"Barack Hussein Obama is an American politician who is the 44th and current President of the United States."
     assert len(sentence) == 19
     assert sentence[1].word == "Hussein"
     assert sentence[1].ner == "PERSON"
Ejemplo n.º 3
0
 def test_depparse(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     dp = sentence.depparse()
     assert dp.roots == [6] # politician
     assert (2, 'nsubj') in dp.children(6) # Obama is child of politician
     assert (3, 'cop') in dp.children(6) # 'is' is ia copula
     assert (0, 'compound') in dp.children(2) # 'Barack' is part of the compount that is Obama.
Ejemplo n.º 4
0
 def test_depparse(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     dp = sentence.depparse()
     assert dp.roots == [6] # politician
     assert (2, 'nsubj') in dp.children(6) # Obama is child of politician
     assert (3, 'cop') in dp.children(6) # 'is' is ia copula
     assert (0, 'compound') in dp.children(2) # 'Barack' is part of the compount that is Obama.
Ejemplo n.º 5
0
 def test_depparse_json(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     dp = sentence.depparse()
     edges = dp.to_json()
     # politician is root
     assert any((edge['dep'] == 'root' and edge['dependent'] == 7 and edge['dependentgloss'] == 'politician') for edge in edges)
     # Obama is child of politician
     assert any((edge['governer'] == 7 and edge['dep'] == 'nsubj' and edge['dependent'] == 3 and edge['dependentgloss'] == 'Obama') for edge in edges)
     # 'is' is ia copula
     assert any((edge['governer'] == 7 and edge['dep'] == 'cop' and edge['dependent'] == 4 and edge['dependentgloss'] == 'is') for edge in edges)
     # 'Barack' is part of the compount that is Obama.
     assert any((edge['governer'] == 3 and edge['dep'] == 'compound' and edge['dependent'] == 1 and edge['dependentgloss'] == 'Barack') for edge in edges)
Ejemplo n.º 6
0
 def test_depparse_json(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     dp = sentence.depparse()
     edges = dp.to_json()
     # politician is root
     assert any((edge['dep'] == 'root' and edge['dependent'] == 7 and edge['dependentgloss'] == 'politician') for edge in edges)
     # Obama is child of politician
     assert any((edge['governer'] == 7 and edge['dep'] == 'nsubj' and edge['dependent'] == 3 and edge['dependentgloss'] == 'Obama') for edge in edges)
     # 'is' is ia copula
     assert any((edge['governer'] == 7 and edge['dep'] == 'cop' and edge['dependent'] == 4 and edge['dependentgloss'] == 'is') for edge in edges)
     # 'Barack' is part of the compount that is Obama.
     assert any((edge['governer'] == 3 and edge['dep'] == 'compound' and edge['dependent'] == 1 and edge['dependentgloss'] == 'Barack') for edge in edges)
Ejemplo n.º 7
0
 def test_depparse_json(self, document_pb):
     sentence_pb = document_pb.sentence[0]
     sentence = AnnotatedSentence.from_pb(sentence_pb)
     dp = sentence.depparse()
     edges = dp.to_json()
     # politician is root
     assert any(
         (edge["dep"] == "root" and edge["dependent"] == 7 and edge["dependentgloss"] == "politician")
         for edge in edges
     )
     # Obama is child of politician
     assert any(
         (
             edge["governer"] == 7
             and edge["dep"] == "nsubj"
             and edge["dependent"] == 3
             and edge["dependentgloss"] == "Obama"
         )
         for edge in edges
     )
     # 'is' is ia copula
     assert any(
         (
             edge["governer"] == 7
             and edge["dep"] == "cop"
             and edge["dependent"] == 4
             and edge["dependentgloss"] == "is"
         )
         for edge in edges
     )
     # 'Barack' is part of the compount that is Obama.
     assert any(
         (
             edge["governer"] == 3
             and edge["dep"] == "compound"
             and edge["dependent"] == 1
             and edge["dependentgloss"] == "Barack"
         )
         for edge in edges
     )