Exemplo n.º 1
0
        private double GetNaturalLanguageDataScore(NaturalLanguageData target, NaturalLanguageData existing)
        {
            var sentencesScore = 0.0;

            if (target.sentences == null || existing.sentences == null)
            {
                return(0);
            }
            foreach (var targetSentence in target.sentences)
            {
                var bestScore = 0.0;
                foreach (var existingSentence in existing.sentences)
                {
                    var score = _sentenceScoreService.GetScore(targetSentence, existingSentence);
                    if (score > bestScore)
                    {
                        bestScore = score;
                    }
                }
                sentencesScore += bestScore;
            }

            var maxSentencesScore = (double)target.sentences.Count;

            if (maxSentencesScore == 0)
            {
                return(0);
            }
            return(sentencesScore / maxSentencesScore);
        }
        public void GetSentenceScore()
        {
            var service       = new SentenceScoreService(new OpenieScoreService(), new SubjectPredicateObjectScoreService(new SubjectPredicateObjectTokenScoreService()), new TokenScoreService(), new SentimentScoreService(), new SentenceTypeScoreService(), new VoiceScoreService());
            var targetTriples = new List <OpenieTriple>();

            targetTriples.Add(new OpenieTriple {
                Subject = "sharks", Relation = "eat", Object = "meat"
            });
            var target = new Sentence {
                OpenieTriples = targetTriples, Subject = new Token {
                    Word = "sharks"
                }, Object = new Token {
                    Word = "sharks"
                }, Predicate = new Token {
                    Word = "sharks"
                }
            };

            var result = service.GetScore(target, target);

            Assert.Equal(1, result);
        }
        public void TestRealSentences()
        {
            var service      = GetAnalyzationService();
            var conversation = new Conversation();

            conversation.name      = "Test";
            conversation.responses = new List <AnalyzedChat>();
            var analyzedChat = new AnalyzedChat
            {
                botName = "sharkbot",
                chat    = new Chat
                {
                    message = "suh",
                    user    = "******",
                    botName = "sharkbot"
                }
            };

            conversation.responses.Add(analyzedChat);

            analyzedChat = new AnalyzedChat
            {
                botName = "sharkbot",
                chat    = new Chat
                {
                    message = "hey",
                    user    = "******",
                    botName = "sharkbot"
                }
            };
            conversation.responses.Add(analyzedChat);

            analyzedChat = new AnalyzedChat
            {
                botName = "sharkbot",
                chat    = new Chat
                {
                    message = "I like to ride my bike at night.",
                    user    = "******",
                    botName = "sharkbot"
                }
            };
            conversation.responses.Add(analyzedChat);

            analyzedChat = new AnalyzedChat
            {
                botName = "sharkbot",
                chat    = new Chat
                {
                    message = "suh dude",
                    user    = "******",
                    botName = "sharkbot"
                }
            };
            conversation.responses.Add(analyzedChat);

            var analyzedConversation = service.AnalyzeConversationAsync(conversation);
            var target    = analyzedConversation.responses[0].naturalLanguageData.sentences[0];
            var existing  = analyzedConversation.responses[1].naturalLanguageData.sentences[0];
            var existing2 = analyzedConversation.responses[2].naturalLanguageData.sentences[0];
            var existing3 = analyzedConversation.responses[3].naturalLanguageData.sentences[0];

            var scoreService = new SentenceScoreService(new OpenieScoreService(), new SubjectPredicateObjectScoreService(new SubjectPredicateObjectTokenScoreService()), new TokenScoreService(), new SentimentScoreService(), new SentenceTypeScoreService(), new VoiceScoreService());
            var result       = scoreService.GetScore(target, existing);
            var result2      = scoreService.GetScore(target, existing2);
            var result3      = scoreService.GetScore(target, existing3);
        }