public override IEnumerable <ISparqlGraphPattern> CreateTriple(ObjectVariants subject, ObjectVariants @object, RdfQuery11Translator q)
        {
            var subjectNode = IsInverse ? @object : subject;
            var objectNode  = IsInverse ? subject : @object;

            //if (subjectNode is ObjectVariants && objectNode is ObjectVariants)

            yield return
                (new SparqlMayBeOneTriple(path.CreateTriple((ObjectVariants)subjectNode, objectNode, q),
                                          (ObjectVariants)subjectNode, (ObjectVariants)objectNode, q));
            //else
            //foreach (var t in path.CreateTriple((ObjectVariants) subjectNode, objectNode, q))
            //    yield return t;
        }
Beispiel #2
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(sVariableNode, oVariableNode))
            {
            case NP.bothNull:

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

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

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

            case NP.bothNotNull:


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

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

                        break;

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

                        break;

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }