예제 #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);
        }
        /// <summary>The main entry point of the code.</summary>
        /// <exception cref="System.IO.IOException"/>
        public static void Main(string[] args)
        {
            Redwood.Util.ForceTrack("Processing treebanks");
            IList <Pair <ICoreMap, ICollection <Pair <Span, Span> > > > trainingData = new List <Pair <ICoreMap, ICollection <Pair <Span, Span> > > >();

            Sharpen.Collections.AddAll(trainingData, ProcessDirectory("WSJ", new File("/home/gabor/lib/data/penn_treebank/wsj")));
            Sharpen.Collections.AddAll(trainingData, ProcessDirectory("Brown", new File("/home/gabor/lib/data/penn_treebank/brown")));
            Redwood.Util.EndTrack("Processing treebanks");
            Redwood.Util.ForceTrack("Training");
            Redwood.Util.Log("dataset size: " + trainingData.Count);
            IClauseSplitter.Train(trainingData.Stream(), new File("/home/gabor/tmp/clauseSearcher.ser.gz"), new File("/home/gabor/tmp/clauseSearcherData.tab.gz"));
            Redwood.Util.EndTrack("Training");
        }