package org.studiorailgun.conversation.parser;

import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.trees.GrammaticalRelation;

/**
 * NLP dependency functions
 */
public class NLPDependencies {
    
    /**
     * Checks if this is a copular dependency
     * @param dependency The dependency tag
     * @return true if it is a copular dependency, false otherwise
     */
    public static boolean isCopular(String dependency){
        return dependency.equals("copula");
    }

    /**
     * Gets the copular verb of the graph
     * @param graph The graph
     * @param root The root
     * @return The copular verb
     */
    public static IndexedWord getCopular(SemanticGraph graph){
        if(graph.getRoots().size() != 1){
            throw new Error("Can't handle roots != 1\n" + graph);
        }
        IndexedWord root = graph.getFirstRoot();
        for(IndexedWord child : graph.getChildList(root)){
            GrammaticalRelation relation = graph.reln(root,child);
            if(NLPDependencies.isCopular(relation.getLongName())){
                return child;
            }
        }
        throw new Error("Passed in root without copular verb!\n" + graph);
    }

}
