package org.studiorailgun;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.Test;
import org.studiorailgun.conversation.parser.NLPParser;
import org.studiorailgun.conversation.parser.depend.Clause;

import edu.stanford.nlp.pipeline.CoreDocument;
import edu.stanford.nlp.pipeline.CoreSentence;
import edu.stanford.nlp.semgraph.SemanticGraph;

/**
 * Test parsing clauses that we might see in a conversation
 */
public class ConversationClauseTests {
    
    @Test
    public void testParseConversationClause1(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("What time is the meeting tomorrow?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),2);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "is"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "time"); //should be the subject
    }

    @Test
    public void testParseConversationClause2(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Tell me a joke!");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),2);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "Tell"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "me"); //should be the subject
    }

    @Test
    public void testParseConversationClause3(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Why did you suggest using an bucket to shovel dirt?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "suggest"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "you"); //should be the subject
    }

    @Test
    public void testParseConversationClause4(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("It's too cold in here; can you turn up the heat?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "cold"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "It"); //should be the subject
    }

    @Test
    public void testParseConversationClause5(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Who are you?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "Who"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "you"); //should be the subject
    }

    @Test
    public void testParseConversationClause6(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Where are you from?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "are"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "you"); //should be the subject
    }

    @Test
    public void testParseConversationClause7(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("What is your name?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "What"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "name"); //should be the subject
    }

    @Test
    public void testParseConversationClause8(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Who is responsible for maintaining the project documentation?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "responsible"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "Who"); //should be the subject
    }

    @Test
    public void testParseConversationClause9(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("What is the capital of France?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "What"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "capital"); //should be the subject
    }

    @Test
    public void testParseConversationClause10(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Explain the difference between god and man.");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "Explain"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "difference"); //should be the subject
    }

    @Test
    public void testParseConversationClause11(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Where did your staff go?");
        CoreSentence sentence = doc.sentences().get(0);
        SemanticGraph graph = sentence.dependencyParse();
        Clause struct = Clause.parse(graph);

        //test number of returns
        assertNotNull(struct.getPredicate());
        assertEquals(struct.getArguments().size(),1);

        //test returned data
        assertEquals(struct.getPredicate().getRoot().originalText(), "go"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "staff"); //should be the subject
    }

}
