Esempio n. 1
0
  // Do not allow POBJ-POBJ binary relations
  public List<RelationInstance> extractBinaryRelations(List<RelationInstance> instanceList) {
    List<RelationInstance> newInstanceList = new ArrayList<RelationInstance>();

    for (RelationInstance instance : instanceList) {
      for (Argument arg1 : instance.getArguments()) {
        for (Argument arg2 : instance.getArguments()) {
          if (arg1 == arg2) continue;

          if (arg1.getArgumentType().equals("SUBJ")) {
            if (arg1 == arg2) continue;
            if (arg2.getArgumentType().equals("DOBJ")
                || arg2.getArgumentType().startsWith("POBJ")
                || arg2.getArgumentType().equals("SUBJ")) {
              newInstanceList.add(createBinaryInstance(instance, arg1, arg2));
            }
          }
          if (arg1.getArgumentType().equals("DOBJ")) {
            if (arg1 == arg2) continue;
            if (arg2.getArgumentType().startsWith("POBJ")
                || arg2.getArgumentType().equals("DOBJ")) {
              newInstanceList.add(createBinaryInstance(instance, arg1, arg2));
            }
          }
        }
      }
    }

    return newInstanceList;
  }
Esempio n. 2
0
 private RelationInstance createBinaryInstance(
     RelationInstance instance, Argument arg1, Argument arg2) {
   RelationInstance newInstance = new RelationInstance();
   String preposition = "";
   if (arg2.getArgumentType().startsWith("POBJ")) {
     preposition = arg2.getArgumentType().substring(5).toLowerCase();
   }
   newInstance.setAnnotatedSentence(instance.getAnnotatedSentence());
   newInstance.setNormalizedRelation(instance.getNormalizedRelation() + " " + preposition);
   newInstance.setOriginalRelation(instance.getOriginalRelation());
   newInstance.addArgument(arg1);
   newInstance.addArgument(arg2);
   return newInstance;
 }
Esempio 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);
    }
  }