Ejemplo n.º 1
0
        public async Task TestReview(bool disableInvert)
        {
            var txt    = "#paulryan #killed #rnc2016 #america #died #wisconsin no more EMOTICON_kissing_heart since you gave up on #trump, you don't represent #us";
            var stream = new DictionaryStream(Path.Combine(path, "Library", "Standard", "EmotionLookupTable.txt"), new FileStreamSource());
            var data   = stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase);

            foreach (var item in data.Keys.ToArray().Where(k => !k.StartsWith("EMOTICON")))
            {
                data.Remove(item);
            }

            var lexicon = SentimentDataHolder.PopulateEmotionsData(data);

            ActualWordsHandler.InstanceOpen.Container.Context.DisableInvertors = disableInvert;

            var result = await ActualWordsHandler.InstanceOpen.TextSplitter.Process(new ParseRequest(txt)).ConfigureAwait(false);

            var document = result.Construct(ActualWordsHandler.InstanceOpen.WordFactory);

            ActualWordsHandler.InstanceOpen.Container.Context.Lexicon = lexicon;
            Text.Data.IParsedReview review = ActualWordsHandler.InstanceOpen.Container.Resolve <Func <Document, IParsedReviewManager> >()(document).Create();
            MachineLearning.Mathematics.RatingData ratings = review.CalculateRawRating();
            Assert.AreEqual(1, review.Sentences.Count);
            Assert.AreEqual(disableInvert, ratings.IsPositive);
        }
Ejemplo n.º 2
0
        private void ReadSlang()
        {
            var stream = new DictionaryStream(Path.Combine(resourcesPath, "SlangLookupTable.txt"), new FileStreamSource());

            foreach (var item in stream.ReadDataFromStream(item => item))
            {
                replacements[item.Word] = item.Value;
            }
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            var path = ActualWordsHandler.InstanceSimple.Configuration.GetConfiguration("Resources");

            path = Path.Combine(path, @"Library\Standard");
            var stream = new DictionaryStream(Path.Combine(path, "EmotionLookupTable.txt"), new FileStreamSource());
            var data   = stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase);

            sentimentData = SentimentDataHolder.PopulateEmotionsData(data);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            var loader = new LexiconConfigLoader(ApplicationLogging.LoggerFactory.CreateLogger <LexiconConfigLoader>());
            var config = loader.Load(TestContext.CurrentContext.TestDirectory);
            var path   = config.GetFullPath(item => item.Model);
            var stream = new DictionaryStream(Path.Combine(path, "EmotionLookupTable.txt"), new FileStreamSource());
            var data   = stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase);

            sentimentData = SentimentDataHolder.PopulateEmotionsData(data);
        }
Ejemplo n.º 5
0
        private void ReadIdioms()
        {
            var stream = new DictionaryStream(Path.Combine(resourcesPath, "IdiomLookupTable.txt"), new FileStreamSource());

            idiomsSentiment = stream.ReadDataFromStream(int.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase);
            foreach (var item in idiomsSentiment.ToArray())
            {
                var arr         = item.Key.Where(c => (char.IsLetterOrDigit(c) || c == '-')).ToArray();
                var alternative = new string(arr);
                replacements[item.Key]       = alternative;
                idiomsSentiment[alternative] = item.Value;
            }
        }
        public void Construct()
        {
            var path   = ConfigurationManager.AppSettings["resources"];
            var file   = Path.Combine(TestContext.CurrentContext.TestDirectory, path, @"Embedded\Dictionary\NRC.txt");
            var stream = new DictionaryStream(file, new FileStreamSource());
            var table  = stream.ReadDataFromStream(double.Parse).ToArray();

            Assert.AreEqual(141820, table.Length);
            file = Path.Combine(TestContext.CurrentContext.TestDirectory, "NRC.dat");
            if (File.Exists(file))
            {
                File.Delete(file);
            }

            var outStream = new CompressedDictionaryStream(file, new FileStreamSource());

            DictionaryStreamExtension.WriteStream(file, table.Select(item => new KeyValuePair <string, double>(item.Word, item.Value)), Encoding.ASCII);
            table = outStream.ReadDataFromStream(double.Parse).ToArray();
            Assert.AreEqual(141820, table.Length);
        }
Ejemplo n.º 7
0
        private Dictionary <string, double> ReadTextData(string file)
        {
            var stream = new DictionaryStream(Path.Combine(config.LexiconPath, file), new FileStreamSource());

            return(stream.ReadDataFromStream(double.Parse).ToDictionary(item => item.Word, item => item.Value, StringComparer.OrdinalIgnoreCase));
        }