Ejemplo n.º 1
0
 /**
  * Gets the prepositions for this word in this sentence
  *
  * @param startingWord
  * @param graph Sentence
  * @param preposition A seeding expression. Ex: "in" or "in_front_of"
  * @return
  */
 public static List<IndexedWord> getPrepRelations(
     IndexedWord startingWord, SemanticGraph graph, String preposition) {
   // GrammaticalRelation prepreln =
   // GrammaticalRelation.getRelation(PrepositionalModifierGRAnnotation.class);
   GrammaticalRelation prepreln = EnglishGrammaticalRelations.getPrep(preposition);
   // checking rule: root->prep_in->det
   return graph.getChildrenWithReln(startingWord, prepreln);
 }
Ejemplo n.º 2
0
  /**
   * This method attempts to resolve noun phrases which consist of more than one word. More
   * precisely, it looks for nn dependencies below {@code head} and creates an entity.
   *
   * @param head The head of the noun phrase
   * @param graph The sentence to look in.
   * @param words The words which make up the noun phrase
   * @return A distinct word
   */
  public static String resolveNN(
      IndexedWord head, SemanticGraph graph, ArrayList<IndexedWord> words) {
    List<IndexedWord> nns =
        graph.getChildrenWithReln(head, EnglishGrammaticalRelations.NOUN_COMPOUND_MODIFIER);
    String name = "";
    // check for nulls. if there is nothing here, we have nothing to do.
    if (nns != null) {
      for (IndexedWord part : nns) {
        name += part.word();
        name += " ";

        words.add(part); // save this word as a part of the results
      }
      // append the head word ("starting" word)
      name += head.word();
      words.add(head); // save this word as a part of the results		
      return name;
    } else {
      return null;
    }
  }
Ejemplo n.º 3
0
 /**
  * This method attempts to resolve noun phrases and conjunction. More precisely, it looks for nn
  * and con_and dependencies below {@code head} and creates a list of entities.
  *
  * @param head The head of the noun phrase
  * @param sentence The sentence to which <code>head</code> belongs
  * @param namesIW The IndexedWords which form the head of each noun phrase
  * @return A list of distinct words or names, grouped by "and"
  */
 public static ArrayList<String> resolveCc(
     IndexedWord head, CoreMap sentence, ArrayList<IndexedWord> namesIW) {
   SemanticGraph graph = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
   // list of names
   ArrayList<String> names = new ArrayList<String>();
   if (namesIW == null) namesIW = new ArrayList<IndexedWord>();
   // adding this subject
   names.add(resolveNN(head, graph));
   // names.add(printTree(match(head, tree, "NP", true, 0)));
   namesIW.add(head);
   // check for more!
   // more names can be reached with "and". Get us an "and":
   GrammaticalRelation andrel = EnglishGrammaticalRelations.getConj("and");
   // ask the graph for everything that is connected by "and":
   List<IndexedWord> ands = graph.getChildrenWithReln(head, andrel);
   for (IndexedWord w : ands) {
     // add 'em
     names.add(resolveNN(w, graph));
     namesIW.add(w);
   }
   // hope those are all
   return names;
 }