Beispiel #1
0
        /// <summary>Create a ne OpenIE system, based on the given properties.</summary>
        /// <param name="props">The properties to parametrize the system with.</param>
        public OpenIE(Properties props)
        {
            //
            // TODO(gabor): handle things like "One example of chemical energy is that found in the food that we eat ."
            //
            //
            // Static Options (for running standalone)
            //
            //
            // Annotator Options (for running in the pipeline)
            //
            // Fill the properties
            ArgumentParser.FillOptions(this, props);
            Properties withoutOpenIEPrefix = new Properties();

            foreach (string key in props.StringPropertyNames())
            {
                withoutOpenIEPrefix.SetProperty(key.Replace("openie.", string.Empty), props.GetProperty(key));
            }
            ArgumentParser.FillOptions(this, withoutOpenIEPrefix);
            // Create the clause splitter
            try
            {
                if (splitterDisable)
                {
                    clauseSplitter = Optional.Empty();
                }
                else
                {
                    if (noModel)
                    {
                        log.Info("Not loading a splitter model");
                        clauseSplitter = Optional.Of(null);
                    }
                    else
                    {
                        clauseSplitter = Optional.Of(IClauseSplitter.Load(splitterModel));
                    }
                }
            }
            catch (IOException e)
            {
                //throw new RuntimeIOException("Could not load clause splitter model at " + splitterModel + ": " + e.getClass() + ": " + e.getMessage());
                throw new RuntimeIOException("Could not load clause splitter model at " + splitterModel, e);
            }
            // Create the forward entailer
            try
            {
                this.weights = ignoreAffinity ? new NaturalLogicWeights(affinityProbabilityCap) : new NaturalLogicWeights(affinityModels, affinityProbabilityCap);
            }
            catch (IOException e)
            {
                throw new RuntimeIOException("Could not load affinity model at " + affinityModels + ": " + e.Message);
            }
            forwardEntailer = new ForwardEntailer(entailmentsPerSentence, weights);
            // Create the relation segmenter
            segmenter = new RelationTripleSegmenter(allNominals);
        }
Beispiel #2
0
        /// <summary>
        /// Create a relation from a CoNLL format like:
        /// <pre>
        /// word_index  word  parent_index  incoming_relation
        /// </pre>
        /// </summary>
        protected internal virtual Optional <RelationTriple> MkExtraction(string conll, int listIndex, bool allNominals)
        {
            Pair <SemanticGraph, IList <CoreLabel> > info = MkTree(conll);
            SemanticGraph     tree     = info.first;
            IList <CoreLabel> sentence = info.second;
            // Run extractor
            Optional <RelationTriple> segmented = new RelationTripleSegmenter(allNominals).Segment(tree, Optional.Empty());

            if (segmented.IsPresent() && listIndex == 0)
            {
                return(segmented);
            }
            IList <RelationTriple> extracted = new RelationTripleSegmenter(allNominals).Extract(tree, sentence);

            if (extracted.Count > listIndex)
            {
                return(Optional.Of(extracted[listIndex - (segmented.IsPresent() ? 1 : 0)]));
            }
            return(Optional.Empty());
        }