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

Method match

pattern/text/search.py:756–779  ·  view source on GitHub ↗

Returns the first match found in the given sentence, or None.

(self, sentence, start=0, _v=None, _u=None)

Source from the content-addressed store, hash-verified

754 return a
755
756 def match(self, sentence, start=0, _v=None, _u=None):
757 """ Returns the first match found in the given sentence, or None.
758 """
759 if sentence.__class__.__name__ == "Text":
760 return find(lambda (m,s): m!=None, ((self.match(s, start, _v), s) for s in sentence))[0]
761 if isinstance(sentence, basestring):
762 sentence = Sentence(sentence)
763 # Variations (_v) further down the list may match words more to the front.
764 # We need to check all of them. Unmatched variations are blacklisted (_u).
765 # Pattern.search() calls Pattern.match() with a persistent blacklist (1.5x faster).
766 a = []
767 for sequence in (_v is not None and _v or self._variations()):
768 if _u is not None and id(sequence) in _u:
769 continue
770 m = self._match(sequence, sentence, start)
771 if m is not None:
772 a.append((m.words[0].index, len(m.words), m))
773 if m is not None and m.words[0].index == start:
774 return m
775 if m is None and _u is not None:
776 _u[id(sequence)] = False
777 # Return the leftmost-longest.
778 if len(a) > 0:
779 return sorted(a)[0][-1]
780
781 def _variations(self):
782 v = variations(self.sequence, optional=lambda constraint: constraint.optional)

Callers 14

searchMethod · 0.95
_formatFunction · 0.45
csv_header_decodeFunction · 0.45
applyMethod · 0.45
find_tokensFunction · 0.45
find_tagsFunction · 0.45
__call__Method · 0.45
search.pyFile · 0.45
matchMethod · 0.45
_matchMethod · 0.45
matchFunction · 0.45
test_matchMethod · 0.45

Calls 6

_variationsMethod · 0.95
_matchMethod · 0.95
lenFunction · 0.85
findFunction · 0.70
SentenceClass · 0.70
appendMethod · 0.45

Tested by 3

test_matchMethod · 0.36
test_matchMethod · 0.36
test_match_functionMethod · 0.36