예제 #1
0
        public void ShouldReplaceVariableStartingWithUnderscore()
        {
            var sut = new SparqlParameterizedString("SELECT * WHERE { ?s a ?_o }");

            sut.SetVariable("_o", new NodeFactory().CreateLiteralNode("test"));

            Assert.Equal("SELECT * WHERE { ?s a \"test\" }", sut.ToString());
        }
예제 #2
0
        public void SetVariableShouldIgnoreVariablePrefixChar2()
        {
            var sut = new SparqlParameterizedString("SELECT * WHERE { ?s a ?o }");

            sut.SetVariable("$o", new NodeFactory().CreateLiteralNode("test"));

            Assert.Equal("SELECT * WHERE { ?s a \"test\" }", sut.ToString());
        }
예제 #3
0
        public void Core445_ParsingTest()
        {
            Random randomizer = new Random();
            SparqlParameterizedString command = new SparqlParameterizedString("SELECT * FROM <urn:with@char> FROM <urn:with?or$char> WHERE { ?subject rdfs:subClassOf ? $c . $c rdfs:label \"string literal with lang tag @inLiteralParamPattern \"@en }");

            command.SetVariable("subject", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            command.SetVariable("c", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            command.SetVariable("or", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            command.SetVariable("char", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            command.SetParameter("char", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            command.SetParameter("en", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            command.SetParameter("inLiteralParamPattern", g.CreateUriNode(UriFactory.Create("urn:some-uri")));
            String output = command.ToString();

            Assert.True(output.Contains("<urn:with@char>"), "In IRI @ characters should not start a parameter capture");
            Assert.True(output.Contains("<urn:with?or$char>"), "In IRI ? and $ characters should not start a variable capture");
            Assert.True(output.Contains("rdfs:subClassOf ? "), "Property path ? quantifier should not start a variable capture");
            Assert.True(output.Contains("@en"), "Language tags should not start a parameter capture");
            Assert.True(output.Contains("@inLiteralParamPattern"), "In string literal @ characters should not start a parameter capture");
        }
예제 #4
0
        public void SparqlParsingHandlesDollarSignInUriParameter2()
        {
            const string queryString       = @"SELECT ?p ?o WHERE { $subject ?p ?o . }";
            const string expectedCondition = @"<http://dbpedia.org/resource/$_(film)> ?p ?o";
            var          uri = new Uri("http://dbpedia.org/resource/$_(film)");

            var parametrizedQueryString = new SparqlParameterizedString(queryString);

            parametrizedQueryString.SetVariable("subject", new UriNode(null, uri));
            var sparqlQuery = new SparqlQueryParser().ParseFromString(parametrizedQueryString);

            Console.WriteLine(sparqlQuery.ToString());

            Assert.That(sparqlQuery.ToString(), Contains.Substring(expectedCondition));
        }
예제 #5
0
        public void Core445_Benchmark()
        {
            Stopwatch timer       = new Stopwatch();
            String    randomQuery = BuildRandomSizeQuery();

            // Parsing performances
            timer.Start();
            SparqlParameterizedString command = new SparqlParameterizedString(baseQuery);

            command.Append(randomQuery);
            command.Append("}");
            timer.Stop();

            Console.WriteLine("Query Size: " + command.CommandText.Length.ToString());
            Console.WriteLine("Variables: " + _variables.Count.ToString());
            Console.WriteLine("Parsing: " + timer.ElapsedMilliseconds.ToString());

            for (int i = 0; i < runs; i++)
            {
                Console.WriteLine("Run #" + i.ToString());
                timer.Reset();
                timer.Start();
                int variablesToSet = randomizer.Next(_variables.Count);
                if (variablesToSet > _variables.Count / 2)
                {
                    variablesToSet = _variables.Count;
                }
                foreach (String variable in _variables.Take(variablesToSet))
                {
                    command.SetVariable(variable, g.CreateUriNode(UriFactory.Create("urn:test#" + randomizer.Next(randomBodyIterations).ToString())));
                }
                timer.Stop();
                Console.WriteLine(variablesToSet.ToString() + " Variables set: " + timer.ElapsedMilliseconds.ToString());
                timer.Reset();
                timer.Start();
                String commandString = command.ToString();
                timer.Stop();
                Console.WriteLine("ToString: " + timer.ElapsedMilliseconds.ToString());
            }
        }
예제 #6
0
        public bool hasStatement(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, bool b, params org.openrdf.model.Resource[] rarr)
        {
            SparqlParameterizedString queryString = new SparqlParameterizedString();
            queryString.CommandText = "ASK";
            foreach (Uri u in rarr.ToContexts(this._mapping))
            {
                queryString.CommandText += "\nFROM <" + this._formatter.FormatUri(u) + ">";
            }
            queryString.CommandText += "\nWHERE { ?subject ?predicate ?object}";
            if (r != null) queryString.SetVariable("subject", SesameConverter.FromSesameResource(r, this._mapping));
            if (uri != null) queryString.SetVariable("predicate", SesameConverter.FromSesameUri(uri, this._mapping));
            if (v != null) queryString.SetVariable("object", SesameConverter.FromSesameValue(v, this._mapping));

            return this.HasTriplesInternal(queryString.ToString());
        }
예제 #7
0
        public org.openrdf.repository.RepositoryResult getStatements(org.openrdf.model.Resource r, org.openrdf.model.URI uri, org.openrdf.model.Value v, bool b, params org.openrdf.model.Resource[] rarr)
        {
            SparqlParameterizedString queryString = new SparqlParameterizedString();
            IEnumerable<Uri> contexts = rarr.ToContexts(this._mapping);
            if (contexts.Any())
            {
                queryString.CommandText = "SELECT (?s AS ?subj) (?p AS ?pred) (?o AS ?obj)\n";
                foreach (Uri u in contexts)
                {
                    queryString.CommandText += "FROM <" + this._formatter.FormatUri(u) + ">\n";
                }
                queryString.CommandText += "WHERE { ?s ?p ?o }";
            }
            else
            {
                queryString.CommandText = "SELECT (?s AS ?subj) (?p AS ?pred) (?o AS ?obj) WHERE { ?s ?p ?o }";
            }
            if (r != null) queryString.SetVariable("s", SesameConverter.FromSesameResource(r, this._mapping));
            if (uri != null) queryString.SetVariable("p", SesameConverter.FromSesameUri(uri, this._mapping));
            if (v != null) queryString.SetVariable("o", SesameConverter.FromSesameValue(v, this._mapping));

            return this.GetStatementsInternal(queryString.ToString(), this._mapping);
        }