コード例 #1
0
        public DependencyParseAnnotator(Properties properties)
        {
            string modelPath = PropertiesUtils.GetString(properties, "model", DependencyParser.DefaultModel);

            parser            = DependencyParser.LoadFromModelFile(modelPath, properties);
            nThreads          = PropertiesUtils.GetInt(properties, "testThreads", DefaultNthreads);
            maxTime           = PropertiesUtils.GetLong(properties, "sentenceTimeout", DefaultMaxtime);
            extraDependencies = MetaClass.Cast(properties.GetProperty("extradependencies", "NONE"), typeof(GrammaticalStructure.Extras));
        }
コード例 #2
0
        // static main method only
        public static void Main(string[] args)
        {
            string modelPath  = DependencyParser.DefaultModel;
            string taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger";

            for (int argIndex = 0; argIndex < args.Length;)
            {
                switch (args[argIndex])
                {
                case "-tagger":
                {
                    taggerPath = args[argIndex + 1];
                    argIndex  += 2;
                    break;
                }

                case "-model":
                {
                    modelPath = args[argIndex + 1];
                    argIndex += 2;
                    break;
                }

                default:
                {
                    throw new Exception("Unknown argument " + args[argIndex]);
                }
                }
            }
            string               text      = "I can almost always tell when movies use fake dinosaurs.";
            MaxentTagger         tagger    = new MaxentTagger(taggerPath);
            DependencyParser     parser    = DependencyParser.LoadFromModelFile(modelPath);
            DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));

            foreach (IList <IHasWord> sentence in tokenizer)
            {
                IList <TaggedWord>   tagged = tagger.TagSentence(sentence);
                GrammaticalStructure gs     = parser.Predict(tagged);
                // Print typed dependencies
                log.Info(gs);
            }
        }