Add an acronym to the dictionary.

    Takes care of avoiding duplicates and keeping the expansion marked with
    the best score.
340688
def _add_expansion_to_acronym_dict(acronym, expansion, level, dictionary):
    
    if len(acronym) >= len(expansion) or acronym in expansion:
        return

    for punctuation in re.findall("\W", expansion):
        # The expansion contains non-basic punctuation. It is probable
        # that it is invalid. Discard it.
        if punctuation not in (",", " ", "-"):
            return False

    if acronym in dictionary:
        add = True
        for stored_expansion, stored_level in dictionary[acronym]:
            if _equivalent_expansions(stored_expansion, expansion):
                if level < stored_level:
                    dictionary[acronym].remove(
                        (stored_expansion, stored_level))
                    break
                else:
                    add = False
        if add:
            dictionary[acronym].append((expansion, level))
            return True
    else:
        dictionary.setdefault(acronym, []).append((expansion, level))
        return True

    return False
1107407
public void addAnonymousFunctions() {
    TreeSet<SymbolScope> scopes = new TreeSet<>(lexicalScopeOrdering);
    for (SymbolScope scope : getAllScopes()) {
      if (scope.isLexicalScope()) {
        scopes.add(scope);
      }
    }

    for (SymbolScope scope : scopes) {
      addAnonymousFunctionsInScope(scope);
    }
  }
252633
def _advanced_acronym_detection(s, i, words, acronyms):
    
    # Combine each letter into single string.
    acstr = ''.join(words[s:i])

    # List of ranges representing found acronyms.
    range_list = []
    # Set of remaining letters.
    not_range = set(range(len(acstr)))

    # Search for each acronym in acstr.
    for acronym in acronyms:
        # TODO: Sanitize acronyms to include only letters.
        rac = regex.compile(unicode(acronym))

        # Loop until all instances of the acronym are found,
        # instead of just the first.
        n = 0
        while True:
            m = rac.search(acstr, n)
            if not m:
                break

            a, b = m.start(), m.end()
            n = b

            # Make sure found acronym doesn't overlap with others.
            ok = True
            for r in range_list:
                if a < r[1] and b > r[0]:
                    ok = False
                    break

            if ok:
                range_list.append((a, b))
                for j in xrange(a, b):
                    not_range.remove(j)

    # Add remaining letters as ranges.
    for nr in not_range:
        range_list.append((nr, nr + 1))

    # No ranges will overlap, so it's safe to sort by lower bound,
    # which sort() will do by default.
    range_list.sort()

    # Remove original letters in word list.
    for _ in xrange(s, i):
        del words[s]

    # Replace them with new word grouping.
    for j in xrange(len(range_list)):
        r = range_list[j]
        words.insert(s + j, acstr[r[0]:r[1]])

    return s + len(range_list) - 1
801115
def add_label(self, doc, label, update_index=True):
        
        label = copy.copy(label)
        assert(label in self.labels.values())
        doc.add_label(label)
        if update_index:
            self.upd_doc(doc)
            self.commit()
456881
def check_abbreviation_unique(self, abbreviation, newFilterPattern, targetItem):
        
        for item in self.allFolders:
            if model.TriggerMode.ABBREVIATION in item.modes:
                if abbreviation in item.abbreviations and item.filter_matches(newFilterPattern):
                    return item is targetItem, item
            
        for item in self.allItems:
            if model.TriggerMode.ABBREVIATION in item.modes:
                if abbreviation in item.abbreviations and item.filter_matches(newFilterPattern):
                    return item is targetItem, item

        return True, None
164273
def _get_acronyms(acronyms):
    """"""
    acronyms_str = {}
    if acronyms:
        for acronym, expansions in iteritems(acronyms):
            expansions_str = ", ".join(["%s (%d)" % expansion
                                        for expansion in expansions])
            acronyms_str[acronym] = expansions_str

    return [{'acronym': str(key), 'expansion': value.encode('utf8')}
            for key, value in acronyms_str.iteritems()]
1056006
def add_section(self, section, friendly_name = None):
  """"""
  if not isinstance(section, BASESTRING): # Make sure the user isn't expecting to use something stupid as a key.
   raise ValueError(section)
  # See if we've got this section already:
  if section in self.config:
   raise DuplicateSectionError(section) # Yep... Kick off.
  else:
   self.config[section] = OrderedDict() # Nope... Ad it
   if friendly_name == None:
    friendly_name = section.title()
   if '&' not in friendly_name:
    friendly_name = '&' + friendly_name
   self.section_names[section] = friendly_name
916389
protected function addDictionaryInformation()
    {
        $translations = [];
        $this->dictionary->removeAllEntries();
        $this->getDictionaryInformation($this->manialink, $translations);

        foreach ($translations as $msgId => $messages) {
            foreach ($messages as $message) {
                $this->dictionary->setEntry($message['Lang'], $msgId, htmlspecialchars($message['Text']));
            }
        }
    }
