public static NRCRecord FindRecord(this INRCDictionary dictionary, IWordItem word)
        {
            NRCRecord nrcRecord = null;

            foreach (var text in word.GetPossibleText())
            {
                nrcRecord = dictionary.FindRecord(text);
                if (nrcRecord != null)
                {
                    break;
                }
            }

            if (nrcRecord == null)
            {
                return(null);
            }

            nrcRecord = (NRCRecord)nrcRecord.Clone();
            if (word.Relationship?.Inverted != null)
            {
                nrcRecord.Invert();
            }

            return(nrcRecord);
        }
Beispiel #2
0
        private void PopulateAttributes(SentimentVector vector, WordEx word, IWordItem original)
        {
            var record = nrcDictionary.FindRecord(word);

            vector.ExtractData(record);
            word.Emotions   = record?.GetDefinedCategories().ToArray();
            word.Attributes = original.Inquirer.Records.SelectMany(item => item.Description.Attributes).ToArray();
        }
Beispiel #3
0
        public void Save(ProcessingContext context)
        {
            var vector = new SentimentVector();

            if (ExtractStyle)
            {
                foreach (var word in context.Processed.Words)
                {
                    vector.ExtractData(dictionary.FindRecord(word));
                }
            }

            lock (csvDataOut)
            {
                csvDataOut.WriteField(context.Original.Id);
                csvDataOut.WriteField(context.Original.DocumentTime);
                csvDataOut.WriteField(context.Original.Stars);
                csvDataOut.WriteField(context.Adjustment.Rating.StarsRating);
                csvDataOut.WriteField(context.Review.GetAllSentiments().Length);
                if (ExtractStyle)
                {
                    csvDataOut.WriteField(vector.Anger);
                    csvDataOut.WriteField(vector.Anticipation);
                    csvDataOut.WriteField(vector.Disgust);
                    csvDataOut.WriteField(vector.Fear);
                    csvDataOut.WriteField(vector.Joy);
                    csvDataOut.WriteField(vector.Sadness);
                    csvDataOut.WriteField(vector.Surprise);
                    csvDataOut.WriteField(vector.Trust);
                    csvDataOut.WriteField(vector.Total);
                }

                csvDataOut.NextRecord();
                csvDataOut.Flush();
            }

            if (Debug)
            {
                resultsWriter.WriteObject(context.Processed);
            }
        }
        public static SentimentVector Extract(this INRCDictionary dictionary, IEnumerable <WordEx> words)
        {
            if (dictionary is null)
            {
                throw new ArgumentNullException(nameof(dictionary));
            }

            if (words is null)
            {
                throw new ArgumentNullException(nameof(words));
            }

            var vector = new SentimentVector();

            foreach (var word in words)
            {
                vector.ExtractData(dictionary.FindRecord(word));
            }

            return(vector);
        }
        public static void ExtractToVector(this INRCDictionary dictionary, SentimentVector vector, IEnumerable <IWordItem> words)
        {
            if (dictionary is null)
            {
                throw new ArgumentNullException(nameof(dictionary));
            }

            if (vector is null)
            {
                throw new ArgumentNullException(nameof(vector));
            }

            if (words is null)
            {
                throw new ArgumentNullException(nameof(words));
            }

            foreach (var word in words)
            {
                vector.ExtractData(dictionary.FindRecord(word));
            }
        }
        public DocumentStyle Extract()
        {
            TextBlock text  = new TextBlock(tagger, inquirer, frequency, document.Sentences.ToArray());
            var       style = new DocumentStyle();

            style.Obscrunity        = text.VocabularyObscurity.GetData();
            style.CharactersSurface = text.Surface.Characters.GetData();
            style.SentenceSurface   = text.Surface.Sentence.GetData();
            style.WordSurface       = text.Surface.Words.GetData();
            style.Readability       = text.Readability.GetData();
            style.Syntax            = text.SyntaxFeatures.GetData();

            foreach (var sentence in document.Sentences.Where(item => item.Words.Count > 0))
            {
                text = new TextBlock(tagger, inquirer, frequency, new[] { sentence });
                var sentenceStyle = new SentenceStyle();
                sentenceStyle.Sentence = sentence;
                style.Sentences.Add(sentenceStyle);
                text.Surface.Words.Load();
                sentenceStyle.WordSurface = text.Surface.Words.GetData();
                foreach (var word in sentence.Words)
                {
                    var wordStyle = new WordStyle(word);
                    wordStyle.Inquirer = text.InquirerFinger.GetData(word);
                    var record = nrcDictionary.FindRecord(word.Text);
                    if (record != null)
                    {
                        wordStyle.NRC = record;
                    }

                    if (wordStyle.HasValue)
                    {
                        sentenceStyle.Words.Add(wordStyle);
                    }
                }
            }

            return(style);
        }