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

Method indexof

pattern/text/tree.py:893–905  ·  view source on GitHub ↗

Returns the indices of tokens in the sentence where the given token tag equals the string. The string can contain a wildcard "*" at the end (this way "NN*" will match "NN" and "NNS"). The tag can be WORD, LEMMA, POS, CHUNK, PNP, RELATION, ROLE, ANCHOR or a custom word tag.

(self, value, tag=WORD)

Source from the content-addressed store, hash-verified

891 yield tuple([self.get(i, tag=tag) for tag in tags])
892
893 def indexof(self, value, tag=WORD):
894 """ Returns the indices of tokens in the sentence where the given token tag equals the string.
895 The string can contain a wildcard "*" at the end (this way "NN*" will match "NN" and "NNS").
896 The tag can be WORD, LEMMA, POS, CHUNK, PNP, RELATION, ROLE, ANCHOR or a custom word tag.
897 For example: Sentence.indexof("VP", tag=CHUNK)
898 returns the indices of all the words that are part of a VP chunk.
899 """
900 match = lambda a, b: a.endswith("*") and b.startswith(a[:-1]) or a==b
901 indices = []
902 for i in range(len(self.words)):
903 if match(value, unicode(self.get(i, tag))):
904 indices.append(i)
905 return indices
906
907 def slice(self, start, stop):
908 """ Returns a portion of the sentence from word start index to word stop index.

Callers

nothing calls this directly

Calls 4

getMethod · 0.95
lenFunction · 0.85
matchFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected