private static bool CompareSolutions(SparqlResult x, SparqlResult y, Dictionary <string, string> bnodeMap)
        {
            var boundVarsX = x.Variables.Where(v => x.HasValue(v) && x.Value(v) != null);
            var boundVarsY = y.Variables.Where(v => y.HasValue(v) && y.Value(v) != null);

            if (!boundVarsX.Any() && !boundVarsY.Any())
            {
                return(true);
            }
            if (x.Variables.Count().Equals(y.Variables.Count()) &&
                x.Variables.All(xv => y.Variables.Contains(xv)))
            {
                foreach (var xv in x.Variables)
                {
                    var xb = x[xv];
                    var yb = y[xv];
                    if (!CompareNodes(xb, yb, bnodeMap))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
        public void SparqlGroupByComplex1()
        {
            String data  = @"PREFIX : <http://test/> INSERT DATA { :x :p 1 , 2 . :y :p 5 }";
            String query = @"SELECT ?s (CONCAT('$', STR(SUM(?o))) AS ?Total) WHERE { ?s ?p ?o } GROUP BY ?s";

            TripleStore store = new TripleStore();

            store.ExecuteUpdate(data);
            Assert.Equal(1, store.Graphs.Count);
            Assert.Equal(3, store.Triples.Count());

            //Aggregates may occur in project expressions and should evaluate correctly
            var results = ExecuteQuery(store, query) as SparqlResultSet;

            Assert.NotNull(results);
            Assert.True(results.All(r => r.HasBoundValue("Total")));

            SparqlResult x = results.Where(r => ((IUriNode)r["s"]).Uri.Equals(new Uri("http://test/x"))).FirstOrDefault();

            Assert.NotNull(x);
            Assert.Equal("$3", x["Total"].AsValuedNode().AsString());

            SparqlResult y = results.Where(r => ((IUriNode)r["s"]).Uri.Equals(new Uri("http://test/y"))).FirstOrDefault();

            Assert.NotNull(y);
            Assert.Equal("$5", y["Total"].AsValuedNode().AsString());
        }
示例#3
0
        /// <summary>
        /// Override of the Equals method for Results
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        /// <remarks>Used implicitly in applying Distinct and Reduced modifiers to the Result Set</remarks>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            else if (obj is SparqlResult)
            {
                SparqlResult other = (SparqlResult)obj;

                // Empty Results are only equal to Empty Results
                if (this._resultValues.Count == 0 && other._resultValues.Count == 0)
                {
                    return(true);
                }
                if (this._resultValues.Count == 0 || other._resultValues.Count == 0)
                {
                    return(false);
                }

                // For differing numbers of values we must contain all the same values for variables
                // bound in both or the variable missing from us must be bound to null in the other
                foreach (String v in other.Variables)
                {
                    if (this._resultValues.ContainsKey(v))
                    {
                        if (this._resultValues[v] == null && other[v] != null)
                        {
                            return(false);
                        }
                        else if (this._resultValues[v] == null && other[v] == null)
                        {
                            continue;
                        }
                        else if (!this._resultValues[v].Equals(other[v]))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (other.HasBoundValue(v))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private static void Test(string query, string literal)

        {
            IGraph graph = new Graph();

            graph.LoadFromString(TestData);

            IInMemoryQueryableStore store = new TripleStore();

            store.Add(graph);
            IQueryableStorage storage = new InMemoryManager(store);

            using (SparqlResultSet resultSet = (SparqlResultSet)storage.Query(query))
            {
                TestTools.ShowResults(resultSet);
                Assert.Equal(1, resultSet.Count);

                SparqlResult result = resultSet[0];
                Assert.True(result.HasBoundValue("oo"));
                Assert.Equal(graph.CreateLiteralNode(literal), result["oo"]);
            }
        }
示例#5
0
 private static bool CompareSolutions(SparqlResult x, SparqlResult y, Dictionary<string, string> bnodeMap)
 {
     var boundVarsX = x.Variables.Where(v => x.HasValue(v) && x.Value(v) != null);
     var boundVarsY = y.Variables.Where(v => y.HasValue(v) && y.Value(v) != null);
     if (!boundVarsX.Any() && !boundVarsY.Any()) return true;
     if (x.Variables.Count().Equals(y.Variables.Count()) &&
         x.Variables.All(xv => y.Variables.Contains(xv)))
     {
         foreach (var xv in x.Variables)
         {
             var xb = x[xv];
             var yb = y[xv];
             if (!CompareNodes(xb, yb, bnodeMap)) return false;
         }
         return true;
     }
     return false;
 }