示例#1
0
        public async Task TestBasic(string text, int rating, int totalSentiments, bool disableInvertor)
        {
            ActualWordsHandler.InstanceSimple.Container.Context.DisableFeatureSentiment = disableInvertor;
            var request = await textSplitter.Process(new ParseRequest(text)).ConfigureAwait(false);

            var document = request.Construct(ActualWordsHandler.InstanceSimple.WordFactory);

            Text.Data.IParsedReview review = ActualWordsHandler.InstanceSimple.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();
            Assert.AreEqual(rating, (int)review.CalculateRawRating().StarsRating);
            SentimentValue[] sentiments = review.GetAllSentiments();
            Assert.AreEqual(totalSentiments, sentiments.Length);
            IRatingAdjustment adjustment = RatingAdjustment.Create(review, new NullMachineSentiment());

            Assert.AreEqual(rating, (int)adjustment.Rating.StarsRating);
        }
示例#2
0
        public async Task <Document> Parse([FromBody] SingleRequestData review)
        {
            if (review == null)
            {
                throw new ArgumentNullException(nameof(review));
            }
            if (review.Id == null)
            {
                review.Id = Guid.NewGuid().ToString();
            }

            if (review.Date == null)
            {
                review.Date = DateTime.UtcNow;
            }

            var document = new Document(review.Text);

            document.Author       = review.Author;
            document.Id           = review.Id;
            document.DocumentTime = review.Date;
            var result = await splitter.Process(new ParseRequest(document)).ConfigureAwait(false);

            return(result.Construct(null));
        }
示例#3
0
        public async Task Process()
        {
            var sentence  = "By default, the application is set to search for new virus definitions daily, but you always can use the scheduling tool to change this.";
            var sentence2 = "Should a virus create serious system problems, AVG creates a rescue disk to scan your computer in MS-DOS mode.";
            var result    = await splitter.Process(new ParseRequest(sentence + ". " + sentence2)).ConfigureAwait(false);

            var document = result.Construct(ActualWordsHandler.InstanceOpen.WordFactory);
            var data     = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();

            Assert.AreEqual(2, data.Sentences.Count);
            Assert.AreEqual(24, data.Sentences[0].Occurrences.Count());
            Assert.AreEqual(12, data.Sentences[0].Occurrences.GetImportant().Count());
            Assert.AreEqual(3, data.Sentences[0].Parts.Count());

            Assert.AreEqual(19, data.Sentences[1].Occurrences.Count());
            Assert.AreEqual(13, data.Sentences[1].Occurrences.GetImportant().Count());
            Assert.AreEqual(2, data.Sentences[1].Parts.Count());
        }
示例#4
0
        public async Task <Document> GetParsed()
        {
            original.Text = repairHandler.Repair(original.Text);
            var document = await splitter.Process(new ParseRequest(original)).ConfigureAwait(false);

            var result = document.Construct(factory);

            result.Status = Status.Parsed;
            return(result);
        }
        public async Task Process(string sentence, int word, int total, string lastPhrase)
        {
            var result = await splitter.Process(new ParseRequest(sentence)).ConfigureAwait(false);

            var document = result.Construct(ActualWordsHandler.InstanceSimple.WordFactory);
            var review   = ActualWordsHandler.InstanceSimple.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();
            var words    = review.ImportantWords.ToArray();
            var phrases  = phraseContructor.GetPhrases(words[word]).ToArray();

            Assert.AreEqual(total, phrases.Length);
            Assert.AreEqual(lastPhrase, phrases.Last().Text);
        }
示例#6
0
        public async Task <LightDocument> Process(ParseRequest request)
        {
            if (splitter == null)
            {
                log.LogInformation("Constructing NEW {0} splitter...", id);
                Interlocked.Exchange(ref current, 0);
                splitter = factory();
            }

            LightDocument result = await splitter.Process(request).ConfigureAwait(false);

            if (Interlocked.Increment(ref current) >= maxProcessing)
            {
                splitter.Dispose();
                splitter = null;
            }

            return(result);
        }
示例#7
0
        public async Task GetCells(bool generate, bool addFeature, int total, string prefix, string lastWord)
        {
            if (addFeature)
            {
                detector.AddFeature(ActualWordsHandler.InstanceSimple.WordFactory.CreateWord("teacher", POSTags.Instance.NN));
            }

            var data = await splitter.Process(new ParseRequest($"I go to school. I like {prefix} teacher.")).ConfigureAwait(false);

            var document = data.Construct(ActualWordsHandler.InstanceSimple.WordFactory);

            review   = ActualWordsHandler.InstanceSimple.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();
            instance = new ExtractReviewTextVector(ActualWordsHandler.InstanceSimple.Container.Resolve <INRCDictionary>(), review)
            {
                GenerateUsingImportantOnly = generate
            };
            IList <TextVectorCell> cells = instance.GetCells();

            Assert.AreEqual(total + 1, cells.Count);

            // feature is always
            Assert.AreEqual(lastWord, cells[cells.Count - 1].Name);
        }