1049422
private void updateIgnoredWordDictionary() {
    wordsToBeIgnoredDictionary = wordsToBeIgnored
                                   .stream()
                                   .collect(Collectors.groupingBy(s -> s.substring(0,1), Collectors.toSet()));
    wordsToBeIgnoredDictionaryIgnoreCase = wordsToBeIgnored
                                             .stream()
                                             .map(String::toLowerCase)
                                             .collect(Collectors.groupingBy(s -> s.substring(0,1), Collectors.toSet()));
  }
37682
function createAbbreviationModel(abbreviation, editor) {
	try {
		const ast = parseAbbreviation(abbreviation, editor);
		return {
			ast,
			abbreviation,
			snippet: expandAbbreviation(abbreviation, editor)
		};
	} catch (err) {
		return null;
	}
}
976223
def update_abbreviations(apps, schema_editor):
    

    # Get model managers
    Group = apps.get_model("representatives", "Group")

    # Abbreviation mapping
    amap = {
        u'SenComCult': u'Culture',
        u'SenComEco': u'Économie',
        u'SenComDef': u'Défense',
        u'SenComEU': u'Europe',
        u'SenComSoc': u'Social',
        u'SenComFin': u'Finances',
        u'SenComLois': u'Lois',
        u'SenComDevD': u'',
        u'SenComAppL': u'',
        u'AnComCult': u'Culture',
        u'AnComEco': u'Économie',
        u'AnComEtrg': u'Étranger',
        u'AnComDef': u'Défense',
        u'AnComEU': u'Europe',
        u'AnComSoc': u'Social',
        u'AnComFin': u'Finances',
        u'AnComLois': u'Lois',
        u'AnComDevD': u'',
        u'AnComImmu': u'',
    }

    for old, new in amap.iteritems():
        for g in Group.objects.filter(abbreviation=old):
            g.abbreviation = new
            g.save()
446067
function addWord(word) {

    var branch = this.root;
    var stopSearchOnCurrentBranch = false;
    var newNode;

    while (!stopSearchOnCurrentBranch) {
      var wordContainsThePrefix = false;
      var isCase3 = false;
      var case2Result;

      //Looks for how branch it should follow
      for (var b in branch.branches) {

        //Case 1: current node prefix == `word`
        if(this._tryCase1(branch, word, b)) {
          return;
        }

        //Case 2: `word` begins with current node prefix to add
        //Cuts the word and goes to the next branch
        case2Result = this._tryCase2(branch, word, b);
        if(case2Result) {
          word = case2Result.word;
          branch = case2Result.branch;
          wordContainsThePrefix = true;
          break;
        }

        //Case 3: current node prefix begins with part of or whole `word`
        if(this._tryCase3(branch, word, b)) {
          isCase3 = stopSearchOnCurrentBranch = wordContainsThePrefix = true;
          break;
        }
      }

      //Case 4: current node prefix doesn't have intersection with `word`
      if(this._tryCase4(branch, word, wordContainsThePrefix)) {
        stopSearchOnCurrentBranch = true;
      }
    }
  }
1022255
public void addSegDict(Collection<String> al) {
		for(String s: al){
			addDict(s);
		}
		createIndex();
	}
1119128
def _add_word(completer):
    
    def inner(word: str):
        completer.words.add(word)
    return inner
349259
def add(self, word):
        """"""
        if not word or word.strip() == '':
            return
        self.words[word]=word
1036925
private void expandTo(int wordIndex)
  {
    int wordsRequired = wordIndex + 1;
    if (firstEmptyWord < wordsRequired) {
      ensureCapacity(wordsRequired);
      firstEmptyWord = wordsRequired;
    }
  }
808757
private void expandAffixes(String pluralCount) {
        // expandAffix() will set currencyChoice to a non-null value if
        // appropriate AND if it is null.
        currencyChoice = null;

        // Reuse one StringBuffer for better performance
        StringBuffer buffer = new StringBuffer();
        if (posPrefixPattern != null) {
            expandAffix(posPrefixPattern, pluralCount, buffer);
            positivePrefix = buffer.toString();
        }
        if (posSuffixPattern != null) {
            expandAffix(posSuffixPattern, pluralCount, buffer);
            positiveSuffix = buffer.toString();
        }
        if (negPrefixPattern != null) {
            expandAffix(negPrefixPattern, pluralCount, buffer);
            negativePrefix = buffer.toString();
        }
        if (negSuffixPattern != null) {
            expandAffix(negSuffixPattern, pluralCount, buffer);
            negativeSuffix = buffer.toString();
        }
    }