Ejemplo n.º 1
0
        public void RemoveComponent(ISchemeComponent component)
        {
            if (!Components.Contains(component))
            {
                return;
            }

            //do something about duplicated Id code
            if (component is Argument)
            { //fix arguments order
                var argument    = component as Argument;
                var argsGreater = from x in Arguments
                                  where x.Order > argument.Order
                                  select x;
                foreach (var arg in argsGreater)
                {
                    arg.Order -= 1;
                }
                _numArgs -= 1;
            }
            if (component is Condition)
            {
                var condition    = component as Condition;
                var condsGreater = from x in Conditions
                                   where x.ID > condition.ID
                                   select x;
                foreach (var cond in condsGreater)
                {
                    cond.ID -= 1;
                }
                _numConds -= 1;
            }
            Components.Remove(component);
        }
Ejemplo n.º 2
0
        //why not just Rules.Add()?
        //FUG
        public Rule AddRule(RuleType type, OntologyNode.Attribute attr, ISchemeComponent reference, OntologyNode.Attribute inputAttr)//, string value)
        {
            Rule rule = new Rule(attr, reference, inputAttr);

            _rules.Add(attr.Name, rule);
            return(rule);
        }
Ejemplo n.º 3
0
 public void RemoveUpper(ISchemeComponent component)
 {
     if (Arg1 == component)
     {
         Arg1 = null;
     }
     else if (Arg2 == component)
     {
         Arg2 = null;
     }
 }
Ejemplo n.º 4
0
        public static void RemoveSchemeConnection(Connector src, Connector dst)
        {
            ISchemeComponent dstComponent = dst.ParentNode.Tag as ISchemeComponent;

            if (dst.Tag is OntologyNode.Attribute)
            {
                dstComponent.Free(dst.Tag as OntologyNode.Attribute);
            }
            else
            { ///
            }
        }
Ejemplo n.º 5
0
        private void NV_NodeRemoving(object sender, System.Windows.RoutedEventArgs e)
        {
            var node = e.Source as network.Node;

            ISchemeComponent comp = ((network.Node)e.Source).Tag as ISchemeComponent;
            var oneighbors        = node.OutgoingNeighbors;

            foreach (var neighbor in oneighbors)
            {
                (neighbor.Tag as ISchemeComponent).RemoveUpper(comp);
            }
            CurrentScheme.RemoveComponent(comp);
            Console.WriteLine("NV_NodeRemoving!");
        }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="type"></param>
 /// <param name="attr"></param>
 /// <param name="reference"></param>
 /// <param name="inputAttr">may be null if 'reference' is a functor</param>
 public Rule(OntologyNode.Attribute attr, ISchemeComponent reference, OntologyNode.Attribute inputAttr)
 {
     if (reference is Argument)
     {
         Type = RuleType.ATTR;
     }
     else if (reference is Functor)
     {
         Type = RuleType.FUNC;
     }
     else
     {
         Type = RuleType.DEF;
     }
     Attribute      = attr;
     Reference      = reference;
     InputAttribute = inputAttr;
     Default        = "";
 }
Ejemplo n.º 7
0
        public void RemoveUpper(ISchemeComponent upper)
        {
            var rulesCopy = new Dictionary <string, Rule>(Rules);

            //rulesCopy.AddRange(Rules);
            foreach (var rule in rulesCopy)
            {
                if (rule.Value.Reference == upper)
                {
                    var defaultValue = rule.Value.Default;
                    Rules.Remove(rule.Key);
                    if (defaultValue != null)
                    {
                        Rules[rule.Key] = new Rule(rule.Value.Attribute, defaultValue);
                    }
                }
            }
            if (upper == EditObject)
            {
                EditObject = null;
            }
        }
Ejemplo n.º 8
0
 public void RemoveUpper(ISchemeComponent upper)
 {
 }
