Пример #1
0
        protected override IPredicate BuildPredicate(XPathNavigator predicateElement, bool inHead, bool resolveImmediatly)
        {
            IPredicate predicate;
            string     predicateName  = predicateElement.Name;
            string     predicateValue = predicateElement.Value;

            switch (predicateName)
            {
            // --------- IND predicates --------
            case "Ind":
                string predicateURI = predicateElement.GetAttribute("uri", String.Empty).ToLower();

                switch (predicateURI)
                {
                case "nxbre://expression":
                    if (inHead)
                    {
                        if (resolveImmediatly)
                        {
                            predicate = new Individual(Compilation.Evaluate(predicateValue));
                        }
                        else
                        {
                            predicate = new Formula(Formula.FormulaResolutionType.NxBRE,
                                                    Binder,
                                                    predicateValue);
                        }
                    }
                    else
                    {
                        predicate = new Function(Function.FunctionResolutionType.Binder,
                                                 predicateValue,
                                                 new ExpressionEvaluator(predicateValue),
                                                 String.Empty,
                                                 String.Empty);
                    }
                    break;

                case "nxbre://operator":
                    // NxBRE operators must follow this pattern: operator(uniqueargument)
                    ObjectPair operatorCall = Parameter.ParseOperatorCall(predicateValue);
                    predicate = new Function(Function.FunctionResolutionType.NxBRE,
                                             predicateValue,
                                             null,
                                             (string)operatorCall.First,
                                             (string)operatorCall.Second);
                    break;

                case "nxbre://binder":
                    if (Binder == null)
                    {
                        throw new BREException("No binder available for Individual: " + predicateValue);
                    }

                    if (inHead)
                    {
                        predicate = new Formula(Formula.FormulaResolutionType.Binder,
                                                Binder,
                                                predicateValue);
                    }
                    else
                    {
                        predicate = Binder.AnalyzeIndividualPredicate(new Individual(predicateValue));
                    }

                    break;

                case "":
                    predicate = new Individual(predicateValue);
                    break;

                default:
                    // there is a predicateURI but it is not recognized by the engine so we assimilate it as
                    // a web reference
                    predicate = new Individual(new HyperLink(predicateValue, predicateURI));
                    break;
                }
                break;

            // --------- VAR predicates --------
            case "Var":
                predicate = new Variable(predicateValue);
                break;

            // --------- DATA predicates --------
            case "Data":
                string schemaType = predicateElement.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
                if (schemaType != String.Empty)
                {
                    // remove any preceding namespace, like in "xs:string"
                    if (schemaType.IndexOf(':') >= 0)
                    {
                        schemaType = schemaType.Split(':')[1];
                    }

                    // this is a strongly typed individual
                    predicate = new Individual(Xml.ToClr(predicateValue, schemaType), schemaType);
                }
                else
                {
                    // this is just a string based predicate, using Data was not so wise...
                    predicate = new Individual(predicateValue);
                }

                break;

            // --------- SLOT predicates --------
            case "slot":
                // the first child must be an Ind, we do not support other slot name holders
                if (predicateElement.MoveToFirstChild())
                {
                    if (predicateElement.Name != "Ind")
                    {
                        throw new BREException("Only Ind is accepted as a slot name holder");
                    }
                    string slotName = predicateElement.Value;
                    if (!predicateElement.MoveToNext())
                    {
                        throw new BREException("A slot should contain two children");
                    }
                    predicate = new Slot(slotName, BuildPredicate(predicateElement, inHead, resolveImmediatly));
                }
                else
                {
                    throw new BREException("A slot can not be empty");
                }

                break;

            // --------- UNKNOWN predicates --------
            default:
                throw new BREException("Unsupported predicate type: " + predicateName);
            }

            return(predicate);
        }
Пример #2
0
        protected override IPredicate BuildPredicate(XPathNavigator predicateElement, bool inHead, bool resolveImmediatly)
        {
            IPredicate predicate;
            string     predicateName  = predicateElement.Name;
            string     predicateValue = predicateElement.Value;

            switch (predicateName)
            {
            // --------- IND predicates --------
            case "ind":
                if (predicateValue.ToLower().StartsWith("expr:"))
                {
                    if (inHead)
                    {
                        if (resolveImmediatly)
                        {
                            predicate = new Individual(Compilation.Evaluate(predicateValue));
                        }
                        else
                        {
                            predicate = new Formula(Formula.FormulaResolutionType.NxBRE,
                                                    Binder,
                                                    predicateValue);
                        }
                    }
                    else
                    {
                        predicate = new Function(Function.FunctionResolutionType.Binder,
                                                 predicateValue,
                                                 new ExpressionEvaluator(predicateValue),
                                                 String.Empty,
                                                 String.Empty);
                    }
                }
                else if (predicateValue.ToLower().StartsWith("nxbre:"))
                {
                    // NxBRE functions must follow this pattern: NxBRE:Function(uniqueargument)
                    string[] split = predicateValue.Split(Parameter.PARENTHESIS);
                    predicate = new Function(Function.FunctionResolutionType.NxBRE,
                                             predicateValue,
                                             null,
                                             split[0],
                                             split[1]);
                }
                else if (Binder == null)
                {
                    predicate = new Individual(predicateValue);
                }
                else if ((inHead) && (predicateValue.ToLower().StartsWith("binder:")))
                {
                    predicate = new Formula(Formula.FormulaResolutionType.Binder,
                                            Binder,
                                            predicateValue);
                }
                else if ((inHead) && (predicateValue.EndsWith("()")))
                {
                    predicate = new Formula(Formula.FormulaResolutionType.Binder,
                                            Binder,
                                            predicateValue);
                }
                else
                {
                    predicate = Binder.AnalyzeIndividualPredicate(new Individual(predicateValue));
                }

                break;

            // --------- VAR predicates --------
            case "var":
                predicate = new Variable(predicateValue);
                break;

            // --------- UNKNOWN predicates --------
            default:
                throw new BREException("Unsupported predicate type: " + predicateName);
            }

            return(predicate);
        }