def clean(self, e): lemma, lemma_pos, lemma_context, lemma_type, lemma_hid = self.l_node(e) tgs, ts = self.tg_nodes(e) ui_lang = self.query_kwargs.get('ui_lang') _right = map(lambda tg: self.clean_tg_node(e, tg), tgs) right_langs = [lang for _, lang in _right] right_nodes = [fmt_node for fmt_node, _ in _right] entry_hash = hash_node(e) # node, and default format for if a formatter doesn't exist for # iso source_lang = self.query_kwargs.get('source_lang') target_lang = self.query_kwargs.get('target_lang') lemma_attrs = self.query_kwargs.get('lemma_attrs', False) if lemma and lemma_pos: default_format = "%s (%s)" % ( lemma, tagfilter(lemma_pos, source_lang, target_lang)) elif lemma and not lemma_pos: default_format = lemma elif lemma_attrs: default_format = '' def add_link(_p): """ If there's a link already, then don't add one, otherwise... """ return _p source_formatted_unlinked = lexicon_overrides.format_source( source_lang, ui_lang, e, target_lang, default_format) source_formatted = add_link(source_formatted_unlinked) formatted_dict = { 'left': lemma, 'source_formatted': source_formatted, 'source_unlinked': source_formatted_unlinked, 'context': lemma_context, 'pos': lemma_pos, 'right': right_nodes, 'lang': right_langs, 'hid': lemma_hid, 'entry_hash': entry_hash, 'input': (lemma, lemma_pos, '', lemma_type), 'node': e } formatted_dict.update(self.additional_template_kwargs) return formatted_dict
def filterPOSAndTag(analysis): filtered_pos = tagfilter(analysis.pos, from_language, to_language) joined = ' '.join(analysis.tag) return (analysis.lemma, joined)
def clean(self, e): lemma, lemma_pos, lemma_context, lemma_type, lemma_hid = self.l_node(e) tgs, ts = self.tg_nodes(e) ui_lang = self.query_kwargs.get('ui_lang') _right = map(lambda tg: self.clean_tg_node(e, tg), tgs) right_langs = [lang for _, lang in _right] right_nodes = [fmt_node for fmt_node, _ in _right] # # Make our own hash, 'cause lxml won't # entry_hash = [ unicode(lemma) # , unicode(lemma_context) # , unicode(lemma_pos) # , ','.join(sorted([t['tx'] for t in right_nodes])) # ] # entry_hash = str('-'.join(entry_hash).__hash__()) entry_hash = hash_node(e) # node, and default format for if a formatter doesn't exist for # iso source_lang = self.query_kwargs.get('source_lang') target_lang = self.query_kwargs.get('target_lang') lemma_attrs = self.query_kwargs.get('lemma_attrs', False) if lemma and lemma_pos: default_format = "%s (%s)" % ( lemma, tagfilter(lemma_pos, source_lang, target_lang)) elif lemma and not lemma_pos: default_format = lemma elif lemma_attrs: default_format = '' def add_link(_p): """ If there's a link already, then don't add one, otherwise... """ if '<a ' in _p or '</a>' in _p: return _p # TODO: will need a more lasting solution... src_lang = self.query_kwargs.get('source_lang') if src_lang == 'SoMe': src_lang = 'sme' _url = [ 'detail', src_lang, self.query_kwargs.get('target_lang'), '%s.html?e_node=%s' % (lemma, entry_hash) ] _url = '/' + '/'.join(_url) link = "<a href='%s'>%s</a>" % (_url, _p) return link source_formatted_unlinked = lexicon_overrides.format_source( source_lang, ui_lang, e, target_lang, default_format) source_formatted = add_link(source_formatted_unlinked) formatted_dict = { 'left': lemma, 'source_formatted': source_formatted, 'source_unlinked': source_formatted_unlinked, 'context': lemma_context, 'pos': lemma_pos, 'right': right_nodes, 'lang': right_langs, 'hid': lemma_hid, 'entry_hash': entry_hash } formatted_dict.update(self.additional_template_kwargs) return formatted_dict
def fixTag(t): t_pos = t.get('pos', False) if not t_pos: return t t['pos'] = tagfilter(t_pos, _from, _to) return t
def tagfilter_by(tag_string, _f, _t, tagset, **kwargs): from morphology.utils import tagfilter return tagfilter(tag_string, _f, _t, tagset=tagset, **kwargs)
def tagfilter_generation(*args, **kwargs): from morphology.utils import tagfilter kwargs['generation'] = True return tagfilter(*args, **kwargs)
def tagfilter(*args, **kwargs): from morphology.utils import tagfilter return tagfilter(*args, **kwargs)
def filter_tag(f): filtered_tag = tagfilter(f.tag, g._from, g._to).split(' ') return (f.input, filtered_tag, [f.form], f.tag.tag_string)