Exemplo n.º 1
0
        static public void Parse(Concept IForm)
        {
            if (IForm.Type == "KNOWLEDGE")
            {
                string lhs = Utils.LSplit(IForm.Name, "=");
                string val = Utils.RSplit(IForm.Name, "=");

                string target = Utils.LSplit(lhs, ".");
                string prop   = Utils.RSplit(lhs, ".");

                var    tmp  = Utils.ExtractFromBracket(target, '[', ']');
                string type = null;
                if (tmp != null)
                {
                    type = tmp[0];
                    target.Replace("[" + type + "]", "");
                }

                if (type == null)
                {
                    Concept c = ConceptBase.Find(target);
                    if (c == null)
                    {
                        c = new Concept(target);
                        c.SetProperty(prop, val);
                        ConceptBase.Add(c);
                    }
                    else
                    {
                        c.SetProperty(prop, val);
                    }
                }
                else
                {
                    Concept c = ConceptBase.Find(target, type);
                    if (c == null)
                    {
                        c = new Concept(target, type);
                        c.SetProperty(prop, val);
                        ConceptBase.Add(c);
                    }
                    else
                    {
                        c.SetProperty(prop, val);
                    }
                }
            }
            else if (IForm.Type == "RULE")
            {
                Rule r = Rule.FromString(IForm.Name);
                RuleBase.Remove(r.GetPattern());
                RuleBase.Add(r);
            }
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------------------------

        /// <summary>
        /// Return a Concept from a UTF-8 text file.
        /// </summary>
        /// <param name="FilePath">File path</param>
        /// <returns></returns>
        static public Concept FromFile(string FilePath)
        {
            Concept c = new Concept(Path.GetFileNameWithoutExtension(FilePath));

            foreach (string line in File.ReadAllLines(FilePath, Encoding.UTF8))
            {
                c.SetProperty(Utils.LSplit(line, "="), Utils.RSplit(line, "="));
            }

            if (c.GetProperty("PARENT") != null)
            {
                c.Parent = ConceptBase.Find(c.GetProperty("PARENT"));
            }

            return(c);
        }