Exemplo n.º 1
0
        /// <summary>
        /// Add new knowledge to the system
        /// </summary>
        /// <param name="name">The name/identifier of the knowledge</param>
        /// <param name="details">The information about the knowledge</param>
        public void Add(string name, Details details)
        {
            if (!Knowledge.ContainsKey(name)) Knowledge[name] = new List<Details>();
            Knowledge[name].Add(details);

            if (!KnowledgeByType.ContainsKey(new Tuple<Types, string>(details.Type, name))) KnowledgeByType[new Tuple<Types, string>(details.Type, name)] = new List<Details>();
            KnowledgeByType[new Tuple<Types, string>(details.Type, name)].Add(details);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the value of some knowledge data
        /// </summary>
        /// <param name="className">The 'class' to check</param>
        /// <param name="variableName">The specific variable to check</param>
        /// <returns>The value of the data</returns>
        public Details GetValue(string className, string variableName)
        {
            if (!className.Contains('_'))
            {
                className = new string(new PorterStemmer().stemTerm(className).ToLower().Where(c => !char.IsPunctuation(c)).ToArray());
            }

            className = className.ToLower();
            variableName = new string(new PorterStemmer().stemTerm(variableName).ToLower().Where(c => !char.IsPunctuation(c)).ToArray());
            variableName = variableName.ToLower();

            try
            {
                Details tmp = Knowledge[className].Find((Details d) => { return d.Name.ToLower() == variableName.ToLower(); });

                //If it's a registered function call, calll the registered function
                if (tmp.Value.StartsWith("[") && tmp.Value.EndsWith("]") &&
                    CSharpFunctionCalls.ContainsKey(tmp.Value.Remove("[").Remove("]").RemoveRange('(', ')')))
                {
                    string[] info = tmp.Value.SubstringRange('(', ')').Remove("(").Remove(")").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    Details[] args = new Details[info.Length];
                    for (int c = 0; c < info.Length; c++)
                    {
                        string[] details = info[c].Split('.');
                        args[c] = Knowledge[(details.Length == 1) ? className : details[0]].Find((Details d) => { return d.Name.ToLower() == ((details.Length == 1) ? info[c] : details[1]).ToLower(); });
                    }

                    string funcName = tmp.Value.Remove("[").Remove("]").RemoveRange('(', ')');
                    tmp = CSharpFunctionCalls[funcName](funcName, args);
                    tmp.Name = variableName;
                }
                return tmp;
            }
            catch (KeyNotFoundException)
            {
                return default(Details);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get a list of 'classes' which have a certain set of variables defined
        /// </summary>
        /// <param name="vals">The variables to check for</param>
        /// <returns>An array of all classes which have the requested variables</returns>
        public string[] GetClassWithValues(params string[] vals)
        {
            List<string> className = new List<string>();

            Details[] tmp = new Details[vals.Length];
            for (int c = 0; c < tmp.Length; c++)
            {
                tmp[c] = new Details()
                {
                    Name = vals[c]
                };
            }

            foreach (string s in Knowledge.Keys)
            {
                if (Knowledge[s].Intersect(tmp, new LambdaComparer<Details>((d, e) => d.Name.ToLower() == e.Name.ToLower())).Any())
                {
                    className.Add(s);
                }
            }

            return className.ToArray();
        }