package org.studiorailgun.conversation.parser;

import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.semgraph.*;
import java.util.*;

import org.studiorailgun.conversation.tracking.Quote;

/**
 * Parses a sentence
 */
public class NLPParser {

    public static String text = "Joe Smith was born in California. " +
      "In 2017, he went to Paris, France in the summer. " +
      "His flight left at 3:00pm on July 10th, 2017. " +
      "After eating some escargot for the first time, Joe said, \"That was delicious!\" " +
      "He sent a postcard to his sister Jane Smith. " +
      "After hearing about Joe's trip, Jane decided she might go to France one day.";

    static StanfordCoreNLP pipeline;

    /**
     * Initializes the part-of-speech Parser
     */
    public static void init(){
        // set up pipeline properties
        Properties props = new Properties();
        // set the list of annotators to run
        props.setProperty("annotators", "tokenize,pos,lemma,ner,parse,depparse,coref,kbp,quote");
        // set a property for an annotator, in this case the coref annotator is being set to use the neural algorithm
        props.setProperty("coref.algorithm", "neural");
        // build pipeline
        pipeline = new StanfordCoreNLP(props);
    }
    
    /**
     * Parses the input sentence
     * @param input The input sentence
     */
    public static void parse(Quote quote){
        if(quote.getParsedDocument() == null){
            // annnotate the document and store
            CoreDocument document = new CoreDocument(quote.getRaw());
            pipeline.annotate(document);
            quote.setParsedDocument(document);

            //store the semantic graph
            SemanticGraph graph = document.sentences().get(0).dependencyParse();
            quote.setGraph(graph);
        }
        
        //TODO: grab information from document here
    }

}
