Exemplo n.º 1
0
def hilight_disagreement(test_amrs,
                         gold_amr,
                         iter_num,
                         aligner=default_aligner,
                         gold_aligned_fh=None):
    """
  Input:
    gold_amr: gold AMR object
    test_amrs: list of AMRs to compare to
  Returns list of disagreement graphs for each gold-test AMR pair.
  """

    amr_graphs = []
    smatchgraphs = []
    gold_label = u'b'
    gold_amr.rename_node(gold_label)
    (gold_inst, gold_rel1, gold_rel2) = gold_amr.get_triples2()
    (gold_inst_t, gold_rel1_t,
     gold_rel2_t) = smatch_graph.amr2dict(gold_inst, gold_rel1, gold_rel2)

    for a in test_amrs:
        aligner.set_amrs(a, gold_amr)
        test_label = u'a'
        a.rename_node(test_label)
        (test_inst, test_rel1, test_rel2) = a.get_triples2()
        if gold_aligned_fh:
            best_match = get_next_gold_alignments(gold_aligned_fh)
            best_match_num = -1.0
        else:
            (best_match, best_match_num) = smatch.get_fh(
                test_inst,
                test_rel1,
                test_rel2,
                gold_inst,
                gold_rel1,
                gold_rel2,
                test_label,
                gold_label,
                node_weight_fn=aligner.node_weight_fn,
                edge_weight_fn=aligner.edge_weight_fn,
                iter_num=iter_num)

        disagreement = SmatchGraph(test_inst, test_rel1, test_rel2, \
          gold_inst_t, gold_rel1_t, gold_rel2_t, \
          best_match, const_map_fn=aligner.const_map_fn)
        amr_graphs.append(
            (disagreement.smatch2graph(node_weight_fn=aligner.node_weight_fn,
                                       edge_weight_fn=aligner.edge_weight_fn),
             best_match_num))
        smatchgraphs.append(disagreement)
    return (amr_graphs, smatchgraphs)
Exemplo n.º 2
0
def hilight_disagreement(test_amrs,
                         gold_amr,
                         iter_num,
                         aligner=default_aligner,
                         gold_aligned_fh=None):
    """
  Input:
    test_amrs: list of AMRs to compare to
    gold_amr: gold AMR object
    iter_num: Number of random restarts to use in smatch algorithm.
  Returns list of disagreement graphs for each gold-test AMR pair.
  """

    smatchgraphs = []
    gold_label = u'b'
    gold_amr.rename_node(gold_label)
    (gold_inst, gold_rel1, gold_rel2) = gold_amr.get_triples2()
    (gold_inst_t, gold_rel1_t,
     gold_rel2_t) = smatch_graph.amr2dict(gold_inst, gold_rel1, gold_rel2)
    # TODO Also compute the weight score if we read gold alignments in from file
    # TODO This would require me to handle constants when we read from file

    for a in test_amrs:
        aligner.set_amrs(a, gold_amr)
        test_label = u'a'
        a.rename_node(test_label)
        (test_inst, test_rel1, test_rel2) = a.get_triples2()
        if gold_aligned_fh:
            best_match = get_next_gold_alignments(gold_aligned_fh)
            best_match_num = -1.0
        else:
            (best_match, best_match_num) = smatch.get_fh(
                test_inst,
                test_rel1,
                test_rel2,
                gold_inst,
                gold_rel1,
                gold_rel2,
                test_label,
                gold_label,
                node_weight_fn=aligner.node_weight_fn,
                edge_weight_fn=aligner.edge_weight_fn,
                iter_num=iter_num)

        disagreement = SmatchGraph(test_inst, test_rel1, test_rel2, \
          gold_inst_t, gold_rel1_t, gold_rel2_t, \
          best_match, const_map_fn=aligner.const_map_fn)
        smatchgraphs.append((disagreement, best_match_num))
    return smatchgraphs
Exemplo n.º 3
0
def hilight_disagreement(test_amrs, gold_amr, iter_num, aligner=default_aligner, gold_aligned_fh=None):
  """
  Input:
    gold_amr: gold AMR object
    test_amrs: list of AMRs to compare to
  Returns list of disagreement graphs for each gold-test AMR pair.
  """

  amr_graphs = []
  smatchgraphs = []
  gold_label=u'b'
  gold_amr.rename_node(gold_label)
  (gold_inst, gold_rel1, gold_rel2) = gold_amr.get_triples2()
  (gold_inst_t, gold_rel1_t, gold_rel2_t) = smatch_graph.amr2dict(gold_inst, gold_rel1, gold_rel2)

  for a in test_amrs:
    aligner.set_amrs(a, gold_amr)
    test_label=u'a'
    a.rename_node(test_label)
    (test_inst, test_rel1, test_rel2) = a.get_triples2()
    if gold_aligned_fh:
      best_match = get_next_gold_alignments(gold_aligned_fh)
      best_match_num = -1.0
    else:
      (best_match, best_match_num) = smatch.get_fh(test_inst, test_rel1, test_rel2,
        gold_inst, gold_rel1, gold_rel2,
        test_label, gold_label,
        node_weight_fn=aligner.node_weight_fn, edge_weight_fn=aligner.edge_weight_fn,
        iter_num=iter_num)

    disagreement = SmatchGraph(test_inst, test_rel1, test_rel2, \
      gold_inst_t, gold_rel1_t, gold_rel2_t, \
      best_match, const_map_fn=aligner.const_map_fn)
    amr_graphs.append((disagreement.smatch2graph(node_weight_fn=aligner.node_weight_fn,
                                                 edge_weight_fn=aligner.edge_weight_fn),
      best_match_num))
    smatchgraphs.append(disagreement)
  return (amr_graphs, smatchgraphs)
Exemplo n.º 4
0
def hilight_disagreement(test_amrs, gold_amr, iter_num, aligner=default_aligner, gold_aligned_fh=None):
  """
  Input:
    test_amrs: list of AMRs to compare to
    gold_amr: gold AMR object
    iter_num: Number of random restarts to use in smatch algorithm.
  Returns list of disagreement graphs for each gold-test AMR pair.
  """

  smatchgraphs = []
  gold_label=u'b'
  gold_amr.rename_node(gold_label)
  (gold_inst, gold_rel1, gold_rel2) = gold_amr.get_triples2()
  (gold_inst_t, gold_rel1_t, gold_rel2_t) = smatch_graph.amr2dict(gold_inst, gold_rel1, gold_rel2)
  # TODO Also compute the weight score if we read gold alignments in from file
  # TODO This would require me to handle constants when we read from file

  for a in test_amrs:
    aligner.set_amrs(a, gold_amr)
    test_label=u'a'
    a.rename_node(test_label)
    (test_inst, test_rel1, test_rel2) = a.get_triples2()
    if gold_aligned_fh:
      best_match = get_next_gold_alignments(gold_aligned_fh)
      best_match_num = -1.0
    else:
      (best_match, best_match_num) = smatch.get_fh(test_inst, test_rel1, test_rel2,
        gold_inst, gold_rel1, gold_rel2,
        test_label, gold_label,
        node_weight_fn=aligner.node_weight_fn, edge_weight_fn=aligner.edge_weight_fn,
        iter_num=iter_num)

    disagreement = SmatchGraph(test_inst, test_rel1, test_rel2, \
      gold_inst_t, gold_rel1_t, gold_rel2_t, \
      best_match, const_map_fn=aligner.const_map_fn)
    smatchgraphs.append((disagreement, best_match_num))
  return smatchgraphs