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

Method constituents

pattern/text/search.py:951–982  ·  view source on GitHub ↗

Returns a list of Word and Chunk objects, where words have been grouped into their chunks whenever possible. Optionally, returns only chunks/words that match given constraint(s), or constraint index.

(self, constraint=None)

Source from the content-addressed store, hash-verified

949 return b
950
951 def constituents(self, constraint=None):
952 """ Returns a list of Word and Chunk objects,
953 where words have been grouped into their chunks whenever possible.
954 Optionally, returns only chunks/words that match given constraint(s), or constraint index.
955 """
956 # Select only words that match the given constraint.
957 # Note: this will only work with constraints from Match.pattern.sequence.
958 W = self.words
959 n = len(self.pattern.sequence)
960 if isinstance(constraint, (int, Constraint)):
961 if isinstance(constraint, int):
962 i = constraint
963 i = i<0 and i%n or i
964 else:
965 i = self.pattern.sequence.index(constraint)
966 W = self._map2.get(i,[])
967 W = [self.words[i-self.words[0].index] for i in W]
968 if isinstance(constraint, (list, tuple)):
969 W = []; [W.extend(self._map2.get(j<0 and j%n or j,[])) for j in constraint]
970 W = [self.words[i-self.words[0].index] for i in W]
971 W = unique(W)
972 a = []
973 i = 0
974 while i < len(W):
975 w = W[i]
976 if w.chunk and W[i:i+len(w.chunk)] == w.chunk.words:
977 i += len(w.chunk) - 1
978 a.append(w.chunk)
979 else:
980 a.append(w)
981 i += 1
982 return a
983
984 def group(self, index, chunked=False):
985 """ Returns a list of Word objects that match the given group.

Callers 7

groupMethod · 0.95
test_match_functionMethod · 0.45
test_matchMethod · 0.45
08-web.pyFile · 0.45
04-taxonomy.pyFile · 0.45
03-lemmata.pyFile · 0.45

Calls 6

lenFunction · 0.85
uniqueFunction · 0.70
indexMethod · 0.45
getMethod · 0.45
extendMethod · 0.45
appendMethod · 0.45

Tested by 3

test_match_functionMethod · 0.36
test_matchMethod · 0.36