Ejemplo n.º 1
0
  public static void fillInParseAnnotations(
      boolean verbose, boolean buildGraphs, CoreMap sentence, Tree tree) {
    // make sure all tree nodes are CoreLabels
    // TODO: why isn't this always true? something fishy is going on
    ParserAnnotatorUtils.convertToCoreLabels(tree);

    // index nodes, i.e., add start and end token positions to all nodes
    // this is needed by other annotators down stream, e.g., the NFLAnnotator
    tree.indexSpans(0);

    sentence.set(TreeAnnotation.class, tree);
    if (verbose) {
      System.err.println("Tree is:");
      tree.pennPrint(System.err);
    }

    if (buildGraphs) {
      // generate the dependency graph
      SemanticGraph deps = generateCollapsedDependencies(tree);
      SemanticGraph uncollapsedDeps = generateUncollapsedDependencies(tree);
      SemanticGraph ccDeps = generateCCProcessedDependencies(tree);
      if (verbose) {
        System.err.println("SDs:");
        System.err.println(deps.toString("plain"));
      }
      sentence.set(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class, deps);
      sentence.set(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class, uncollapsedDeps);
      sentence.set(
          SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class, ccDeps);
    }

    setMissingTags(sentence, tree);
  }
Ejemplo n.º 2
0
  @Override
  public Tuple parse(
      IndexedWord gov, IndexedWord dep, SemanticGraph depGraph, Tuple t, Set<IndexedWord> visited) {
    getPOSString(gov, dep);

    Tuple t1;
    /*
     * Check for LeafNode
     */
    if (depGraph.getChildren(dep).size() > 0) {
      t1 = parse(dep, depGraph, visited);
    } else {
      Entity e = new Entity(dep.word(), EntityType.Notion);
      t1 = new Tuple(e);
    }
    String s = depGraph.getEdge(gov, dep).getRelation().getSpecific();
    Relation r = new Relation(s, RelationType.One2One);

    if (t == null) {
      Entity e1 = new Entity(gov.word(), EntityType.Object);
      Tuple t2 = new Tuple(e1);
      t = new Tuple(t1, r, t2);
    } else {
      t = new Tuple(t1, r, t);
    }
    logger.info(t.toString());
    return t;
  }
Ejemplo n.º 3
0
  private void evaluate(
      String normalizedSentence, String originalSentence, String entity1, String entity2)
      throws FileNotFoundException, UnsupportedEncodingException {
    List<RelationInstance> instances = null;

    try {
      instances = relationExtraction.extractRelations(normalizedSentence, true);
      if (instances.size() > 0) {
        CoreMap sentence = instances.get(0).getAnnotatedSentence();
        SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
        System.out.println("========== Sentence =========");
        System.out.println(sentence.toString());
        if (dependencies != null) System.out.println(dependencies.toFormattedString());
        System.out.println("======= N-ary Instaces ======");
        for (RelationInstance instance : instances) {
          System.out.println(instance);
        }
      }

      instances = extractBinaryRelations(instances);

    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Resuming...");
    }

    boolean relationMatched = false;

    String concatenatedRelations = "";

    if (instances != null && instances.size() > 0) {

      System.out.println("======= Binary Instaces ======");

      for (RelationInstance instance : instances) {

        System.out.println("Instance: " + instance.getOriginalRelation());

        boolean containMention1 = false;
        boolean containMention2 = false;

        for (Argument arg : instance.getArguments()) {
          System.out.println("\tArg: [" + arg.getEntityId() + "] - Type: " + arg.getArgumentType());
          // .endsWith() (previously .contains()) is a hack for bad annotated entities in the ground
          // truth, such as Andre [[[Agassi]]].
          if (arg.getEntityName().endsWith(PLACEHOLDER_ENTITY1)) {
            containMention1 = true;
          }

          if (arg.getEntityName().endsWith(PLACEHOLDER_ENTITY2)) {
            containMention2 = true;
          }
        }

        if (containMention1 && containMention2) {
          if (concatenatedRelations.isEmpty()) {
            concatenatedRelations = instance.getOriginalRelation();
          } else {
            // concatenatedRelations += " ,, " + instance.getOriginalRelation();
            concatenatedRelations += " " + instance.getOriginalRelation();
          }

          relationMatched = true;
        }
      }
    }

    if (!relationMatched) {
      ps.println(entity1 + "\t---\t" + entity2 + "\t" + originalSentence);
    } else {
      ps.println(
          entity1 + "\t" + concatenatedRelations.trim() + "\t" + entity2 + "\t" + originalSentence);
    }
  }