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

Function compile

pattern/text/search.py:868–885  ·  view source on GitHub ↗

Returns a Pattern from the given string or regular expression. Recently compiled patterns are kept in cache.

(pattern, *args, **kwargs)

Source from the content-addressed store, hash-verified

866_cache = {}
867_CACHE_SIZE = 100 # Number of dynamic Pattern objects to keep in cache.
868def compile(pattern, *args, **kwargs):
869 """ Returns a Pattern from the given string or regular expression.
870 Recently compiled patterns are kept in cache.
871 """
872 id, p = repr(pattern)+repr(args), None
873 if id in _cache:
874 return _cache[id]
875 if isinstance(pattern, basestring):
876 p = Pattern.fromstring(pattern, *args, **kwargs)
877 if isinstance(pattern, regexp):
878 p = Pattern([Constraint(words=[pattern], taxonomy=kwargs.get("taxonomy", TAXONOMY))], *args, **kwargs)
879 if len(_cache) > _CACHE_SIZE:
880 _cache.clear()
881 if isinstance(p, Pattern):
882 _cache[id] = p
883 return p
884 else:
885 raise TypeError, "can't compile '%s' object" % pattern.__class__.__name__
886
887def match(pattern, sentence, *args, **kwargs):
888 """ Returns the first match found in the given sentence, or None.

Callers 2

matchFunction · 0.85
searchFunction · 0.85

Calls 6

PatternClass · 0.85
ConstraintClass · 0.85
lenFunction · 0.85
fromstringMethod · 0.45
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…