Exemplo n.º 1
0
  private String getHeadNoun(String uri) {
    String[] tokens = lexicalize(uri);

    // if we have multiple tokens, get the head noun
    String head;
    if (tokens.length > 1) {
      head = Joiner.on(" ").join(tokens);

      Annotation document = new Annotation(head);
      pipeline.annotate(document);

      CoreMap sentence = document.get(SentencesAnnotation.class).get(0);
      Tree tree = sentence.get(TreeAnnotation.class);

      Tree headTree = headFinder.determineHead(tree);
      // we assume that the last occurring NN is the head noun
      List<Tree> leaves = headTree.getLeaves();
      head = leaves.get(leaves.size() - 1).label().value();
    } else {
      head = tokens[0];
    }
    return head;
  }