Example usage for edu.stanford.nlp.semgraph SemanticGraph toString

List of usage examples for edu.stanford.nlp.semgraph SemanticGraph toString

Introduction

In this page you can find the example usage for edu.stanford.nlp.semgraph SemanticGraph toString.

Prototype

@Override
public String toString() 

Source Link

Document

Recursive depth first traversal.

Usage

From source file:nlp.prototype.NewJFrame.java

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked

    DefaultTreeModel model2 = (DefaultTreeModel) jTree2.getModel();
    DefaultMutableTreeNode rootNode2 = new DefaultMutableTreeNode("top");
    model2.setRoot(rootNode2);/*www.j  a  v  a 2 s .  c o  m*/

    /*TextCorpus textCorpus = processor.parseCorpus(jTextArea1.getText());
            
    for (SentenceToken token : textCorpus.getSentences()) {
    DefaultMutableTreeNode sentenceTokenNode = new DefaultMutableTreeNode();
    sentenceTokenNode.setUserObject(token);
    rootNode2.add(sentenceTokenNode);
    addNodes(token, sentenceTokenNode);
    }
            
    DefaultTokenSerializer serializer = new DefaultTokenSerializer();
    Document xmlDocument = serializer.serialize(textCorpus);
    jTextArea4.setText(serializer.transform(xmlDocument));
    jTextArea7.setText(serializer.transform(xmlDocument, this.jTextArea6.getText()));*/

    Annotation document = new Annotation(jTextArea1.getText());
    pipeline.annotate(document);
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    Map<Integer, CorefChain> corefMap = document.get(CorefChainAnnotation.class);
    List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);

    DefaultListModel listModel = new DefaultListModel();

    for (Class key : document.keySet()) {
        Object value = document.get(key);

        if (value != null && value.toString() != null && !value.toString().isEmpty()) {
            listModel.addElement(key.toString() + " - [" + value.toString() + "]");
        }
    }

    DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("top");
    model.setRoot(rootNode);

    List<POSToken> tokenList = new ArrayList<>();

    jList1.setModel(listModel);

    for (CoreMap sentence : sentences) {
        Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
        SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
        String root = graph.getFirstRoot().originalText();

        MultiValuedMap<String, GrammarToken> map = new HashSetValuedHashMap<>();

        for (SemanticGraphEdge edge : graph.edgeIterable()) {
            GrammarToken grammarToken = new GrammarToken(edge);
            map.put(grammarToken.getTarget(), grammarToken);
        }

        DefaultMutableTreeNode node = new DefaultMutableTreeNode();
        POSToken token = new POSToken((CoreLabel) tree.label());
        token.setGrammar(graph.toString());
        node.setUserObject(token);
        rootNode.add(node);
        addNodes(tree, false, node, node, map, root, corefMap, tokens);
        tokenList.add(token);
    }

    setAdjacentNodes(tokenList);
}

From source file:parsers.CoreNLPSuite.java

public static String dependencyParse(String input) {
    String ans = "";
    Annotation document = new Annotation(input);
    Parsers.pipeline.annotate(document);
    List<CoreMap> sentences = document.get(SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
        ans = ans + dependencies.toString() + "\n";
    }//www .j  av a  2 s  . c  o  m
    return ans;
}