コード例 #1
0
        /// <summary>
        /// Returns a new
        /// <c>SemanticGraph</c>
        /// constructed from a given
        /// <see cref="Edu.Stanford.Nlp.Trees.Tree"/>
        /// with given options.
        /// This factory method is intended to replace a profusion of highly similar
        /// factory methods, such as
        /// <c>typedDependencies()</c>
        /// ,
        /// <c>typedDependenciesCollapsed()</c>
        /// ,
        /// <c>allTypedDependencies()</c>
        /// ,
        /// <c>allTypedDependenciesCollapsed()</c>
        /// , etc.
        /// For a fuller explanation of the meaning of the boolean arguments, see
        /// <see cref="Edu.Stanford.Nlp.Trees.GrammaticalStructure"/>
        /// .
        /// </summary>
        /// <param name="tree">A tree representing a phrase structure parse</param>
        /// <param name="includeExtras">
        /// Whether to include extra dependencies, which may
        /// result in a non-tree
        /// </param>
        /// <param name="filter">A filter to exclude certain dependencies; ignored if null</param>
        /// <param name="originalDependencies">
        /// generate original Stanford dependencies instead of new
        /// Universal Dependencies
        /// </param>
        /// <returns>A SemanticGraph</returns>
        public static SemanticGraph MakeFromTree(Tree tree, SemanticGraphFactory.Mode mode, GrammaticalStructure.Extras includeExtras, IPredicate <TypedDependency> filter, bool originalDependencies, bool includePunctuationDependencies)
        {
            GrammaticalStructure gs;

            if (originalDependencies)
            {
                IPredicate <string> wordFilt;
                if (includePunctuationDependencies)
                {
                    wordFilt = Filters.AcceptFilter();
                }
                else
                {
                    wordFilt = new PennTreebankLanguagePack().PunctuationWordRejectFilter();
                }
                gs = new EnglishGrammaticalStructure(tree, wordFilt, new SemanticHeadFinder(true));
            }
            else
            {
                IPredicate <string> tagFilt;
                if (includePunctuationDependencies)
                {
                    tagFilt = Filters.AcceptFilter();
                }
                else
                {
                    tagFilt = new PennTreebankLanguagePack().PunctuationTagRejectFilter();
                }
                gs = new UniversalEnglishGrammaticalStructure(tree, tagFilt, new UniversalSemanticHeadFinder(true));
            }
            return(MakeFromTree(gs, mode, includeExtras, filter));
        }
コード例 #2
0
        public ParserAnnotator(string annotatorName, Properties props)
        {
            string model = props.GetProperty(annotatorName + ".model", LexicalizedParser.DefaultParserLoc);

            if (model == null)
            {
                throw new ArgumentException("No model specified for Parser annotator " + annotatorName);
            }
            this.Verbose = PropertiesUtils.GetBool(props, annotatorName + ".debug", false);
            string[] flags = ConvertFlagsToArray(props.GetProperty(annotatorName + ".flags"));
            this.parser            = LoadModel(model, Verbose, flags);
            this.maxSentenceLength = PropertiesUtils.GetInt(props, annotatorName + ".maxlen", -1);
            string treeMapClass = props.GetProperty(annotatorName + ".treemap");

            if (treeMapClass == null)
            {
                this.treeMap = null;
            }
            else
            {
                this.treeMap = ReflectionLoading.LoadByReflection(treeMapClass, props);
            }
            this.maxParseTime = PropertiesUtils.GetLong(props, annotatorName + ".maxtime", -1);
            this.kBest        = PropertiesUtils.GetInt(props, annotatorName + ".kbest", 1);
            this.keepPunct    = PropertiesUtils.GetBool(props, annotatorName + ".keepPunct", true);
            string buildGraphsProperty = annotatorName + ".buildgraphs";

            if (!this.parser.GetTLPParams().SupportsBasicDependencies())
            {
                if (PropertiesUtils.GetBool(props, buildGraphsProperty))
                {
                    log.Info("WARNING: " + buildGraphsProperty + " set to true, but " + this.parser.GetTLPParams().GetType() + " does not support dependencies");
                }
                this.BuildGraphs = false;
            }
            else
            {
                this.BuildGraphs = PropertiesUtils.GetBool(props, buildGraphsProperty, true);
            }
            if (this.BuildGraphs)
            {
                bool generateOriginalDependencies = PropertiesUtils.GetBool(props, annotatorName + ".originalDependencies", false);
                parser.GetTLPParams().SetGenerateOriginalDependencies(generateOriginalDependencies);
                ITreebankLanguagePack tlp         = parser.GetTLPParams().TreebankLanguagePack();
                IPredicate <string>   punctFilter = this.keepPunct ? Filters.AcceptFilter() : tlp.PunctuationWordRejectFilter();
                this.gsf = tlp.GrammaticalStructureFactory(punctFilter, parser.GetTLPParams().TypedDependencyHeadFinder());
            }
            else
            {
                this.gsf = null;
            }
            this.nThreads = PropertiesUtils.GetInt(props, annotatorName + ".nthreads", PropertiesUtils.GetInt(props, "nthreads", 1));
            bool usesBinary = StanfordCoreNLP.UsesBinaryTrees(props);

            this.saveBinaryTrees   = PropertiesUtils.GetBool(props, annotatorName + ".binaryTrees", usesBinary);
            this.noSquash          = PropertiesUtils.GetBool(props, annotatorName + ".nosquash", false);
            this.extraDependencies = MetaClass.Cast(props.GetProperty(annotatorName + ".extradependencies", "NONE"), typeof(GrammaticalStructure.Extras));
        }
 public UniversalChineseGrammaticalStructure(Tree t, IPredicate <string> puncFilter, IHeadFinder hf)
     : base(t, UniversalChineseGrammaticalRelations.Values(), UniversalChineseGrammaticalRelations.ValuesLock(), null, hf, puncFilter, Filters.AcceptFilter())
 {
 }
 /// <param name="headFinder">
 /// If a headFinder is provided, then head percolation will be done
 /// for trees. Otherwise, it must be called separately.
 /// </param>
 public UnlabeledAttachmentEval(string str, bool runningAverages, IHeadFinder headFinder)
     : this(str, runningAverages, headFinder, Filters.AcceptFilter <string>())
 {
 }