예제 #1
0
        public void Load()
        {
            Dictionary <string, int> map = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);

            foreach (var property in mapDefinition.ActualProperties)
            {
                var fields = mapDefinition[property];
                foreach (var field in fields)
                {
                    if (field.ValueType == typeof(bool))
                    {
                        map[property] = 0;
                    }
                }
            }

            map["Positive"] = 0;
            map["Negative"] = 0;
            foreach (var wordEx in Text.Words)
            {
                InquirerDefinition        definition = wordEx.GetPossibleVariation(word => inquirer.GetDefinitions(word));
                Dictionary <string, bool> table      = new Dictionary <string, bool>();
                wordLevelFingerPrint[wordEx] = table;
                foreach (var inquirerRecord in definition.Records)
                {
                    if (inquirerRecord.Description.Harward.Sentiment.Type != PositivityType.Neutral)
                    {
                        string sentiment = inquirerRecord.Description.Harward.Sentiment.Type.ToString();
                        map[sentiment]   = map[sentiment] + 1;
                        table[sentiment] = true;
                    }

                    DataTree tree = new DataTree(inquirerRecord.Description, mapDefinition);
                    foreach (var leaf in tree.AllLeafs)
                    {
                        if (!(leaf.Value is bool) ||
                            !(bool)leaf.Value)
                        {
                            continue;
                        }

                        map[leaf.Name]   = map[leaf.Name] + 1;
                        table[leaf.Name] = true;
                    }
                }
            }

            Dictionary <string, double> mapProbability = new Dictionary <string, double>(StringComparer.OrdinalIgnoreCase);

            foreach (var record in map)
            {
                mapProbability[record.Key] = (double)record.Value / Text.Words.Length;
            }

            InquirerProbabilities = new DataTree(null, mapDefinition, new DictionaryDataItemFactory(mapProbability));
        }
예제 #2
0
 public static bool HasDefined(this InquirerDefinition definition, Func <InquirerRecord, bool> condition)
 {
     return(definition.Records.Any(condition));
 }