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 complex sentence tests
 */
public class ComplexClauseTests {
    
    @Test
    public void testMacroStructureParse1(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("The sun lowered, the stars appeared, and the moon rose.");
        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.getClauses().size(), 2);

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

    @Test
    public void testMacroStructureParse2(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("Birds fly, but fish swim.");
        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.getClauses().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 testMacroStructureParse3(){
        NLPParser.init();
        CoreDocument doc = NLPParser.parse("She cooked dinner, yet nobody ate it.");
        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);
        assertEquals(struct.getClauses().size(), 1);

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

}
