Exemplo n.º 1
0
  @Override
  public Object produceValue(Annotation np, Document doc) {
    // Get the sentence annotations
    AnnotationSet par = doc.getAnnotationSet(Constants.PAR);
    AnnotationSet nps = doc.getAnnotationSet(Constants.NP);

    for (Annotation p : par) {
      int num;
      if (Constants.PAR_NUMS_UNAVAILABLE) {
        num = 0;
      } else {
        num = Integer.parseInt(p.getAttribute("parNum"));
      }
      AnnotationSet enclosed = nps.getContained(p);
      for (Annotation e : enclosed) {
        e.setProperty(this, num);
      }
    }

    // Make sure that all annotations have an associated PARNUM
    for (Annotation n : nps) {
      if (n.getProperty(this) == null) {
        AnnotationSet o = par.getOverlapping(0, n.getEndOffset());
        if (o == null || o.size() < 1) {
          n.setProperty(this, 0);
        } else {
          Annotation p = o.getLast();
          int num = Integer.parseInt(p.getAttribute("parNum")); // = 0;
          n.setProperty(this, num);
        }
      }
    }

    if (np.getProperty(this) == null) {
      AnnotationSet o = par.getOverlapping(0, np.getEndOffset());
      if (o == null || o.size() < 1) {
        np.setProperty(this, 0);
      } else {
        Annotation p = o.getLast();
        int num = Integer.parseInt(p.getAttribute("parNum"));
        np.setProperty(this, num);
      }
    }

    return np.getProperty(this);
  }
Exemplo n.º 2
0
 public static ArticleTypeEnum articleType(Annotation np, Document doc) {
   String[] indefs = {"a", "an", "one"};
   // String[] defs = { "the", "this", "that", "these", "those" };
   String[] quans = {"every", "all", "some", "most", "few", "many", "much"};
   String[] words = doc.getWords(np);
   String first = words[0];
   if (ProperName.getValue(np, doc)) return ArticleTypeEnum.DEFINITE;
   if (isPronoun(np, doc)) return ArticleTypeEnum.DEFINITE;
   if (memberArray(first, indefs)) return ArticleTypeEnum.INDEFINITE;
   if (memberArray(first, quans)) {
     if (words.length < 2 || !words[1].equalsIgnoreCase("of")) return ArticleTypeEnum.QUANTIFIED;
     else return ArticleTypeEnum.DEFINITE;
   }
   AnnotationSet pos = doc.getAnnotationSet(Constants.POS);
   pos = pos.getContained(np);
   if (pos != null && pos.size() > 0) {
     if (isCardinalNumber(pos.getFirst()) || isPredeterminer(pos.getFirst()))
       return ArticleTypeEnum.QUANTIFIED;
     if (isPossesivePronoun(pos.getFirst()) || isProperNoun(pos.getLast()))
       return ArticleTypeEnum.DEFINITE;
   }
   return ArticleTypeEnum.INDEFINITE;
 }