Exemplo n.º 1
0
  /*
   * Returns 0 - If NA 1 - If Incompatible 2 - If compatible
   */
  public static int sameSemanticClass(Annotation np1, Annotation np2, Document doc) {

    NPSemTypeEnum type1 = NPSemanticType.getValue(np1, doc);
    NPSemTypeEnum type2 = NPSemanticType.getValue(np2, doc);

    if (type1.equals(type2) && !type1.equals(NPSemTypeEnum.UNKNOWN)) return 2;

    String[] wn_senses1 = WNSemClass.getValue(np1, doc);
    String[] wn_senses2 = WNSemClass.getValue(np2, doc);

    if (wn_senses1.length < 1 || wn_senses2.length < 1) return 0;

    for (String s : COMP_SUPERTYPES) {
      if (memberArray(s, wn_senses1) && memberArray(s, wn_senses2)) return 2;
    }

    if (overlaps(wn_senses1, wn_senses2)) {
      if (FeatureUtils.isPronoun(np1, doc) || FeatureUtils.isPronoun(np2, doc)) return 2;
      String[] w1 = doc.getWords(np1);
      String[] w2 = doc.getWords(np2);
      if (intersection(w1, w2) > 0) return 2;
    }

    return 1;
  }
Exemplo n.º 2
0
  @Override
  public String produceValue(
      Annotation np1, Annotation np2, Document doc, Map<Feature, String> featVector) {
    if (FeatureUtils.isPronoun(np1, doc) || FeatureUtils.isPronoun(np2, doc)) return INCOMPATIBLE;
    Annotation head1 = HeadNoun.getValue(np1, doc);
    Annotation head2 = HeadNoun.getValue(np2, doc);

    String h1 = doc.getAnnotString(head1).toLowerCase();
    String h2 = doc.getAnnotString(head2).toLowerCase();

    /* Checking to ensure the head nouns differ. */
    if (h1.equals(h2)) return COMPATIBLE;
    if (FeatureUtils.isPronoun(np1, doc) || FeatureUtils.isPronoun(np2, doc)) return INCOMPATIBLE;
    if (ProperName.getValue(np2, doc) || ProperName.getValue(np1, doc)) return INCOMPATIBLE;
    if (FeatureUtils.isSubclass(np1, np2, doc) || FeatureUtils.isSubclass(np2, np2, doc))
      return COMPATIBLE;
    return INCOMPATIBLE;
  }
  @Override
  public void initialize(Annotation[] nps, Document doc, boolean training) {
    super.initialize(nps, doc, training);
    pairs = new ArrayList<Annotation[]>();
    HashMap<Annotation, ArrayList<Annotation>> posessives =
        new HashMap<Annotation, ArrayList<Annotation>>();

    RuleResolvers.addAllPossesives(doc.getAnnotationSet(Constants.NP), doc, posessives);
    int propNames = 0, regular = 0, is = 0, def = 0;
    for (int j = nps.length - 1; j >= 0; j--) {
      Annotation np2 = nps[j];
      RuleResolvers.NPType type2 = RuleResolvers.getNPtype(np2, doc, posessives);
      // int par2 = ParNum.getValue(np2, doc);
      int sen2 = SentNum.getValue(np2, doc);
      boolean pn2 = type2.equals(RuleResolvers.NPType.PROPER_NAME);
      boolean pron2 = type2.equals(RuleResolvers.NPType.PRONOUN);
      boolean def2 = !pron2 && !pn2 && !FeatureUtils.isIndefinite(np2, doc);
      boolean specPronoun2 =
          pron2
              && FeatureUtils.getPronounPerson(doc.getAnnotText(np2))
                  != PersonPronounTypeEnum.THIRD;
      boolean person2 =
          pn2 && ProperNameType.getValue(np2, doc).equals(FeatureUtils.NPSemTypeEnum.PERSON);
      boolean done = false;
      for (int k = j - 1; k >= 0 && !done; k--) {
        Annotation np1 = nps[k];
        // Get the type of the first np
        RuleResolvers.NPType type1 = RuleResolvers.getNPtype(np1, doc, posessives);
        // int par1 = ParNum.getValue(np1, doc);
        // int parNum = Math.abs(par1 - par2);
        int sen1 = SentNum.getValue(np1, doc);
        int senNum = Math.abs(sen1 - sen2);
        boolean pron1 = type1.equals(RuleResolvers.NPType.PRONOUN);
        boolean pn1 = type1.equals(RuleResolvers.NPType.PROPER_NAME);
        boolean specPronoun1 =
            pron1
                && FeatureUtils.getPronounPerson(doc.getAnnotText(np1))
                    != PersonPronounTypeEnum.THIRD;
        boolean person1 =
            pn1 && ProperNameType.getValue(np1, doc).equals(FeatureUtils.NPSemTypeEnum.PERSON);
        boolean includePair = false;
        if (pn1
            && pn2
            && ProperNameType.getValue(np1, doc).equals(ProperNameType.getValue(np2, doc))) {
          includePair = true;
          propNames++;
        } else if (person2 && specPronoun1) {
          includePair = true;
          is++;
        } else if (specPronoun1 && (specPronoun2 || person2)) {
          includePair = true;
          is++;
        } else if (specPronoun2 && (specPronoun1 || person1)) {
          includePair = true;
          is++;
        } else if (def2 && !pron1 && (senNum <= 6)) {
          includePair = true;
          def++;
        } else if (senNum <= 2) {
          includePair = true;
          regular++;
        }
        if (includePair) {
          pairs.add(new Annotation[] {np1, np2});
        } else {
          if (!pn2 && !specPronoun2 && (!def2 || (senNum > 6))) {
            done = true;
          }
        }
      }
    }
    pairIter = pairs.iterator();
  }