package org.studiorailgun;

import static org.junit.Assert.*;

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

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

/**
 * Macro structure parsing simple sentence tests
 */
public class SimpleClauseTests {
    
    @Test
    public void testMacroStructureParse1(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("His name is Bob.");
        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(), "Bob"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "name"); //should be the subject
    }

    @Test
    public void testMacroStructureParse2(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("She ran.");
        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(), "ran"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "She"); //should be the subject
    }

    @Test
    public void testMacroStructureParse3(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("The cat sleeps.");
        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(), "sleeps"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "cat"); //should be the subject
    }

    @Test
    public void testMacroStructureParse4(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("A dog barked.");
        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(), "barked"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "dog"); //should be the subject
    }

    @Test
    public void testMacroStructureParse5(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Colorful birds fly.");
        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(), "fly"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "birds"); //should be the subject
    }

    @Test
    public void testMacroStructureParse6(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("The cat sleeps on the mat.");
        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);
        assertEquals(struct.getAdjuncts().size(),1);

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

    @Test
    public void testMacroStructureParse7(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Guys, take it easy.");
        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(), "take"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "Guys"); //should be the subject
        assertEquals(struct.getPredicate().getAdverbs().get(0).getRoot().originalText(), "easy"); //should be the adverb
    }

    @Test
    public void testMacroStructureParse8(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("He dropped her the ball.");
        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(),3);

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

    @Test
    public void testMacroStructureParse9(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("There is a ball below.");
        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(), "is"); //should be copular verb
        assertEquals(struct.getPredicate().isExistential(), true); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "ball"); //should be the subject
    }

    @Test
    public void testMacroStructureParse10(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("She appears intelligent.");
        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(), "appears"); //should be copular verb
        assertEquals(struct.getArguments().get(0).getRoot().originalText(), "She"); //should be the subject
    }

}
