Returns (lu_id, synonyms=[(word, lu_id)] ) tuple given a synset ID and a lemma
172486
def get_lu_from_synset(self, syn_id, lemma = None):
        """"""
        if not lemma:
            return self.get_lus_from_synset(syn_id) #alias
        if not isinstance(lemma,unicode):
            lemma = unicode(lemma,'utf-8')

        root = self.get_synset_xml(syn_id)
        elem_synonyms = root.find( ".//synonyms" )

        lu_id = None
        synonyms = []
        for elem_synonym in elem_synonyms:
            synonym_str = elem_synonym.get( "c_lu_id-previewtext" )        # get "c_lu_id-previewtext" attribute
            # synonym_str ends with ":<num>"
            synonym = synonym_str.split( ':' )[ 0 ].strip()

            if synonym != lemma:
                synonyms.append( (synonym, elem_synonym.get("c_lu_id")) )
                if self.debug:
                    printf( "synonym add: %s" % synonym )
            else:
                lu_id = elem_synonym.get( "c_lu_id" )        # get "c_lu_id" attribute
                if self.debug:
                    printf( "lu_id: %s" % lu_id )
                    printf( "synonym skip lemma: %s" % synonym )
        return lu_id, synonyms
1003188
def id2word(self, xs):
        
        if isinstance(xs, list):
            return [self._id2word[x] for x in xs]
        return self._id2word[xs]
1146511
def bracketedList(l, r, sep, expr, allow_missing_close=False):
  
  # We may need to backtrack for lists, because of list comprehension, but not for
  # any of the other lists
  strict = l != '['
  closer = sym(r) if not allow_missing_close else p.Optional(sym(r))
  if strict:
    return sym(l) - listMembers(sep, expr) - closer
  else:
    return sym(l) + listMembers(sep, expr) + closer
238620
def tokens2ids(tokens: Iterable[str], vocab: Dict[str, int]) -> List[int]:
    
    return [vocab.get(w, vocab[C.UNK_SYMBOL]) for w in tokens]
422010
def lemmatize(self, tokens):
        """"""
        entries = self.entries
        forms_and_lemmas = self.forms_and_lemmas

        lemma_list = [x[0] for x in entries]
        """Provide a lemma for each token"""
        lemmatized = []
        for token in tokens:
            """check for a match between token and list of lemmas"""
            if token in lemma_list:
                lemmed = (token, token)
                lemmatized.append(lemmed)
            else:
                """if no match check for a match between token and list of lemma forms"""
                lemma = [k for k, v in forms_and_lemmas.items() if token in v]
                if lemma != []:
                    lemmed = (token, lemma)
                    lemmatized.append(lemmed)
                elif lemma == []:
                    """if no match apply regular expressions and check for a match against the list of lemmas again"""
                    regexed = regex(token)
                    if regexed in lemma_list:
                        lemmed = (token, regexed)
                        lemmatized.append(lemmed)
                    else:
                        lemmed = (token, "None")
                        lemmatized.append(lemmed)
        return lemmatized
900487
def word2id(self, xs):
        
        if isinstance(xs, list):
            return [self._word2id.get(x, self.UNK) for x in xs]
        return self._word2id.get(xs, self.UNK)
1205944
def keyword(self) -> Tuple[Optional[str], str]:
        
        i1 = self.yang_identifier()
        if self.peek() == ":":
            self.offset += 1
            i2 = self.yang_identifier()
            return (i1, i2)
        return (None, i1)
311015
def _get_keywords_with_score(extracted_lemmas, lemma_to_word):
    
    keywords = {}
    for score, lemma in extracted_lemmas:
        keyword_list = lemma_to_word[lemma]
        for keyword in keyword_list:
            keywords[keyword] = score
    return keywords
1171988
def t_ID(self, t):
        '
        t.type = self.reserved_words.get(t.value, 'ID')
        return t
1284201
def get_substructure_mapping(self, other, limit=1):
        
        i = self._matcher(other).subgraph_isomorphisms_iter()
        if limit == 1:
            m = next(i, None)
            if m:
                return {v: k for k, v in m.items()}
            return
        elif limit == 0:
            return ({v: k for k, v in m.items()} for m in i)
        return [{v: k for k, v in m.items()} for m in islice(i, limit)]
594535
def relations():
    """"""
    rels = {}
    for reltype in relation_types():
        relids = {}
        for relid in relation_ids(reltype):
            units = {local_unit(): relation_get(unit=local_unit(), rid=relid)}
            for unit in related_units(relid):
                reldata = relation_get(unit=unit, rid=relid)
                units[unit] = reldata
            relids[relid] = units
        rels[reltype] = relids
    return rels
769904
def lemmatise(self, f, pos=False, get_lemma_object=False, lower=True):
        
        if lower:
            # We do not run numeral on lower
            yield from self._lemmatise_roman_numerals(f, pos=pos, get_lemma_object=get_lemma_object)

            # We run on the lower version
            if f.lower() != f:
                yield from self.lemmatise(f.lower(), pos=pos, get_lemma_object=get_lemma_object, lower=False)

        f = deramise(f)
        yield from self._lemmatise(f, pos=pos, get_lemma_object=get_lemma_object)
        yield from self._lemmatise_assims(f, pos=pos, get_lemma_object=get_lemma_object)
        yield from self._lemmatise_desassims(f, pos=pos, get_lemma_object=get_lemma_object)
        yield from self._lemmatise_contractions(f, pos=pos, get_lemma_object=get_lemma_object)

        yield from self._lemmatise_suffixe(f, pos=pos, get_lemma_object=get_lemma_object)
1285932
def __extract_lemmas(self, doc, m, phrase):
        

        ph_start = m['start']
        ph_end = m['end']
        start_index = None
        for ind, word in enumerate(doc['words']):
            if word['start'] == ph_start:
                start_index = ind
                break
        end_index = None
        for ind, word in enumerate(doc['words']):
            if word['end'] == ph_end:
                end_index = ind
                break
        if start_index is not None and end_index is not None:
            
            lem = []
                
            for i in doc['words'][start_index:end_index + 1]:
                word_lem = []
                for idx, j in enumerate(i['analysis']):
                    if i['analysis'][idx]['partofspeech'] in ['A', 'D', 'C', 'J']:
                        if i['analysis'][idx]['lemma'] not in word_lem:
                            word_lem.append(i['analysis'][idx]['lemma'])
                word_lem_str = '|'.join(word_lem)          
                lem.append(word_lem_str)

        else:
            raise Exception('Something went really wrong')
        return lem
368447
def iter_referents_tuples(self):
        
        tlow, thigh = self['targetset_arity'].get_tuple()
        clow, chigh = self['contrast_arity'].get_tuple()
        singletons = list([int(i) for i,_ in self.iter_singleton_referents()])
        t = len(singletons)
        low = int(max(1, tlow))
        high = int(min([t,  thigh]))
        for elements in itertools.chain.from_iterable(itertools.combinations(singletons, r) \
                for r in reversed(xrange(low, high+1))):
            if clow <= t-len(elements) <= chigh:
                yield  elements
1101816
def labels(self):
        
        all_labels = set(self.token_patterns.keys())
        all_labels.update(self.phrase_patterns.keys())
        return tuple(all_labels)
723533
def find(self, sought, view='lemma'):
        '''
        
        '''
        for word in self.wordlist:
            if sought == word.views[view]:
                yield word
970840
def to_d(l):
    
    _d = {}
    for x in l:
        for k, v in x.items():
            _d[k] = v
    return _d