def __init__(self, mentions=None, news_sentences_models=None): """ :param mentions: """ if mentions is not None: if all(isinstance(m, MentionModel) for m in mentions): self.mentions = _add_relation(self.mentions, mentions) elif all(isinstance(m, Mention) for m in mentions) and news_sentences_models is not None: self.mentions = _add_relation(self.mentions, [MentionModel( start=m.start, end=m.end, head=m.head, tokens=news_sentences_models[m.sentence - 1].get_tokens(m.start, m.end)) for m in mentions] )
def add_desc_eval(self, desc_eval): """ :type desc_eval: DescEval :param desc_eval: :return: """ return _add_relation(self.desc_eval_list, desc_eval)
def add_mwe_model(self, mwe=None): """ :param mwe: :return: """ if isinstance(mwe, InstrumentedList): self.mwes_model = _add_relation(self.mwes_model, mwe) return self.mwes_model
def add_coreference(self, coref): """ :param coref: :return: """ if coref is not None and coref: if self.coreferences is None or coref not in self.coreferences: self.coreferences = _add_relation(self.coreferences, coref)
def add_mention(self, mention): """ :param mention: :return: """ if mention is not None and mention: if self.mentions is not None or mention not in self.mentions: self.mentions = _add_relation(self.mentions, mention) return self.mentions
def add_sentence(self, sentence): """ :type sentence: app.align_module.base_model.Sentence :param sentence: :return: """ if sentence is not None and sentence: if self.sentences is None or sentence not in self.sentences: self.sentences = _add_relation(self.sentences, sentence) return self.sentences
def add_tokenized(self, token): """ :type token: app.align_module.base_model.Token :param token: :return: """ if token is not None and token: if self.tokenized is not None or token not in self.tokenized: self.tokenized = _add_relation(self.tokenized, token) return self.tokenized
def add_alignments(self, alignment=None): """ Add alignment to a group :param alignment: alignment object :type alignment: Alignment :return: list of all alignments """ if alignment is not None and alignment: if self.list_alignments is None or alignment not in self.list_alignments: self.list_alignments = _add_relation(self.list_alignments, alignment) return self.list_alignments
def add_mwe(self, mwe=None): """ Add mwe to an alignment :param mwe: multi-word expression containing self.term :return: a list of all multi-word expressions """ if mwe is not None: if self.list_mwe is None or mwe not in self.list_mwe: new_mwe = MWE(mwe) # self.list_mwe = _add(self.list_mwe, new_mwe) self.mwes_model = _add_relation(self.mwes_model, new_mwe) self.has_mwe = bool(self.mwes_model) return self.mwes_model
def add_sentence(self, sentence=None): """ :type sentence: app.align_module.base_model.Sentence, list :param sentence: :return: """ if sentence is not None and sentence: if self.belongs_sentence is None or \ ((isinstance(sentence, list) and all(s not in self.belongs_sentence for s in sentence)) or (isinstance(sentence, Sentence) and sentence not in self.belongs_sentence)): self.belongs_sentence = _add_relation(self.belongs_sentence, sentence) return self.belongs_sentence
def add_syn(self, syn=None, snt=None): """ Add syn to an alignment :param syn: synonym of self.term :return: a list of all synonyms """ if syn is not None and syn: if self.list_syns is None or syn not in self.list_syns: new_syn = Synonym(syn) if snt is not None: new_syn.add_sentence(sentence=snt) # self.list_syns = _add(self.list_syns, ) self.syns_model = _add_relation(self.syns_model, new_syn) self.has_syns = bool(self.list_syns) return self.syns_model
def add_from_zip_list(self, tkn_snt_list): """ :param tkn_snt_list: :return: """ for index, (snt, tknized) in enumerate(tkn_snt_list): if index == 0: label = 'title' elif index == 1: label = 'subtitle' else: label = 'text' snt_model = Sentence(text=snt, label=label) for tkn in tknized: tkn_model = Token(tkn.marshal()) snt_model.add_tokenized(tkn_model) # _add_session(tkn_model) self.sentences = _add_relation(self.sentences, snt_model)
def add_from_coref_objects(self, coref_object): """ :param coref_object: list :return: """ coref: Coreference for coref in coref_object: _coref_model = CoreferenceModel() _mention_list = [] for mention in coref.get_mentions(): _sentence = self.get_sentence_index(index=int(mention.sentence) - 1) _tokens = _sentence.get_tokens(start=mention.start, end=mention.end ) _m = MentionModel( start=mention.start, head=mention.head, end=mention.end, tokens=InstrumentedList(_tokens) ) _mention_list.append(_m) _coref_model.add_mention(_mention_list) self.coreferences = _add_relation(self.coreferences, _coref_model)
def add_tokens(self, tokens): if tokens is not None and tokens: if self.tokens is not None or tokens not in self.tokens: self.tokens = _add_relation(self.tokens, tokens) return self.tokens
def add_sentence(self, sentence=None): return _add_relation(self.belongs_sentence, sentence)
def add_amr(self, amr): return _add_relation(self.amr_list, amr)