Example usage for edu.stanford.nlp.ling LabeledWord tag

List of usage examples for edu.stanford.nlp.ling LabeledWord tag

Introduction

In this page you can find the example usage for edu.stanford.nlp.ling LabeledWord tag.

Prototype

Label tag

To view the source code for edu.stanford.nlp.ling LabeledWord tag.

Click Source Link

Usage

From source file:edu.rpi.tw.linkipedia.search.nlp.NaturalLanguageProcessor.java

License:Open Source License

public String printTree(Tree tree) {
    List<LabeledWord> words = tree.labeledYield();

    String currentPhrase = "";
    for (LabeledWord word : words) {
        if (!(word.tag().toString().matches("[A-Z]+")))
            continue;
        currentPhrase += word.word() + "|" + word.tag() + " ";
    }/*from w  w  w. j a  va 2 s .com*/
    System.out.println("Phrase: " + currentPhrase);
    return currentPhrase;
}

From source file:edu.rpi.tw.linkipedia.search.nlp.NaturalLanguageProcessor.java

License:Open Source License

private List<String> getNounPhraseFromParseTree(Tree parse) {

    List<String> phraseList = new ArrayList<String>();
    for (Tree subtree : parse) {
        if (subtree.label().value().equals("NP")) {
            String subtreeString = subtree.toString();
            if (subtreeString.lastIndexOf("(NP") != subtreeString.indexOf("(NP"))
                continue;
            //System.out.println(subtree);
            List<LabeledWord> words = subtree.labeledYield();
            String currentPhrase = "";
            for (LabeledWord word : words) {

                currentPhrase += word.word() + "|" + word.tag() + " ";
            }//from   w w  w .j  a  v  a 2  s.c o  m
            currentPhrase = currentPhrase.trim();
            phraseList.add(currentPhrase);
        }
    }

    return phraseList;

}