From 378bd43f093910593cb6e89dc5b222715e03a67b Mon Sep 17 00:00:00 2001 From: botsharp2018 Date: Sat, 8 Sep 2018 20:51:16 -0500 Subject: [PATCH] Allow multiple classifications. --- BotSharp.NLP.UnitTest/NaiveBayesClassifierTest.cs | 2 +- BotSharp.NLP/Classify/ClassifierFactory.cs | 2 +- BotSharp.NLP/Corpus/LabeledPerFileNameReader.cs | 2 +- BotSharp.NLP/Sentence.cs | 5 ++++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/BotSharp.NLP.UnitTest/NaiveBayesClassifierTest.cs b/BotSharp.NLP.UnitTest/NaiveBayesClassifierTest.cs index b4020594..d4a037ca 100644 --- a/BotSharp.NLP.UnitTest/NaiveBayesClassifierTest.cs +++ b/BotSharp.NLP.UnitTest/NaiveBayesClassifierTest.cs @@ -45,7 +45,7 @@ namespace BotSharp.NLP.UnitTest testData.ForEach(td => { var classes = classifier.Classify(td); - if(td.Label == classes[0].Item1) + if(td.Labels[0] == classes[0].Item1) { correct++; } diff --git a/BotSharp.NLP/Classify/ClassifierFactory.cs b/BotSharp.NLP/Classify/ClassifierFactory.cs index 24df05e2..3baba28a 100644 --- a/BotSharp.NLP/Classify/ClassifierFactory.cs +++ b/BotSharp.NLP/Classify/ClassifierFactory.cs @@ -38,7 +38,7 @@ namespace BotSharp.NLP.Classify { _classifier.Train(sentences.Select(x => new LabeledFeatureSet { - Label = x.Label, + Label = x.Labels[0], Features = GetFeatures(x.Words) }).ToList(), _options); } diff --git a/BotSharp.NLP/Corpus/LabeledPerFileNameReader.cs b/BotSharp.NLP/Corpus/LabeledPerFileNameReader.cs index 1b465b02..1a9eb3b7 100644 --- a/BotSharp.NLP/Corpus/LabeledPerFileNameReader.cs +++ b/BotSharp.NLP/Corpus/LabeledPerFileNameReader.cs @@ -26,7 +26,7 @@ namespace BotSharp.NLP.Corpus { sentences.Add(new Sentence { - Label = lable, + Labels = new List { lable }, Text = line }); } diff --git a/BotSharp.NLP/Sentence.cs b/BotSharp.NLP/Sentence.cs index e0914fa4..50d075d6 100644 --- a/BotSharp.NLP/Sentence.cs +++ b/BotSharp.NLP/Sentence.cs @@ -9,7 +9,10 @@ namespace BotSharp.NLP { public List Words { get; set; } - public String Label { get; set; } + /// + /// Allow multiple classification + /// + public List Labels { get; set; } public String Text { get; set; } }