Ejemplo n.º 9
0
        public static FactSchemeBank FromXml(XElement root, List <OntologyNode> ontology, Vocabularies.Vocabulary themes)
        {
            FactSchemeBank bank = new FactSchemeBank();

            foreach (XElement xscheme in root.Elements())
            {
                Scheme scheme = new Scheme(xscheme.Attribute(FatonConstants.XML_SCHEME_NAME).Value);
                scheme.Segment = xscheme.Attribute(FatonConstants.XML_SCHEME_SEGMENT)?.Value;
                if (scheme.Segment == null)
                {
                    scheme.Segment = "";
                }
                var arguments = from x in xscheme.Elements()
                                where x.Name.LocalName == FatonConstants.XML_ARGUMENT_TAG
                                select x;
                var results = from x in xscheme.Elements()
                              where x.Name.LocalName == FatonConstants.XML_RESULT_TAG
                              select x;
                var conditionComplexes = from x in xscheme.Elements()
                                         where x.Name.LocalName == FatonConstants.XML_CONDITIONCOMPLEX_TAG
                                         select x;
                var functors = from x in xscheme.Elements()
                               where x.Name.LocalName == "Functor"
                               select x;
                foreach (XElement xarg in arguments)
                {
                    Argument arg = null;
                    if (xarg.Attribute(FatonConstants.XML_ARGUMENT_OBJECTTYPE).Value.Equals(ArgumentType.TERMIN.ToString()))
                    {
                        Termin term;
                        string termName = xarg.Attribute("ClassName").Value;
                        if (termName.StartsWith("#"))
                        {
                            term = DiglexFunctions.LexFunctions.First(x => x.Name == termName);
                        }
                        else
                        {
                            term = themes[termName];
                        }
                        arg = scheme.AddArgument(term);
                        var varattrs = from x in xarg.Elements() where x.Name == "VarAttr" select x;
                        foreach (var attr in varattrs)
                        {
                            arg.Attributes.Add(new OntologyNode.Attribute(OntologyNode.Attribute.AttributeType.STRING, attr.Attribute("Name").Value, true));
                        }
                    }
                    else
                    {
                        OntologyClass argKlass;
                        foreach (OntologyClass klass in ontology)
                        {
                            argKlass = klass.FindChild(xarg.Attribute(FatonConstants.XML_ARGUMENT_CLASSNAME).Value);
                            if (argKlass == null)
                            {
                                continue;
                            }
                            arg = scheme.AddArgument(argKlass);
                            break;
                        }
                    }
                    arg.Order = uint.Parse(xarg.Attribute(FatonConstants.XML_ARGUMENT_ORDER).Value);
                    foreach (XElement xcond in xarg.Elements(FatonConstants.XML_ARGUMENT_CONDITION_TAG))
                    {
                        var condition  = new Argument.ArgumentCondition();
                        var attrName   = xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_ATTRNAME).Value;
                        var type       = xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_TYPE).Value;
                        var comparType = xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_OPERATION).Value;
                        var value      = xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_DATA).Value;
                        condition.Operation = (ArgumentConditionOperation)Enum.Parse(typeof(ArgumentConditionOperation), comparType);
                        condition.CondType  = (ArgumentConditionType)Enum.Parse(typeof(ArgumentConditionType), type);
                        condition.Data      = value;
                        var attr = arg.Attributes.Find(x => x.Name.Equals(attrName));
                        arg.Conditions[attr].Add(condition);
                    }
                }
                foreach (XElement xres in results)
                {
                    OntologyClass resKlass = null;
                    Result        result;
                    foreach (OntologyClass klass in ontology)
                    {
                        resKlass = klass.FindChild(xres.Attribute(FatonConstants.XML_RESULT_CLASSNAME).Value);
                        if (resKlass != null)
                        {
                            break;
                        }
                    }
                    if (resKlass == null)
                    {
                        continue;
                    }
                    result = scheme.AddResult(resKlass, xres.Attribute(FatonConstants.XML_RESULT_NAME).Value);
                    foreach (XElement xrul in xres.Elements())
                    {
                        Result.RuleType ruleType = (Result.RuleType)Enum.Parse(typeof(Result.RuleType),
                                                                               xrul.Attribute(FatonConstants.XML_RESULT_RULE_TYPE).Value);
                        OntologyNode.Attribute attr = result.Reference.AllAttributes.Find(x => x.Name == xrul.Attribute(FatonConstants.XML_RESULT_RULE_ATTR).Value);
                        if (ruleType == Result.RuleType.ATTR)
                        {
                            Argument arg = scheme.Arguments.Find(x => x.Order == int.Parse(xrul.Attribute(FatonConstants.XML_RESULT_RULE_RESOURCE).Value));
                            OntologyNode.Attribute inputAttr = null;
                            if (attr.AttrType != OntologyNode.Attribute.AttributeType.OBJECT)
                            {
                                inputAttr = arg.Attributes.Find(x => x.Name == xrul.Attribute(FatonConstants.XML_RESULT_RULE_ATTRFROM).Value);
                            }
                            var rule = result.AddRule(ruleType, attr, arg, inputAttr);
                            rule.ResourceType = (RuleResourceType)Enum.Parse(typeof(RuleResourceType),
                                                                             xrul.Attribute(FatonConstants.XML_RESULT_RULE_RESOURCETYPE).Value);
                            if (xrul.Attribute("Default") != null)
                            {
                                rule.Default = xrul.Attribute("Default").Value;
                            }
                        }

                        if (ruleType == Result.RuleType.FUNC)
                        {
                            Functor fun = FunctorFactory.Build(xrul.Attribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_NAME).Value);
                            fun.CID = UID.Take(uint.Parse(xrul.Attribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_ID).Value));
                            var inputs = xrul.Elements(FatonConstants.XML_RESULT_RULE_FUNCTOR_INPUT);
                            fun.Inputs.Clear();
                            foreach (var xinput in inputs)
                            {
                                var resourceType = (RuleResourceType)Enum.Parse(typeof(RuleResourceType),
                                                                                xinput.Attribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_RESOURCETYPE).Value);
                                ISchemeComponent       resource = null;
                                OntologyNode.Attribute value    = null;
                                if (resourceType == RuleResourceType.ARG)
                                {
                                    resource = scheme.Arguments.Find(x => x.Order == int.Parse(xinput.Attribute(FatonConstants.XML_RESULT_RULE_RESOURCE).Value));
                                    value    = ((Argument)resource).Attributes.Find(x => x.Name == xinput.Attribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_ATTRFROM).Value);
                                }
                                else
                                {
                                };
                                var input = new Functor.FunctorInput("input");
                                input.Set(value, resource);
                                fun.Inputs.Add(input);
                            }
                            scheme.Components.Add(fun);
                            var rule = result.AddRule(ruleType, attr, fun, fun.Output);
                            if (xrul.Attribute("Default") != null)
                            {
                                rule.Default = xrul.Attribute("Default").Value;
                            }
                        }
                    }
                    if (xres.Attribute(FatonConstants.XML_RESULT_ARGEDIT) != null)
                    {
                        result.Type       = ResultType.EDIT;
                        result.EditObject = scheme.Arguments.Find(x => x.Order == int.Parse(xres.Attribute(FatonConstants.XML_RESULT_ARGEDIT).Value));
                    }
                }

                foreach (var xcomplex in conditionComplexes)
                {
                    var argName1   = uint.Parse(xcomplex.Attribute("Arg1").Value);
                    var argName2   = uint.Parse(xcomplex.Attribute("Arg2").Value);
                    var conditions = xcomplex.Elements();
                    foreach (var xcond in conditions)
                    {
                        var cond = scheme.AddCondition();
                        cond.ID        = uint.Parse(xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_ID).Value);
                        cond.Type      = (ConditionType)Enum.Parse(typeof(ConditionType), xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_TYPE).Value);
                        cond.Operation = (ConditionOperation)Enum.Parse(typeof(ConditionOperation), xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_OPERATION).Value);

                        var arg1 = scheme.Arguments.Find(x => x.Order == argName1);
                        var arg2 = scheme.Arguments.Find(x => x.Order == argName2);
                        cond.Arg1 = arg1;
                        cond.Arg2 = arg2;
                        cond.Data = xcond.Attribute(FatonConstants.XML_ARGUMENT_CONDITION_DATA).Value;
                    }
                }
                bank.Schemes.Add(scheme);
            }

            return(bank);
        }
Ejemplo n.º 10
0
 public void Set(OntologyNode.Attribute attr, ISchemeComponent attrSource)
 {
     this.value  = attr;
     this.source = attrSource;
 }
Ejemplo n.º 11
0
 public void RemoveUpper(ISchemeComponent component)
 {
     throw new NotImplementedException();
 }