Exemplo n.º 1
0
 private IEnumerable <SparqlResult> RunTriple(ObjectVariants subject, ObjectVariants objct)
 {
     return(this.predicatePath.CreateTriple(subject, objct, this.q).Aggregate(Enumerable.Repeat(new SparqlResult(this.q), 1),
                                                                              (enumerable, triple) => triple.Run(enumerable)));
 }
        public override IEnumerable <ISparqlGraphPattern> CreateTriple(ObjectVariants subject, ObjectVariants @object, RdfQuery11Translator q)
        {
            var subjectNode = IsInverse ? @object : subject;
            var objectNode  = IsInverse ? subject : @object;

            yield return(new SparqlPathManyTriple(subjectNode, path, objectNode, q));
        }
Exemplo n.º 3
0
 public TripleOVStruct(ObjectVariants s, ObjectVariants p, ObjectVariants o)
 {
     Subject   = s;
     Predicate = p;
     Object    = o;
 }
 public IEnumerable <TripleOVStruct> GetTriplesWithPredicate(ObjectVariants p)
 {
     return(Graph.GetTriplesWithObject(p));
 }
Exemplo n.º 5
0
 public SparqlIriExpression(ObjectVariants sparqlUriNode)
 {
     Const = sparqlUriNode;
 }
Exemplo n.º 6
0
 public SparqlResult Add(ObjectVariants newObj, VariableNode variable)
 {
     this.rowArray[variable.Index] = newObj;
     return(this);
 }
 public bool Contains(ObjectVariants subject, ObjectVariants predicate, ObjectVariants obj)
 {
     return(Graph.Contains(subject, predicate, obj));
 }
