Finds the fuzzy matches (within edit distance 1) of w from words
512063
def query(self, w, ed=1):  # Can only handle ed=1
        
        assert ed <= self._ed
        if ed == 0:
            return [w] if w in self._L else ['']
        w = str(w)
        n = len(w)
        prefix, suffix = w[:n // 2], w[n // 2:][::-1]
        options_w_prefix = self._L.keys(prefix)
        options_w_suffix = [x[::-1] for x in self._R.iterkeys(suffix)]
        return [
            _w
            for _w in set(itertools.chain(options_w_prefix, options_w_suffix))
            if abs(len(_w) - len(w)) <= 1 and lvdistance(str(_w), str(w), 1) <= 1
        ]
261714
function getCorrection(words, match) {
	for (const word of words) {
		const pattern = getPattern(word);
		if (!getRegExp([pattern]).test(match)) {
			continue;
		}

		const corrected = match.replace(new RegExp(`\\b${pattern}`, 'i'), word);
		return matchCasing(corrected, match);
	}

	return false;
}
471399
function containsWords(wordlist, str) {
    var i;
    var matches = [];
    for (i = 0; i < wordlist.length; i++) {
        var re = new RegExp("\\b" + wordlist[i] + "\\b", "i");
        if (re.exec(str)) {
            matches.push(wordlist[i]);
        }
    }
    return matches;
}
48797
def find_regions(self, word):
        
        length = len(word)

        for index, match in enumerate(re.finditer("[aeiouy][^aeiouy]", word)):
            if index == 0:
                if match.end() < length:
                    self.r1 = match.end()
            if index == 1:
                if match.end() < length:
                    self.r2 = match.end()
                break
1275143
def get_matches(pattern, language, max_count=8):
    
    if str(pattern) == pattern:
        pattern = compile_pattern(pattern)

    results = []

    if not dicts.exists(language):
        print("The language '%s' is not available locally." % language)
        return []

    with open(dicts.filepath(language), 'r') as f:
        for word in f:
            if max_count <= 0:
                break
            w = word.strip()
            if pattern.match(w) and w not in results:
                results.append(w)
                max_count -= 1

    return results
1275310
def matches(language)
      values.select {|v|
        v = v.match(/^(.+?)-/) ? $1 : v if @first_level_match
        v == language || v == '*' || (language.match(/^(.+?)-/) && v == $1)
      }.sort {|a, b|
        # "*" gets least precedence, any others are compared based on length.
        a == '*' ? -1 : (b == '*' ? 1 : a.length <=> b.length)
      }.reverse
    end
907768
def suffix(tokens, operator_table):
    """"""
    operator, matched_tokens = operator_table.suffix.match(tokens)
    if operator:
        return TokenMatch(operator, None, matched_tokens)
299129
def word_matches(s1, s2, n=3):
    
    return __matches(s1, s2, word_ngrams, n=n)
958198
def fuzzyfinder(text, collection):
    """"""
    suggestions = []
    if not isinstance(text, six.text_type):
        text = six.u(text)
    pat = '.*?'.join(map(re.escape, text))
    regex = re.compile(pat, flags=re.IGNORECASE)
    for item in collection:
        r = regex.search(item)
        if r:
            suggestions.append((len(r.group()), r.start(), item))

    return (z for _, _, z in sorted(suggestions))
307125
def findAllMatches(self, needle, similarity):
        
        positions = []
        # Use findBestMatch to get the best match
        while True:
            best_match = self.findBestMatch(needle, similarity)
            if best_match is None: # No more matches
                break
            # Found a match. Add it to our list
            positions.append(best_match) # (position, confidence)

            # Erase the found match from the haystack.
            # Repeat this process until no other matches are found
            x, y = best_match[0]
            w = needle.shape[1]
            h = needle.shape[0]
            roi = (x, y, w, h)
            # numpy 2D slice
            roi_slice = (slice(roi[1], roi[1]+roi[3]), slice(roi[0], roi[0]+roi[2]))
            self.haystack[roi_slice] = 0

        # Whew! Let's see if there's a match after all that.
        positions.sort(key=lambda x: (x[0][1], x[0][0]))
        return positions
677853
def wsp(word):
    ''''''
    HEAVY = r'[ieaAoO]{1}[\.]*(u|y)[^ieaAoO]+(\.|$)'

    # # if the word is not monosyllabic, lop off the final syllable, which is
    # # extrametrical
    # if '.' in word:
    #     word = word[:word.rindex('.')]

    # gather the indices of syllable boundaries
    delimiters = [i for i, char in enumerate(word) if char == '.']

    if len(delimiters) % 2 != 0:
        delimiters.append(len(word))

    unstressed = []

    # gather the indices of unstressed positions
    for i, d in enumerate(delimiters):
        if i % 2 == 0:
            unstressed.extend(range(d + 1, delimiters[i + 1]))

    # find the number of unstressed heavy syllables
    heavies = re.finditer(HEAVY, word)
    violations = sum(1 for m in heavies if m.start(0) in unstressed)

    return violations
1030988
def find_exact(self, prefix):
        '''
        
        '''
        matches = self.find_all(prefix)
        if len(matches) == 1:
            match = matches.pop()
            if match.prefix == prefix:
                return match

        return None
1073895
def find_matches(self, text):
        """"""
        if self.use_main_ns:
            self.namespace = __main__.__dict__

        if "." in text:
            return self.attr_matches(text)
        else:
            return self.global_matches(text)
65286
def findClosestPronunciation(inputIsleWordList, aPron):
    '''
    
    '''
    
    retList = _findBestPronunciation(inputIsleWordList, aPron)
    isleWordList = retList[0]
    bestIndex = retList[3]
    
    return isleWordList[bestIndex]
262790
def find_previous_word_ending(self, count=1, WORD=False):
        
        if count < 0:
            return self.find_next_word_ending(count=-count, WORD=WORD)

        text_before_cursor = self.text_after_cursor[:1] + self.text_before_cursor[::-1]

        regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE
        iterator = regex.finditer(text_before_cursor)

        try:
            for i, match in enumerate(iterator):
                # Take first match, unless it's the word on which we're right now.
                if i == 0 and match.start(1) == 0:
                    count += 1

                if i + 1 == count:
                    return -match.start(1) + 1
        except StopIteration:
            pass
448850
def match(self, sentence, start=0, _v=None, _u=None):
        
        if sentence.__class__.__name__ == "Sentence":
            pass
        elif isinstance(sentence, list) or sentence.__class__.__name__ == "Text":
            return find(lambda m,s: m is not None, ((self.match(s, start, _v), s) for s in sentence))[0]
        elif isinstance(sentence, basestring):
            sentence = Sentence(sentence)
        elif isinstance(sentence, Match) and len(sentence) > 0:
            sentence = sentence[0].sentence.slice(sentence[0].index, sentence[-1].index + 1)
        # Variations (_v) further down the list may match words more to the front.
        # We need to check all of them. Unmatched variations are blacklisted (_u).
        # Pattern.search() calls Pattern.match() with a persistent blacklist (1.5x faster).
        a = []
        for sequence in (_v is not None and _v or self._variations()):
            if _u is not None and id(sequence) in _u:
                continue
            m = self._match(sequence, sentence, start)
            if m is not None:
                a.append((m.words[0].index, len(m.words), m))
            if m is not None and m.words[0].index == start:
                return m
            if m is None and _u is not None:
                _u[id(sequence)] = False
        # Return the leftmost-longest.
        if len(a) > 0:
            return sorted(a)[0][-1]
519718
private int matchAnyToOne(final int wordIndex, final int candIndex) {
    if (replacementsAnyToOne.containsKey(candidate[candIndex])) {
      for (final char[] rep : replacementsAnyToOne.get(candidate[candIndex])) {
        int i = 0;
        while (i < rep.length && (wordIndex + i) < wordLen && rep[i] == wordProcessed[wordIndex + i]) {
          i++;
        }
        if (i == rep.length) {
          return i;
        }
      }
    }
    return 0;
  }