Search in sources :

Example 6 with ReasonPair

use of main.database.ReasonPair in project Info-Evaluation by TechnionYP5777.

the class AnalyzeParagragh method InteractiveReasonFinding.

//This function makes the analyze process interactive with the user - he gets reasons to choose from and chooses the most fitiing one.
public LinkedList<ReasonPair> InteractiveReasonFinding() {
    LinkedList<ReasonPair> $ = new LinkedList<ReasonPair>();
    final Properties props = new Properties();
    props.put("annotators", "tokenize,ssplit, pos, regexner, parse,lemma,natlog,openie");
    final StanfordCoreNLP pipeLine = new StanfordCoreNLP(props);
    // inputText will be the text to evaluate in this example
    final String inputText = input + "";
    final Annotation document = new Annotation(inputText);
    // Finally we use the pipeline to annotate the document we created
    pipeLine.annotate(document);
    for (final CoreMap sentence : document.get(SentencesAnnotation.class)) for (RelationTriple ¢ : sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class)) $.add(new ReasonPair(¢.confidence, ¢.relationGloss() + " " + ¢.objectGloss()));
    return $;
}
Also used : RelationTriple(edu.stanford.nlp.ie.util.RelationTriple) ReasonPair(main.database.ReasonPair) Properties(java.util.Properties) CoreMap(edu.stanford.nlp.util.CoreMap) LinkedList(java.util.LinkedList) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) SentencesAnnotation(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) CollapsedDependenciesAnnotation(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation)

Example 7 with ReasonPair

use of main.database.ReasonPair in project Info-Evaluation by TechnionYP5777.

the class AnalyzeParagragh method InteractiveAnalyze.

public InteractiveTableTuple InteractiveAnalyze() {
    final String $ = getName();
    final String input_date = getDate(year);
    String accurate_name = "";
    LinkedList<ReasonPair> reasons = InteractiveReasonFinding();
    final Properties props = new Properties();
    props.put("annotators", "tokenize,ssplit, pos, regexner, parse,lemma,natlog,openie");
    final StanfordCoreNLP pipeLine = new StanfordCoreNLP(props);
    final String inputText = input + "";
    final Annotation document = new Annotation(inputText);
    pipeLine.annotate(document);
    for (final CoreMap sentence : document.get(SentencesAnnotation.class)) {
        final SemanticGraph dependencies = sentence.get(CollapsedDependenciesAnnotation.class);
        for (final IndexedWord root : dependencies.getRoots()) for (final SemanticGraphEdge edge : dependencies.getOutEdgesSorted(root)) {
            final IndexedWord dep = edge.getDependent();
            if ("nsubjpass".equals((edge.getRelation() + ""))) {
                for (final SemanticGraphEdge keshet : dependencies.getOutEdgesSorted(dep)) {
                    final IndexedWord dep2 = keshet.getDependent();
                    final String rel2 = keshet.getRelation() + "";
                    if ("arrested".equals(edge.getGovernor().word()) && ((dep2.ner() != null && "PERSON".equals(dep2.ner())) || "compound".equals(rel2) || "det".equals(rel2)))
                        accurate_name += dep2.word() + " ";
                }
                accurate_name += dep.word();
            }
        }
    }
    return new InteractiveTableTuple(accurate_name.isEmpty() ? $ : accurate_name, input_date, reasons);
}
Also used : SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) ReasonPair(main.database.ReasonPair) Properties(java.util.Properties) IndexedWord(edu.stanford.nlp.ling.IndexedWord) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) SentencesAnnotation(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) CollapsedDependenciesAnnotation(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge) InteractiveTableTuple(main.database.InteractiveTableTuple)

Example 8 with ReasonPair

use of main.database.ReasonPair in project Info-Evaluation by TechnionYP5777.

the class InteractiveTableTupleTest method test2.

@Test
public void test2() {
    InteractiveTableTuple t = new InteractiveTableTuple();
    t.setName("Justin Bieber");
    t.setDate("12/02/2016");
    assertEquals(t.getDate(), "12/02/2016");
    assertEquals(t.getName(), "Justin Bieber");
    assertEquals((t.getRegularDate() + ""), "Fri Dec 02 00:00:00 IST 2016");
    assert t.getKeyWords().isEmpty();
    ReasonPair rp = new ReasonPair();
    rp.setProbability(0.4);
    rp.setReason("stubbing");
    LinkedList<ReasonPair> lst = new LinkedList<>();
    lst.add(rp);
    t.setReasons(lst);
    assertEquals(t.getReasons().get(0).getProbability(), 0.4, 0);
    assertEquals(t.getReasons().get(0).getReason(), "stubbing");
}
Also used : ReasonPair(main.database.ReasonPair) LinkedList(java.util.LinkedList) InteractiveTableTuple(main.database.InteractiveTableTuple) Test(org.junit.Test)

Example 9 with ReasonPair

use of main.database.ReasonPair in project Info-Evaluation by TechnionYP5777.

the class InteractiveAnalyzeParagraphTest method test3.

@Test
public void test3() {
    final Sentence sent = new Sentence("Vin Diesel was arrested for furious driving on August 14, 2002 in California");
    final InteractiveTableTuple itt = new AnalyzeParagragh(sent, "2002").InteractiveAnalyze();
    assertEquals("Vin Diesel", itt.getName());
    assertEquals("08/14/2002", itt.getDate());
    for (ReasonPair ¢ : itt.getReasons()) System.out.println(¢.getReason() + " with probability: " + ¢.getProbability());
}
Also used : AnalyzeParagragh(main.Analyze.AnalyzeParagragh) ReasonPair(main.database.ReasonPair) Sentence(edu.stanford.nlp.simple.Sentence) InteractiveTableTuple(main.database.InteractiveTableTuple) Test(org.junit.Test)

Example 10 with ReasonPair

use of main.database.ReasonPair in project Info-Evaluation by TechnionYP5777.

the class InteractiveAnalyzeParagraphTest method test1.

@Test
public void test1() {
    final Sentence sent = new Sentence("Justin Bieber was arrested for drunk driving in Georgia on February 22, 2015 .");
    final InteractiveTableTuple itt = new AnalyzeParagragh(sent, "2015").InteractiveAnalyze();
    assertEquals("Justin Bieber", itt.getName());
    assertEquals("02/22/2015", itt.getDate());
    for (ReasonPair ¢ : itt.getReasons()) System.out.println(¢.getReason() + " with probability: " + ¢.getProbability());
}
Also used : AnalyzeParagragh(main.Analyze.AnalyzeParagragh) ReasonPair(main.database.ReasonPair) Sentence(edu.stanford.nlp.simple.Sentence) InteractiveTableTuple(main.database.InteractiveTableTuple) Test(org.junit.Test)

Aggregations

ReasonPair (main.database.ReasonPair)11 Test (org.junit.Test)9 InteractiveTableTuple (main.database.InteractiveTableTuple)6 Sentence (edu.stanford.nlp.simple.Sentence)3 LinkedList (java.util.LinkedList)3 AnalyzeParagragh (main.Analyze.AnalyzeParagragh)3 SentencesAnnotation (edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation)2 Annotation (edu.stanford.nlp.pipeline.Annotation)2 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)2 CollapsedDependenciesAnnotation (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation)2 CoreMap (edu.stanford.nlp.util.CoreMap)2 Properties (java.util.Properties)2 RelationTriple (edu.stanford.nlp.ie.util.RelationTriple)1 IndexedWord (edu.stanford.nlp.ling.IndexedWord)1 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)1 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)1 AnalyzePage (main.Analyze.AnalyzePage)1