Exemplo n.º 8
0
        private IEnumerable <SparqlResult> SetVariablesValues(SparqlResult variableBinding, StoreCallCase @case)
        {
            switch (@case)
            {
            case StoreCallCase.spo:
                return(this.spo(this.Subject, this.Predicate, this.Object, variableBinding));

            case StoreCallCase.spO:
                return(this.store.GetTriplesWithSubjectPredicate(this.Subject, this.Predicate).Select(o => variableBinding.Add(o, this.oVariableNode)));

            case StoreCallCase.sPo:
                return(this.store.GetTriplesWithSubjectObject(this.Subject, this.Object).Select(p => variableBinding.Add(p, this.pVariableNode)));

            case StoreCallCase.sPO:
                return(this.store.GetTriplesWithSubject(this.Subject).Select(t => this.SetValues(variableBinding, t)));

            case StoreCallCase.Spo:
                return(this.store.GetTriplesWithPredicateObject(this.Predicate, this.Object).Select(s => variableBinding.Add(s, this.sVariableNode)));

            case StoreCallCase.SpO:
                return(this.store.GetTriplesWithPredicate(this.Predicate).Select(t => this.SetValues(variableBinding, t)));

            case StoreCallCase.SPo:
                return(this.store.GetTriplesWithObject(this.Object).Select(t => this.SetValues(variableBinding, t)));

            case StoreCallCase.SPO:
                return(this.store.GetTriples((s, p, o) => variableBinding.Add(s, this.sVariableNode, p, this.pVariableNode, o, this.oVariableNode)));


            case StoreCallCase.gspo:
                return(this.spoGraphs(variableBinding));

            case StoreCallCase.gspO:
                return(this.graphs.SelectMany(graph => this.store.NamedGraphs
                                              .GetObject(this.Subject, this.Predicate, graph)

                                              .Select(o => variableBinding.Add(o, this.oVariableNode))));

            case StoreCallCase.gsPo:
                return(this.graphs.SelectMany(graph => this.store.NamedGraphs
                                              .GetPredicate(this.Subject, this.Object, graph)

                                              .Select(p => variableBinding.Add(p, this.pVariableNode))));

            case StoreCallCase.gsPO:
                return(this.graphs.SelectMany(g => this.store
                                              .NamedGraphs
                                              .GetTriplesWithSubjectFromGraph(this.Subject, g)

                                              .Select(quad => this.SetValues(variableBinding, quad))));

            case StoreCallCase.gSpo:
                return(this.graphs.SelectMany(graph => this.store.NamedGraphs
                                              .GetSubject(this.Predicate, this.Object, graph)

                                              .Select(s => variableBinding.Add(s, this.sVariableNode))));

            case StoreCallCase.gSpO:
                return(this.graphs.SelectMany(g => this.store
                                              .NamedGraphs
                                              .GetTriplesWithPredicateFromGraph(this.Predicate, g)

                                              .Select(quad => this.SetValues(variableBinding, quad))));

            case StoreCallCase.gSPo:
                return(this.graphs.SelectMany(g => this.store
                                              .NamedGraphs
                                              .GetTriplesWithObjectFromGraph(this.Object, g)

                                              .Select(quad => this.SetValues(variableBinding, quad))));

            case StoreCallCase.gSPO:
                return(this.graphs.SelectMany(g => this.store.NamedGraphs.GetTriplesFromGraph(g, (s, p, o) => variableBinding.Add(s, this.sVariableNode, p, this.pVariableNode, o, this.oVariableNode))));

            case StoreCallCase.Gspo:
                return((this.variableDataSet.Any()
                        ? this.variableDataSet.Where(g => this.store.NamedGraphs.Contains(this.Subject, this.Predicate, this.Object, g))
                        : this.store.NamedGraphs.GetGraph(this.Subject, this.Predicate, this.Object))

                       .Select(g => variableBinding.Add(g, this.variableDataSet.Variable)));

            case StoreCallCase.GspO:
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(g => this.store
                                                           .NamedGraphs
                                                           .GetObject(this.Subject, this.Predicate, g)

                                                           .Select(o => variableBinding.Add(o, this.oVariableNode, g, this.variableDataSet.Variable))));
                }
                else
                {
                    return(this.store
                           .NamedGraphs
                           .GetTriplesWithSubjectPredicate(this.Subject, this.Predicate)

                           .Select(quad => this.SetValues(variableBinding, quad)));
                }

            // if graphVariable is null, ctor check this.
            case StoreCallCase.GsPo:
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(g => this.store.NamedGraphs.GetPredicate(this.Subject, this.Object, g)

                                                           .Select(p => variableBinding.Add(p, this.pVariableNode, g, this.variableDataSet.Variable))));
                }
                else
                {
                    return(this.store
                           .NamedGraphs
                           .GetTriplesWithSubjectObject(this.Subject, this.Object)

                           .Select(quad => this.SetValues(variableBinding, quad)));
                }

            case StoreCallCase.GsPO:
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(g => this.store
                                                           .NamedGraphs
                                                           .GetTriplesWithSubjectFromGraph(this.Subject, g)

                                                           .Select(quad => this.SetValues(variableBinding, quad))));
                }
                else
                {
                    return(this.store
                           .NamedGraphs
                           .GetTriplesWithSubject(this.Subject)

                           .Select(quad => this.SetValues(variableBinding, quad)));
                }

            case StoreCallCase.GSpo:
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(g => this.store
                                                           .NamedGraphs
                                                           .GetSubject(this.Predicate, this.Object, g)

                                                           .Select(s => variableBinding.Add(s, this.sVariableNode, g, this.variableDataSet.Variable))));
                }
                else
                {
                    return(this.store
                           .NamedGraphs
                           .GetTriplesWithPredicateObject(this.Predicate, this.Object)

                           .Select(quad => this.SetValues(variableBinding, quad)));
                }

            case StoreCallCase.GSpO:
                ObjectVariants predicate = this.Predicate;
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(
                               g => this.store.NamedGraphs.GetTriplesWithPredicateFromGraph(predicate, g)

                               .Select(quad => this.SetValues(variableBinding, quad))));
                }
                else
                {
                    return(this.store.NamedGraphs.GetTriplesWithPredicate(predicate)

                           .Select(quad => this.SetValues(variableBinding, quad)));
                }

            case StoreCallCase.GSPo:
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(g => this.store
                                                           .NamedGraphs
                                                           .GetTriplesWithObjectFromGraph(this.Object, g))

                           .Select(quad => this.SetValues(variableBinding, quad)));
                }
                return(this.store
                       .NamedGraphs
                       .GetTriplesWithObject(this.Object)

                       .Select(quad => this.SetValues(variableBinding, quad)));

            case StoreCallCase.GSPO:
                if (this.variableDataSet.Any())
                {
                    return(this.variableDataSet.SelectMany(g => this.store
                                                           .NamedGraphs
                                                           .GetTriplesFromGraph(g, (s, p, o) =>
                                                                                variableBinding.Add(s, this.sVariableNode, p, this.pVariableNode, o, this.oVariableNode, g, this.variableDataSet.Variable))));
                }
                return(this.store
                       .NamedGraphs
                       .GetAll((s, p, o, g) =>
                               variableBinding.Add(s, this.sVariableNode, p, this.pVariableNode, o, this.oVariableNode, g, this.variableDataSet.Variable)));

            default:
                throw new ArgumentOutOfRangeException("case");
            }
        }
 public IEnumerable <ObjectVariants> GetSubjects(ObjectVariants pred, ObjectVariants obj)
 {
     return(Graph.GetSubjects(pred, obj));
 }
Exemplo n.º 10
0
 public void Add(ObjectVariants s, ObjectVariants p, ObjectVariants o)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public IEnumerable <ObjectVariants> GetTriplesWithSubjectObject(ObjectVariants subj, ObjectVariants obj)
 {
     return(Graph.GetTriplesWithSubjectObject(subj, obj));
 }
