Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public static string Signature(string annotatorName, Properties props)
        {
            StringBuilder os = new StringBuilder();

            os.Append(annotatorName + ".model:" + props.GetProperty(annotatorName + ".model", LexicalizedParser.DefaultParserLoc));
            os.Append(annotatorName + ".debug:" + props.GetProperty(annotatorName + ".debug", "false"));
            os.Append(annotatorName + ".flags:" + props.GetProperty(annotatorName + ".flags", string.Empty));
            os.Append(annotatorName + ".maxlen:" + props.GetProperty(annotatorName + ".maxlen", "-1"));
            os.Append(annotatorName + ".treemap:" + props.GetProperty(annotatorName + ".treemap", string.Empty));
            os.Append(annotatorName + ".maxtime:" + props.GetProperty(annotatorName + ".maxtime", "-1"));
            os.Append(annotatorName + ".originalDependencies:" + props.GetProperty(annotatorName + ".originalDependencies", "false"));
            os.Append(annotatorName + ".buildgraphs:" + props.GetProperty(annotatorName + ".buildgraphs", "true"));
            os.Append(annotatorName + ".nthreads:" + props.GetProperty(annotatorName + ".nthreads", props.GetProperty("nthreads", string.Empty)));
            os.Append(annotatorName + ".nosquash:" + props.GetProperty(annotatorName + ".nosquash", "false"));
            os.Append(annotatorName + ".keepPunct:" + props.GetProperty(annotatorName + ".keepPunct", "true"));
            os.Append(annotatorName + ".extradependencies:" + props.GetProperty(annotatorName + ".extradependencies", "NONE").ToLower());
            bool usesBinary      = StanfordCoreNLP.UsesBinaryTrees(props);
            bool saveBinaryTrees = PropertiesUtils.GetBool(props, annotatorName + ".binaryTrees", usesBinary);

            os.Append(annotatorName + ".binaryTrees:" + saveBinaryTrees);
            return(os.ToString());
        }