예제 #1
0
        /// <summary>
        /// Prints an OpenIE triple to a String, according to the output format requested in
        /// the annotator.
        /// </summary>
        /// <param name="extraction">The triple to write.</param>
        /// <param name="docid">The document ID (for the ReVerb format)</param>
        /// <param name="sentence">The sentence the triple was extracted from (for the ReVerb format)</param>
        /// <returns>A String representation of the triple.</returns>
        public static string TripleToString(RelationTriple extraction, string docid, ICoreMap sentence)
        {
            switch (Format)
            {
            case OpenIE.OutputFormat.Reverb:
            {
                return(extraction.ToReverbString(docid, sentence));
            }

            case OpenIE.OutputFormat.Ollie:
            {
                return(extraction.ConfidenceGloss() + ": (" + extraction.SubjectGloss() + "; " + extraction.RelationGloss() + "; " + extraction.ObjectGloss() + ')');
            }

            case OpenIE.OutputFormat.Default:
            {
                return(extraction.ToString());
            }

            case OpenIE.OutputFormat.QaSrl:
            {
                return(extraction.ToQaSrlString(sentence));
            }

            default:
            {
                throw new InvalidOperationException("Format is not implemented: " + Format);
            }
            }
        }
        private static Element ToXML(RelationTriple triple, string curNS)
        {
            Element top = new Element("triple", curNS);

            top.AddAttribute(new Attribute("confidence", triple.ConfidenceGloss()));
            // Create the subject
            Element subject = new Element("subject", curNS);

            subject.AddAttribute(new Attribute("begin", int.ToString(triple.SubjectTokenSpan().first)));
            subject.AddAttribute(new Attribute("end", int.ToString(triple.SubjectTokenSpan().second)));
            Element text = new Element("text", curNS);

            text.AppendChild(triple.SubjectGloss());
            Element lemma = new Element("lemma", curNS);

            lemma.AppendChild(triple.SubjectLemmaGloss());
            subject.AppendChild(text);
            subject.AppendChild(lemma);
            top.AppendChild(subject);
            // Create the relation
            Element relation = new Element("relation", curNS);

            relation.AddAttribute(new Attribute("begin", int.ToString(triple.RelationTokenSpan().first)));
            relation.AddAttribute(new Attribute("end", int.ToString(triple.RelationTokenSpan().second)));
            text = new Element("text", curNS);
            text.AppendChild(triple.RelationGloss());
            lemma = new Element("lemma", curNS);
            lemma.AppendChild(triple.RelationLemmaGloss());
            relation.AppendChild(text);
            relation.AppendChild(lemma);
            top.AppendChild(relation);
            // Create the object
            Element @object = new Element("object", curNS);

            @object.AddAttribute(new Attribute("begin", int.ToString(triple.ObjectTokenSpan().first)));
            @object.AddAttribute(new Attribute("end", int.ToString(triple.ObjectTokenSpan().second)));
            text = new Element("text", curNS);
            text.AppendChild(triple.ObjectGloss());
            lemma = new Element("lemma", curNS);
            lemma.AppendChild(triple.ObjectLemmaGloss());
            @object.AppendChild(text);
            @object.AppendChild(lemma);
            top.AppendChild(@object);
            return(top);
        }
예제 #3
0
        static List <TripleTerm> ExtractTriple(string content)
        {
            List <TripleTerm> result = new List <TripleTerm>();

            edu.stanford.nlp.simple.Document doc = new edu.stanford.nlp.simple.Document(content);
            var list = doc.sentences();

            for (int i = Variable.VariableZero; i < list.size(); i++)
            {
                edu.stanford.nlp.simple.Sentence sentence = (edu.stanford.nlp.simple.Sentence)list.get(i);
                var tripleList = sentence.openieTriples();
                for (int j = Variable.VariableZero; j < tripleList.size(); j++)
                {
                    var            tripleListArray = tripleList.toArray();
                    RelationTriple relationTriple  = (RelationTriple)tripleListArray[j];
                    var            currentTriple   = new TripleTerm(
                        relationTriple.subjectGloss(),
                        relationTriple.relationGloss(),
                        relationTriple.objectGloss());
                    result.Add(currentTriple);
                }
            }
            return(result);
        }