public string[] PosTagTokens(string[] tokens) { if (mPosTagger == null) { mPosTagger = new OpenNLP.Tools.PosTagger.EnglishMaximumEntropyPosTagger(mModelPath + "EnglishPOS.nbin", mModelPath + @"\Parser\tagdict"); } return(mPosTagger.Tag(tokens)); }
public string[] PosTagTokens(string[] tokens) { if (mPosTagger == null) { mPosTagger = new EnglishMaximumEntropyPosTagger(mModelPath + "EnglishPOS.nbin", mModelPath + @"\Parser\tagdict"); } return mPosTagger.Tag(tokens); }
public bool LoadModel(string ModelFile) { try { posTagger = new EnglishMaximumEntropyPosTagger(ModelFile); _isMAxentModelLoaded = true; return true; } catch { System.Console.WriteLine("Uable to load the Stanford CRF Model... "); _isMAxentModelLoaded = false; return false; } }
/// <summary> /// Create a parser and default goals. /// </summary> /// <param name="brain">The brain</param> /// <param name="robot">The robot</param> public override void Init(Brain.CBrain brain, IRobot robot) { this.brain = brain; this.robot = robot; // Load external NLP systems in their own threads restorerLoaded = new AutoResetEvent(false); parserLoaded = new AutoResetEvent(false); Thread parserLoader = new Thread(InitParser); Thread restorerLoader = new Thread(InitRestorer); parserLoader.Start(); restorerLoader.Start(); // Load up other systems in the meantime this.tokenizer = new EnglishMaximumEntropyTokenizer(sharpNLPPath + "EnglishTok.nbin"); this.tagger = new EnglishMaximumEntropyPosTagger(sharpNLPPath + "EnglishPOS.nbin", sharpNLPPath + @"\Parser\tagdict"); // Make default goals GoalBuilder gotoGoal = new GoalBuilder("GotoX", brain); int ruleIndex = gotoGoal.AddRule("GotoX"); gotoGoal.AddAndAntecedent(ruleIndex, "CurrentDestination Arg *=*;1"); gotoGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Going to the $CurrentDestination_\""); gotoGoal.AddConsequent(ruleIndex, "Execs", "Motion GoTo $CurrentDestination close"); gotoGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Commander, I finished moving to the $CurrentDestination_\""); gotoGoal.AddConsequent(ruleIndex, "Remove", "CurrentDestination Arg"); gotoGoal.AddConsequent(ruleIndex, "Quit", ""); gotoGoal.Commit(); failureGoal = new GoalBuilder("DidNotUnderstand", brain); ruleIndex = failureGoal.AddRule("DidNotUnderstand"); failureGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"I didn't understand what you said.\""); failureGoal.AddConsequent(ruleIndex, "Quit", ""); failureGoal.Commit(); GoalBuilder goingToGoal = new GoalBuilder("SayGoingToX", brain); ruleIndex = goingToGoal.AddRule("SayGoingToX"); goingToGoal.AddAndAntecedent(ruleIndex, "CurrentDestination Arg *=*;1"); goingToGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"I'm Going to the $CurrentDestination_\""); goingToGoal.AddConsequent(ruleIndex, "Quit", ""); goingToGoal.Commit(); GoalBuilder goingNowhereGoal = new GoalBuilder("SayGoingNowhere", brain); ruleIndex = goingNowhereGoal.AddRule("SayGoingNowhere"); goingNowhereGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"I'm not going anywhere right now.\""); goingNowhereGoal.AddConsequent(ruleIndex, "Quit", ""); goingNowhereGoal.Commit(); GoalBuilder dontKnowGoal = new GoalBuilder("DontKnowHowToX", brain); ruleIndex = dontKnowGoal.AddRule("DontKnowHowToX"); dontKnowGoal.AddAndAntecedent(ruleIndex, "DontKnow Arg *=*;1"); dontKnowGoal.AddConsequent(ruleIndex, "Execs", "Voice Say \"Sorry, but I don't know how to $DontKnow_\""); dontKnowGoal.AddConsequent(ruleIndex, "Remove", "DontKnow Arg"); dontKnowGoal.AddConsequent(ruleIndex, "Quit", ""); dontKnowGoal.Commit(); // Wait for all systems to finish loading restorerLoaded.WaitOne(); parserLoaded.WaitOne(); this.semantics = new SemanticsInterface(); }
private void initComponents() { sentenceDetector = new EnglishMaximumEntropySentenceDetector(Path.Combine(ModelDir, "EnglishSD.nbin")); tokenizer = new EnglishMaximumEntropyTokenizer(Path.Combine(ModelDir, "EnglishTok.nbin")); posTagger = new EnglishMaximumEntropyPosTagger(Path.Combine(ModelDir, "EnglishPOS.nbin")); chunker = new EnglishTreebankChunker(Path.Combine(ModelDir, "EnglishChunk.nbin")); parser = new EnglishTreebankParser(FileUtils.WithSeparator(ModelDir), true, false); }
private void TestDechunk() { // detokenize var inputs = new string[] { "- Harry's your sister. - Look, what exactly am I supposed to be doing here?", "\"Piss off!\"", "- Sorry Mrs. Hudson, I'll skip the tea. Off out. - Both of you?", "I love playing half-life; that's just who I am!", "That's why I... have just begun to write a book.", "And they lived happily ever after...", "It's gonna be $1.5 sir." }; // var tokenizer = new EnglishMaximumEntropyTokenizer(currentDirectory + "../Resources/Models/EnglishTok.nbin"); var chunker = new EnglishTreebankChunker(currentDirectory + "../Resources/Models/EnglishChunk.nbin"); var dechunker = new RegexDictionaryDechunker(); var detokienizer = new DictionaryDetokenizer(); var englishPosPath = currentDirectory + "../Resources/Models/EnglishPOS.nbin"; var tagDictPath = currentDirectory + "../Resources/Models/Parser/tagdict"; var posTagger = new EnglishMaximumEntropyPosTagger(englishPosPath, tagDictPath); foreach (var input in inputs) { string[] tokens = tokenizer.Tokenize(input); string[] tags = posTagger.Tag(tokens); var chunks = chunker.GetChunks(tokens, tags); var chunksStrings = chunks .Select(ch => detokienizer.Detokenize(ch.TaggedWords.Select(tw => tw.Word).ToArray())) .ToArray(); var output = dechunker.Dechunk(chunksStrings); Console.WriteLine("input: " + input); Console.WriteLine("chunks: " + string.Join(" | ", chunks)); Console.WriteLine("ouput: " + output); Console.WriteLine("--"); } }