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

Method classify

pattern/text/search.py:300–314  ·  view source on GitHub ↗

Returns the (most recently added) semantic type for the given term ("many" => "quantity"). If the term is not in the dictionary, try Taxonomy.classifiers.

(self, term, **kwargs)

Source from the content-addressed store, hash-verified

298 self._values[term] = value
299
300 def classify(self, term, **kwargs):
301 """ Returns the (most recently added) semantic type for the given term ("many" => "quantity").
302 If the term is not in the dictionary, try Taxonomy.classifiers.
303 """
304 term = self._normalize(term)
305 if dict.__contains__(self, term):
306 return self[term][0].keys()[-1]
307 # If the term is not in the dictionary, check the classifiers.
308 # Returns the first term in the list returned by a classifier.
309 for classifier in self.classifiers:
310 # **kwargs are useful if the classifier requests extra information,
311 # for example the part-of-speech tag.
312 v = classifier.parents(term, **kwargs)
313 if v:
314 return v[0]
315
316 def parents(self, term, recursive=False, **kwargs):
317 """ Returns a list of all semantic types for the given term.

Callers 3

test_taxonomyMethod · 0.95
test_classifierMethod · 0.95

Calls 4

_normalizeMethod · 0.95
parentsMethod · 0.80
__contains__Method · 0.45
keysMethod · 0.45

Tested by 3

test_taxonomyMethod · 0.76
test_classifierMethod · 0.76