Exemple #1
0
 void Start()
 {
     ClearTexture();
     _textClassifier = GameObject.Find("Text Classifier").GetComponent <TextClassifier>();
     _textClassifier.Start();
     _hasPrinted = false;
     //_colors = new Color[]{Color.cyan, Color.magenta, Color.blue, Color.green, Color.yellow, Color.red};
 }
Exemple #2
0
        public void TextClassifier_ShouldCreateAnInstanceOfThisType_WhenProperArgument()
        {
            // Arrange
            // Act
            TextClassifier actual = new TextClassifier();

            // Assert
            Assert.IsInstanceOf <TextClassifier>(actual);
        }
Exemple #3
0
        private static void RunExample2()
        {
            string text = "Vår kund erbjuder trivsel";
            List <LabeledExample> labeledExamples = CreateLabeledExamples();

            ITextClassifier      textClassifier = new TextClassifier();
            TextClassifierResult result         = textClassifier.PredictLabel(text, labeledExamples);

            Console.WriteLine(result.Label);
        }
Exemple #4
0
        private static void RunExample1()
        {
            string text = "We are looking for several skilled and driven developers to join our team.";
            List <LabeledExample> labeledExamples = CreateLabeledExamples();

            ITextClassifier      textClassifier = new TextClassifier();
            TextClassifierResult result         = textClassifier.PredictLabel(text, labeledExamples);

            Console.WriteLine(result.Label);
        }
Exemple #5
0
        public void CategorizePayments(Account account)
        {
            //TODO:get the owner of the account,get his personal tags
            //get his personal rules
            //classify his spendings

            TextClassifier classifier = new TextClassifier();

            var operations = account.Operations;

            foreach (var operation in operations)
            {
                var tag = classifier.Categorize(operation.OppositeDescription);
                operation.Tag = tag;
                _repository.SaveOrUpdate(operation);
            }
        }
Exemple #6
0
        public void PredictLabel_ShouldReturnANullLabelAndLogTheExpectedMessages_WhenContainsAllIndexAverageValuesEqualToZero()
        {
            // Arrange
            List <string>   actualLogMessages = new List <string>();
            Action <string> fakeLoggingAction
                = (message) => actualLogMessages.Add(message);
            TextClassifierComponents components
                = new TextClassifierComponents(
                      new NGramTokenizer(),
                      new SimilarityIndexCalculatorJaccard(),
                      TextClassifierComponents.DefaultRoundingFunction,
                      TextClassifierComponents.DefaultTextTruncatingFunction,
                      fakeLoggingAction);
            TextClassifier textClassifier = new TextClassifier(components, new TextClassifierSettings());
            string         truncatedText
                = TextClassifierComponents.DefaultTextTruncatingFunction.Invoke(
                      ObjectMother.TextClassifier_Text3,
                      TextClassifierSettings.DefaultTruncateTextInLogMessagesAfter);
            List <string> expectedLogMessages = new List <string>()
            {
                MessageCollection.TextClassifier_AttemptingToPredictLabel,
                MessageCollection.TextClassifier_FollowingTextHasBeenProvided.Invoke(truncatedText),
                MessageCollection.TextClassifier_FollowingTokenizationStrategyWillBeUsed.Invoke(new TokenizationStrategy()),
                MessageCollection.TextClassifier_FollowingNGramsTokenizerRuleSetWillBeUsed.Invoke(new NGramTokenizerRuleSet()),
                MessageCollection.TextClassifier_XLabeledExamplesHaveBeenProvided.Invoke(ObjectMother.TextClassifier_LabeledExamples),
                MessageCollection.TextClassifier_ProvidedTextHasBeenTokenizedIntoXNGrams.Invoke(ObjectMother.TextClassifier_Text3_NGrams),

                MessageCollection.TextClassifier_ComparingProvidedTextAgainstFollowingLabeledExample.Invoke(ObjectMother.TextClassifier_LabeledExamples[0]),
                MessageCollection.TextClassifier_CalculatedSimilarityIndexValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes[0].Value),
                MessageCollection.TextClassifier_RoundedSimilarityIndexValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes[0].Value),
                MessageCollection.TextClassifier_FollowingSimilarityIndexObjectHasBeenAddedToTheList.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes[0]),

                MessageCollection.TextClassifier_ComparingProvidedTextAgainstFollowingLabeledExample.Invoke(ObjectMother.TextClassifier_LabeledExamples[1]),
                MessageCollection.TextClassifier_CalculatedSimilarityIndexValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes[1].Value),
                MessageCollection.TextClassifier_RoundedSimilarityIndexValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes[1].Value),
                MessageCollection.TextClassifier_FollowingSimilarityIndexObjectHasBeenAddedToTheList.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes[1]),

                MessageCollection.TextClassifier_TokenizedTextHasBeenComparedAgainstTheProvidedLabeledExamples,
                MessageCollection.TextClassifier_XSimilarityIndexObjectsHaveBeenComputed.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexes),

                MessageCollection.TextClassifier_FollowingUniqueLabelsHaveBeenFound.Invoke(ObjectMother.TextClassifier_Text3_UniqueLabels),

                MessageCollection.TextClassifier_CalculatingIndexAverageForTheFollowingLabel.Invoke(ObjectMother.TextClassifier_Text3_UniqueLabels[0]),
                MessageCollection.TextClassifier_CalculatedSimilarityIndexAverageValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages[0].Value),
                MessageCollection.TextClassifier_RoundedSimilarityIndexAverageValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages[0].Value),
                MessageCollection.TextClassifier_FollowingSimilarityIndexAverageObjectHasBeenAddedToTheList.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages[0]),

                MessageCollection.TextClassifier_CalculatingIndexAverageForTheFollowingLabel.Invoke(ObjectMother.TextClassifier_Text3_UniqueLabels[1]),
                MessageCollection.TextClassifier_CalculatedSimilarityIndexAverageValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages[1].Value),
                MessageCollection.TextClassifier_RoundedSimilarityIndexAverageValueIs.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages[1].Value),
                MessageCollection.TextClassifier_FollowingSimilarityIndexAverageObjectHasBeenAddedToTheList.Invoke(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages[1]),

                MessageCollection.TextClassifier_XSimilarityIndexAverageObjectsHaveBeenComputed(ObjectMother.TextClassifier_Text3_SimilarityIndexAverages),

                MessageCollection.TextClassifier_FollowingVerificationHasFailed.Invoke("ContainsAtLeastOneIndexAverageThatIsNotZero"),

                MessageCollection.TextClassifier_PredictedLabelIs.Invoke(ObjectMother.TextClassifier_Text3_Label),
                MessageCollection.TextClassifier_PredictionHasFailedTryIncreasingTheAmountOfProvidedLabeledExamples
            };

            // Act
            TextClassifierResult actual
                = textClassifier.PredictLabel(
                      ObjectMother.TextClassifier_Text3,
                      ObjectMother.TextClassifier_LabeledExamples);

            // Assert
            Assert.IsTrue(
                ObjectMother.AreEqual(
                    ObjectMother.TextClassifier_Text3_TextClassifierResult,
                    actual
                    ));
            Assert.AreEqual(expectedLogMessages, actualLogMessages);
        }