MCPcopy Index your code
hub / github.com/clips/pattern / test_fromstring

Method test_fromstring

test/test_search.py:158–214  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

156 self.assertEqual(constraint.taxonomy, kwargs.get("taxonomy", search.taxonomy))
157
158 def test_fromstring(self):
159 # Assert Constraint string syntax.
160 for s, kwargs in (
161 ( "cats", dict( words = ["cats"])),
162 ( "Cat*", dict( words = ["cat*"])),
163 ( "\\[cat\\]", dict( words = ["[cat]"])),
164 ("[black cats]", dict( words = ["black cats"])),
165 ( "black_cats", dict( words = ["black cats"])),
166 ("black\\_cats", dict( words = ["black_cats"])),
167 ( "NNS", dict( tags = ["NNS"])),
168 ( "NN*|VB*", dict( tags = ["NN*", "VB*"])),
169 ( "NP", dict(chunks = ["NP"])),
170 ( "SBJ", dict( roles = ["SBJ"])),
171 ( "CATS", dict( taxa = ["cats"])),
172 ( "cats?", dict( words = ["cats"], optional=True)),
173 ( "(cats)", dict( words = ["cats"], optional=True)),
174 ( "\\(cats\\)", dict( words = ["(cats)"])),
175 ( "cats+", dict( words = ["cats"], multiple=True)),
176 ( "cats\\+", dict( words = ["cats+"])),
177 ( "cats+dogs", dict( words = ["cats+dogs"])),
178 ( "(cats+)", dict( words = ["cats"], optional=True, multiple=True)),
179 ( "(cats)+", dict( words = ["cats"], optional=True, multiple=True)),
180 ( "cats+?", dict( words = ["cats"], optional=True, multiple=True)),
181 ( "cats?+", dict( words = ["cats"], optional=True, multiple=True)),
182 ( "^[fat cat]?", dict( words = ["fat cat"], first=True, optional=True)),
183 ( "[^fat cat?]", dict( words = ["fat cat"], first=True, optional=True)),
184 ( "cats\\|dogs", dict( words = ["cats|dogs"])),
185 ( "cats|dogs", dict( words = ["cats", "dogs"])),
186 ( "^cat", dict( words = ["cat"], first=True)),
187 ( "\\^cat", dict( words = ["^cat"])),
188 ( "(cat*)+", dict( words = ["cat*"], optional=True, multiple=True)),
189 ( "^black_cat+", dict( words = ["black cat"], multiple=True, first=True)),
190 ( "black\[cat", dict( words = ["black[cat"])),
191 ( "black\(cat", dict( words = ["black(cat"])),
192 ( "black\{cat", dict( words = ["black{cat"])),
193 ( "black\|cat", dict( words = ["black|cat"])),
194 ( "black\!cat", dict( words = ["black!cat"])),
195 ( "black\^cat", dict( words = ["black^cat"])),
196 ( "black\+cat", dict( words = ["black+cat"])),
197 ( "black\?cat", dict( words = ["black?cat"])),
198 ( "cats|NN*", dict( words = ["cats"], tags=["NN*"]))):
199 self._test_constraint(search.Constraint.fromstring(s), **kwargs)
200 # Assert non-alpha taxonomy items.
201 t = search.Taxonomy()
202 t.append("0.5", type="0.5")
203 t.append("half", type="0.5")
204 v = search.Constraint.fromstring("0.5", taxonomy=t)
205 # Assert non-alpha words without taxonomy.
206 self.assertTrue(v.taxa == ["0.5"])
207 v = search.Constraint.fromstring("0.5")
208 # Assert exclude Constraint.
209 self.assertTrue(v.words == ["0.5"])
210 v = search.Constraint.fromstring("\\!cats|!dogs|!fish")
211 self.assertTrue(v.words == ["!cats"])
212 self.assertTrue(v.exclude.words == ["dogs", "fish"])
213 print "pattern.search.Constraint.fromstring"
214 print "pattern.search.Constraint.fromstring"
215

Callers

nothing calls this directly

Calls 3

_test_constraintMethod · 0.95
appendMethod · 0.95
fromstringMethod · 0.45

Tested by

no test coverage detected