Exemplo n.º 12
0
        public IEnumerable <ObjectVariants> GetTriplesWithSubjectPredicate(ObjectVariants subj, ObjectVariants pred)
        {
            ObjectVariants[] objects;
            var key = new KeyValuePair <int, int>(((OV_iriint)subj).code, ((OV_iriint)pred).code);

            if (spCache.TryGetValue(key, out objects))
            {
                return(objects);
            }
            objects = Graph.GetTriplesWithSubjectPredicate(subj, pred).ToArray();
            spCache.Add(key, objects);
            return(objects);
        }
Exemplo n.º 13
0
 public IEnumerable <TripleOVStruct> GetTriplesWithSubject(ObjectVariants s)
 {
     return(Graph.GetTriplesWithSubject(s));
 }
 public SparqlLiteralExpression(ObjectVariants sparqlLiteralNode)
 {
     Const = sparqlLiteralNode;
     //SetExprType(sparqlLiteralNode.Variant);
 }
Exemplo n.º 15
0
 public void Delete(ObjectVariants subject, ObjectVariants predicate, ObjectVariants obj)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public SparqlGraphGraph(ObjectVariants sparqlNode)
 {
     // TODO: Complete member initialization
     Name = sparqlNode;
 }
Exemplo n.º 17
0
 public void SetWith(ObjectVariants iri)
 {
     with = iri;
 }
Exemplo n.º 18
0
 private IEnumerable <SparqlResult> spo(ObjectVariants subjectNode, ObjectVariants predicateNode, ObjectVariants objNode, SparqlResult variablesBindings)
 {
     if (this.store.Contains(subjectNode, predicateNode, objNode))
     {
         yield return(variablesBindings);
     }
 }
Exemplo n.º 19
0
        protected virtual ObjectVariants ApplyTyped(ObjectVariants left, ObjectVariants right)
        {
            if (left.Variant == ObjectVariantEnum.Typed && right.Variant == ObjectVariantEnum.Typed)
            {
                // double dl,dr;
                int  il, ir;
                long ll, lr;
                if (int.TryParse((string)left.Content, out il) && int.TryParse((string)right.Content, out ir))
                {
                    return(new OV_typed(this.@operator(il, ir).ToString(), ((OV_typed)left).turi));
                }
                if (long.TryParse((string)left.Content, out ll) && long.TryParse((string)left.Content, out lr))
                {
                    return(new OV_typed(this.@operator(ll, lr).ToString(), ((OV_typed)left).turi));
                }
                else
                {
                    return
                        (new OV_typed(this.@operator(Convert.ToDouble(left.Content), Convert.ToDouble(right.Content)).ToString(),
                                      ((OV_typed)left).turi));
                }
            }
            else if (left.Variant == ObjectVariantEnum.Typed || right.Variant == ObjectVariantEnum.Typed)
            {
                OV_typed       t;
                ObjectVariants second;
                if ((left as OV_typed) != null)
                {
                    t      = left as OV_typed;
                    second = right;
                }
                else
                {
                    t      = right as OV_typed;
                    second = left;
                }

                // double d;
                int  i;
                long l;
                if (int.TryParse((string)t.Content, out i) && second.Content is int)
                {
                    return
                        (new OV_typed(
                             this.@operator(Convert.ToInt32(left.Content), Convert.ToInt32(right.Content)).ToString(),
                             t.turi));
                }
                if (long.TryParse((string)t.Content, out l) && second.Content is long)
                {
                    return
                        (new OV_typed(
                             this.@operator(Convert.ToInt64(left.Content), Convert.ToInt64(right.Content)).ToString(),
                             t.turi));
                }
                else
                {
                    return
                        (new OV_typed(
                             this.@operator(Convert.ToDouble(left.Content), Convert.ToDouble(right.Content)).ToString(),
                             t.turi));
                }
            }
            else
            {
                if (left is INumLiteral && right is INumLiteral)
                {
                    if (left.Variant == ObjectVariantEnum.Double || right.Variant == ObjectVariantEnum.Double)
                    {
                        return
                            (new OV_double(
                                 this.@operator(Convert.ToDouble(left.Content), Convert.ToDouble(right.Content))));
                    }
                    else if (left.Variant == ObjectVariantEnum.Decimal || right.Variant == ObjectVariantEnum.Decimal)
                    {
                        return
                            (new OV_decimal(
                                 this.@operator(Convert.ToDecimal(left.Content), Convert.ToDecimal(right.Content))));
                    }
                    else if (left.Variant == ObjectVariantEnum.Float || right.Variant == ObjectVariantEnum.Float)
                    {
                        return
                            (new OV_float(
                                 this.@operator(Convert.ToSingle(left.Content), Convert.ToSingle(right.Content))));
                    }
                    else if (left.Variant == ObjectVariantEnum.Int || right.Variant == ObjectVariantEnum.Int)
                    {
                        return(new OV_integer(this.@operator(left.Content, right.Content)));
                    }

                    // todo
                }
            }

            throw new NotImplementedException();
        }
