Example usage for edu.stanford.nlp.ie.util RelationTriple subjectLemmaGloss

List of usage examples for edu.stanford.nlp.ie.util RelationTriple subjectLemmaGloss

Introduction

In this page you can find the example usage for edu.stanford.nlp.ie.util RelationTriple subjectLemmaGloss.

Prototype

public String subjectLemmaGloss() 

Source Link

Document

The subject of this relation triple, as a String of the subject's lemmas.

Usage

From source file:edu.illinois.cs.cogcomp.pipeline.handlers.StanfordOpenIEHandler.java

License:Open Source License

@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
    Annotation document = new Annotation(ta.text);
    pipeline.annotate(document);//from w w  w .  ja va  2s. c  o m
    SpanLabelView vu = new SpanLabelView(viewName, ta);
    for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
        Collection<RelationTriple> triples = sentence
                .get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
        for (RelationTriple triple : triples) {
            Constituent subject = getConstituent(triple.subjectGloss(), triple.subjectTokenSpan(), sentence,
                    ta);
            subject.addAttribute("subjectGloss", triple.subjectGloss());
            subject.addAttribute("subjectLemmaGloss", triple.subjectLemmaGloss());
            subject.addAttribute("subjectLink", triple.subjectLink());
            Constituent object = getConstituent(triple.objectGloss(), triple.objectTokenSpan(), sentence, ta);
            object.addAttribute("objectGloss", triple.objectGloss());
            object.addAttribute("objectLemmaGloss", triple.objectLemmaGloss());
            object.addAttribute("objectLink", triple.objectLink());
            Constituent relation = getConstituent(triple.relationGloss(), triple.relationTokenSpan(), sentence,
                    ta);
            relation.addAttribute("relationGloss", triple.relationGloss());
            relation.addAttribute("relationLemmaGloss", triple.relationLemmaGloss());
            Relation subj = new Relation("subj", relation, subject, triple.confidence);
            Relation obj = new Relation("obj", relation, object, triple.confidence);
            vu.addRelation(subj);
            vu.addRelation(obj);
            vu.addConstituent(subject);
            vu.addConstituent(object);
            vu.addConstituent(relation);
        }
    }
    ta.addView(viewName, vu);
}

From source file:iitg.cs565.Alphabet.InfoExtracter.RealationBuilder.java

public void buildAllRelations() {
    try {/*from   w w w  . j av  a 2s. c  o  m*/
        Properties props = new Properties();
        props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
        StanfordCoreNLP core = new StanfordCoreNLP(props);

        System.out.println("Stanford Core NLP Initialized");

        BufferedReader br = null;
        PrintWriter pw = null;
        String line;
        int fileIndex = 1;

        for (; fileIndex < AlphabetConstants.LARGEST_FILE_INDEX; fileIndex++) {
            StringBuffer inFilePath = new StringBuffer();
            StringBuffer outFilePath = new StringBuffer();
            inFilePath.append(AlphabetConstants.TAGGED_PROTEST_ARTICLES_PATH).append(fileIndex);
            outFilePath.append(AlphabetConstants.RELATION_PATH).append(fileIndex);

            File file = new File(inFilePath.toString());

            if (file.exists()) {
                System.out.println("File exists: " + fileIndex);

                // Read file                   
                br = new BufferedReader(new FileReader(inFilePath.toString()));
                pw = new PrintWriter(new FileWriter(outFilePath.toString()));

                // Read all lines
                while ((line = br.readLine()) != null) {

                    Annotation doc = new Annotation(line);
                    core.annotate(doc);

                    for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
                        Collection<RelationTriple> triples = sentence
                                .get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
                        for (RelationTriple triple : triples) {

                            pw.write("(" + triple.subjectLemmaGloss() + "#" + triple.relationLemmaGloss() + "#"
                                    + triple.objectLemmaGloss() + ")\n");

                        }
                    }
                }
                br.close();
                ;
                pw.close();

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}