def _eval_one(self, gold_inst: Sent, pred_inst: Sent): conf: DparEvalConf = self.conf # assert gold_inst.id == pred_inst.id, "Err: SentID mismatch!" # assert gold_inst.seq_word.vals == pred_inst.seq_word.vals, "Err: sent text mismatch!" # -- gold_tokens = gold_inst.get_tokens() pred_tokens = pred_inst.get_tokens() assert len(gold_tokens) == len(pred_tokens) if conf.exclude_punct: res = DparEvalResult(conf, [ (a, b) for a, b in zip(gold_tokens, pred_tokens) if a.upos != "PUNCT" ]) else: res = DparEvalResult(conf, [(a, b) for a, b in zip(gold_tokens, pred_tokens)]) return res
def span2feat(self, sent: Sent, widx: int, wlen: int): # from a span to feat # def span2feat(self, sent: Sent, widx: int, wlen: int, try_head=True): # from a span to feat conf: LexConstrainerConf = self.conf hwidx = self.hf.find_shead(sent, widx, wlen) # try to find head word if conf.use_fn_style: hpos = sent.seq_upos.vals[hwidx] lu_name = " ".join(sent.seq_lemma.vals[widx:widx+wlen]).lower() + "." \ + UD2FN_POS_MAP.get(hpos, hpos.lower()) feat = self.lu2feat(lu_name) else: tokens = sent.get_tokens(widx, widx + wlen) feat = " ".join([self.lex_feat_f(t) for t in tokens]) # my own feat! # special try_head if not found # if try_head and wlen>0 and feat not in self.cmap: # return self.span2feat(sent, hwidx, 1, False) return feat
def feat_toks(self, s: Sent): sent_toks = s.get_tokens() sent_tok_feats = [self.feat_tok_f(t) for t in sent_toks] return sent_toks, sent_tok_feats