Exemplo n.º 20
0
 public void Add(VariableNode variable, ObjectVariants value)
 {
     this.rowArray[variable.Index] = value;
 }
Exemplo n.º 21
0
 public SparqlPathManyTriple(ObjectVariants subject, SparqlPathTranslator pred, ObjectVariants @object, RdfQuery11Translator q)
 {
     this.predicatePath = pred;
     this.Subject       = subject;
     this.Object        = @object;
     this.q             = q;
     this.sVariableNode = this.Subject as VariableNode;
     this.oVariableNode = this.Object as VariableNode;
 }
 public SparqlBoolLiteralExpression(ObjectVariants sparqlLiteralNode)
 {
     this.Const = sparqlLiteralNode;
 }
Exemplo n.º 23
0
        public IEnumerable <SparqlResult> Run(IEnumerable <SparqlResult> variableBindings)
        {
            var bindings = variableBindings;

            Queue <ObjectVariants> newSubjects = new Queue <ObjectVariants>();

            ObjectVariants[] fromVariable = null;
            ObjectVariants   o            = null;
            ObjectVariants   s            = null;

            switch (NullablePairExt.Get(this.sVariableNode, this.oVariableNode))
            {
            case NP.bothNull:

                return(this.TestSOConnection(this.Subject, this.Object) ? bindings : Enumerable.Empty <SparqlResult>());

            case NP.leftNull:
                newSubjects.Enqueue(this.Subject);
                return(bindings.SelectMany(binding =>
                {
                    o = binding[this.oVariableNode];
                    if (o != null)
                    {
                        return this.TestSOConnection(this.Subject, o)
                                ? Enumerable.Repeat(binding, 1)
                                : Enumerable.Empty <SparqlResult>();
                    }
                    else
                    {
                        if (fromVariable == null)
                        {
                            fromVariable = this.GetAllSConnections(this.Subject).ToArray();
                        }
                        return fromVariable.Select(node => binding.Add(node, this.oVariableNode));
                    }
                }));

            case NP.rigthNull:
                return(bindings.SelectMany(binding =>
                {
                    s = binding[this.sVariableNode];
                    if (s != null)
                    {
                        return this.TestSOConnection(s, this.Object)
                                ? Enumerable.Repeat(binding, 1)
                                : Enumerable.Empty <SparqlResult>();
                    }
                    else
                    {
                        if (fromVariable == null)
                        {
                            fromVariable = this.GetAllOConnections(this.Object).ToArray();
                        }
                        return fromVariable.Select(node => binding.Add(node, this.sVariableNode));
                    }
                }));

            case NP.bothNotNull:


                return(bindings.SelectMany(binding =>
                {
                    s = binding[this.sVariableNode];
                    o = binding[this.oVariableNode];
                    switch (NullablePairExt.Get(s, o))
                    {
                    case NP.bothNotNull:
                        if ((this.useCache && this.TestSOConnectionFromCache(s, o)) || this.TestSOConnection(s, o))
                        {
                            return Enumerable.Repeat(binding, 1);
                        }
                        else
                        {
                            return Enumerable.Empty <SparqlResult>();
                        }

                    case NP.rigthNull:
                        return this.GetAllSConnections(s).Select(node => binding.Add(node, this.oVariableNode));

                        break;

                    case NP.leftNull:
                        return this.GetAllOConnections(o).Select(node => binding.Add(node, this.sVariableNode));

                        break;

                    case NP.bothNull:
                        this.useCache = true;
                        this.bothVariablesChache = this.predicatePath.CreateTriple(this.sVariableNode, this.oVariableNode, this.q)
                                                   .Aggregate(Enumerable.Repeat(new SparqlResult(this.q), 1),
                                                              (enumerable, triple) => triple.Run(enumerable))
                                                   .Select(
                            r =>
                            new KeyValuePair <ObjectVariants, ObjectVariants>(r[this.sVariableNode], r[this.oVariableNode]))
                                                   .ToArray();
                        return this.bothVariablesCacheBySubject.Keys.SelectMany(this.GetAllSConnections,
                                                                                (sbj, node) => binding.Add(sbj, this.sVariableNode, node, this.oVariableNode));

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public SparqlNumLiteralExpression(ObjectVariants sparqlLiteralNode)
 {
     //SetExprType(ExpressionTypeEnum.numeric);
     Const = sparqlLiteralNode;
     //TypedOperator = result => sparqlLiteralNode;
 }
Exemplo n.º 25
0
 public SparqlVariableBinding(VariableNode variable, ObjectVariants node)
 {
     // TODO: Complete member initialization
     this.Variable = variable;
     this.value    = node;
 }