forked from rock3125/enhanced-subject-verb-object-extraction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subject_verb_object_extract_test.py
182 lines (152 loc) · 7.31 KB
/
subject_verb_object_extract_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Copyright 2017 Peter de Vocht
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from subject_verb_object_extract import findSVOs, printDeps, nlp
# test the subject/verb/object_extraction
class SubjectVerbOjectExtractTest(unittest.TestCase):
def __init__(self, methodName: str):
unittest.TestCase.__init__(self, methodName)
# test
def test_svo_1(self):
tok = nlp("the annoying person that was my boyfriend hit me")
svos = findSVOs(tok)
printDeps(tok) # just show what printDeps() does
self.assertTrue(set(svos) == {('the annoying person', 'was', 'my boyfriend'), ('the annoying person', 'hit', 'me')})
def test_svo_2(self):
tok = nlp("making $12 an hour? where am i going to go? I have no other financial assistance available and he certainly won't provide support.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('I', '!have', 'other financial assistance available'), ('he', '!provide', 'support')})
def test_svo_3(self):
tok = nlp("I don't have other assistance")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('I', '!have', 'other assistance')})
def test_svo_4(self):
tok = nlp("They ate the pizza with anchovies.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('They', 'ate', 'the pizza')})
def test_svo_5(self):
tok = nlp("I have no other financial assistance available and he certainly won't provide support.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('I', '!have', 'other financial assistance available'), ('he', '!provide', 'support')})
def test_svo_6(self):
tok = nlp("I have no other financial assistance available, and he certainly won't provide support.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('I', '!have', 'other financial assistance available'),
('he', '!provide', 'support')})
def test_svo_7(self):
tok = nlp("he did not kill me")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', '!kill', 'me')})
def test_svo_8(self):
tok = nlp("he is an evil man that hurt my child and sister")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'is', 'an evil man'),
('an evil man', 'hurt', 'my child'),
('an evil man', 'hurt', 'sister')})
def test_svo_9(self):
tok = nlp("he told me i would die alone with nothing but my career someday")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'told', 'me')})
def test_svo_10(self):
tok = nlp("I wanted to kill him with a hammer.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('I', 'kill', 'him')})
def test_svo_11(self):
tok = nlp("because he hit me and also made me so angry I wanted to kill him with a hammer.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'hit', 'me'), ('I', 'kill', 'him')})
def test_svo_12(self):
tok = nlp("he and his brother shot me")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'shot', 'me'), ('his brother', 'shot', 'me')})
def test_svo_13(self):
tok = nlp("he and his brother shot me and my sister")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'shot', 'me'), ('he', 'shot', 'my sister'),
('his brother', 'shot', 'me'), ('his brother', 'shot', 'my sister')})
def test_svo_14(self):
tok = nlp("the boy raced the girl who had a hat that had spots.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('the boy', 'raced', 'the girl'), ('who', 'had', 'a hat'),
('a hat', 'had', 'spots')})
def test_svo_15(self):
tok = nlp("he spit on me")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'spit', 'me')})
def test_svo_16(self):
tok = nlp("he didn't spit on me")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', '!spit', 'me')})
def test_svo_17(self):
tok = nlp("the boy raced the girl who had a hat that didn't have spots.")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('the boy', 'raced', 'the girl'), ('who', 'had', 'a hat'),
('a hat', '!have', 'spots')})
def test_svo_18(self):
tok = nlp("he is a nice man that didn't hurt my child and sister")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', 'is', 'a nice man'), ('a nice man', '!hurt', 'my child'),
('a nice man', '!hurt', 'sister')})
def test_svo_19(self):
tok = nlp("he didn't spit on me and my child")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', '!spit', 'me'), ('he', '!spit', 'my child')})
def test_svo_20(self):
tok = nlp("he didn't spit on me or my child")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', '!spit', 'me'), ('he', '!spit', 'my child')})
def test_svo_21(self):
tok = nlp("he didn't spit on me nor my child")
svos = findSVOs(tok)
# printDeps(tok)
self.assertTrue(set(svos) == {('he', '!spit', 'me'), ('he', '!spit', 'my child')})
def test_svo_22(self):
tok = nlp("he beat and hurt me")
# printDeps(tok)
svos = findSVOs(tok)
self.assertTrue(set(svos) == {('he', 'beat', 'me'), ('he', 'hurt', 'me')})
def test_svo_23(self):
tok = nlp("I was beaten by him")
# printDeps(tok)
svos = findSVOs(tok)
self.assertTrue(set(svos) == {('him', 'beat', 'I')})
def test_svo_24(self):
tok = nlp("lessons were taken by me")
# printDeps(tok)
svos = findSVOs(tok)
self.assertTrue(set(svos) == {('me', 'take', 'lessons')})
def test_svo_25(self):
tok = nlp("Seated in Mission Control, Chris Kraft neared the end of a tedious Friday afternoon as he monitored a seemingly interminable ground test of the Apollo 1 spacecraft.")
# printDeps(tok)
svos = findSVOs(tok)
self.assertTrue(set(svos) == {('Chris Kraft', 'neared', 'the end of a tedious Friday afternoon'), ('he', 'monitored', 'a interminable ground test of the Apollo spacecraft')})