def main(args): goldF = args.goldfile sysFs = args.sysfile ss_mapper = lambda ss: coarsen_pss(ss, args.depth) if ss.startswith( 'p.') else ss # Load gold data gold_sents = list(load_sents(goldF, ss_mapper=ss_mapper)) for sent in gold_sents: sent['punits'] = { tuple(e['toknums']): (e['lexcat'], e['ss'], e['ss2']) for e in list(sent['swes'].values()) + list(sent['smwes'].values()) if e['ss'] and (e['ss'].startswith('p.') or e['ss'] == '??') } all_sys_scores = {} for sysF in sysFs: sysscores = eval_sys(sysF, gold_sents, ss_mapper) syspath = sysF.name basename = syspath.rsplit('.', 2)[0] if basename not in all_sys_scores: all_sys_scores[basename] = [ defaultdict(lambda: defaultdict(Counter)), defaultdict(lambda: defaultdict(Counter)) ] if syspath.split('.')[-2] == 'goldid': all_sys_scores[basename][0] = sysscores else: all_sys_scores[basename][1] = sysscores # Print output args.output_format(all_sys_scores, depth=args.depth)
def main(args): goldF = args.goldfile sysFs = args.sysfile ss_mapper = lambda ss: coarsen_pss(ss, args.depth) if ss.startswith( 'p.') else ss # Load gold data gold_sents = list(load_sents(goldF, ss_mapper=ss_mapper)) all_sys_scores = {} for sysF in sysFs: sysscores = eval_sys(sysF, gold_sents, ss_mapper) syspath = sysF.name basename = syspath.rsplit('.', 2)[0] if basename not in all_sys_scores: all_sys_scores[basename] = [ defaultdict(lambda: defaultdict(Counter)), defaultdict(lambda: defaultdict(Counter)) ] if syspath.split('.')[-2] == 'goldid': all_sys_scores[basename][0] = sysscores else: all_sys_scores[basename][1] = sysscores # Print output args.output_format(all_sys_scores, depth=args.depth, mode=args.output_mode)
def __call__(self, ss): return coarsen_pss(ss, self.depth) if ss.startswith('p.') else ss
def ss_mapper(ss): return coarsen_pss(ss, DEPTH) if ss.startswith('p.') else ss
def main(args): if args.colorless or not sys.stdin.isatty(): for c in dir(Colors): if not c.startswith('_'): setattr(Colors, c, '') for s in dir(Styles): if not s.startswith('_'): setattr(Styles, s, '') goldF = args.goldfile sysFs = args.sysfile ss_mapper = lambda ss: coarsen_pss(ss, args.depth) if ss.startswith('p.') else ss # Load gold data gold_sents = list(load_sents(goldF, ss_mapper=ss_mapper)) predFs = [load_sents(predFP, ss_mapper=ss_mapper) for predFP in sysFs] all_sys_scores = {} def filter_labels(ll): result = dict(ll) for k,l in ll.items(): if l.startswith('n.') and args.no_noun: del result[k] elif l.startswith('v.') and args.no_verb: del result[k] elif l.startswith('p.') and args.no_snacs: del result[k] return result R = lambda ww,sg,wg,ll: render(ww, sg if not args.no_mwe else [], wg if not args.no_mwe else [], filter_labels(ll)) for i,sent in enumerate(gold_sents): # gold analysis words = [t["word"] for t in sent["toks"]] rendered = [] rendered.append(R(words, [e["toknums"] for e in sent["smwes"].values()], [e["toknums"] for e in sent["wmwes"].values()], makelabelmap(sent, include_lexcat=args.lexcats, include_supersenses=True))) for predF in predFs: psent = next(predF) assert psent['sent_id']==sent['sent_id'] rendered.append(R(words, [e["toknums"] for e in psent["smwes"].values()], [e["toknums"] for e in psent["wmwes"].values()], makelabelmap(sent, include_lexcat=args.lexcats, include_supersenses=True))) diff_classes = set() if not args.no_diff: diff_classes.add('special') if not args.no_mwe_diff: diff_classes.add('mwe') if not args.no_noun_diff: diff_classes.add('n') if not args.no_snacs_diff: diff_classes.add('p') if not args.no_verb_diff: diff_classes.add('v') if args.sent_ids: print(sent['sent_id'], end='\t') print(color_rendered(words, rendered, diff_classes)) #assert False,(color_rendered(words, rendered),words,rendered) # restore the terminal's default colors print(Colors.ENDC, end='')
def ss_mapper(supersense): return coarsen_pss(supersense, DEPTH) if supersense.startswith('p.') else supersense