how can a SPARQL Query on Website

ChrisD Source

I learned from rdfdotnet wiki. How can a SPARQL Query a Website? If I understand that correctly I must first to write a endpoint than the query string with SparqlParameterizedString queryString or with String. Then, I write

SparqlResultSet results = endpoint.QueryWithResultSet(queryString);

My code:

//Define a remote endpoint
        //Use the DBPedia SPARQL endpoint with the default Graph set to DBPedia
        SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://localhost:10080"));//, "http://localhost:10080");

        //Create a Parameterized String
        SparqlParameterizedString queryString = new SparqlParameterizedString();

        //Add a namespace declaration
        queryString.Namespaces.AddNamespace("lf-maint", new Uri(""));
        queryString.Namespaces.AddNamespace("foaf", new Uri(""));
        queryString.Namespaces.AddNamespace("rdfs", new Uri(""));

        //Set the SPARQL command
        //For more complex queries we can do this in multiple lines by using += on the
        //CommandText property
        //Note we can use @name style parameters here
        queryString.CommandText = "select ?l { ?s a lf-maint:Fault; lf - maint:description ?l filter(lang(?l) = \"de\") }";

        SparqlParameterizedString.ExecuteQuery Method (IRdfHandler, ISparqlResultsHandler)

        //Make a SELECT query against the Endpoint
        //Exception muss noch geschrieben werden VDS.RDF.Query.RdfQueryException
            //retun ist eine HttpWebResponce
            SparqlResultSet results = endpoint.QueryWithResultSet(queryString);     
            foreach (SparqlResult result in results)

        //Exception für VDS.RDF.Query.RdfQueryException
        catch (RdfQueryException e)
            Console.WriteLine("Error RdfQueryException: " + e);
        //Exception für den VDS.RDF.Parsing.RdfParserSelectionException
        catch(RdfParserSelectionException e)
            Console.WriteLine("Error RdfParserSelectionException: " + e);               //bekomme fehler beim Parsen

        //Make a DESCRIBE query against the Endpoint
        IGraph g = endpoint.QueryWithResultGraph("DESCRIBE ");
        foreach (Triple t in g.Triples)

my libarys:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDS.RDF.Parsing;
using VDS.RDF.Query;
using VDS.RDF;


answered 4 months ago ChrisD #1

Sorry, I expressed myself in a hurry a little bad. The point is that I can do a SPARQL query on the URI. I would like to do this via a C # program. So that I can later embed this code in another program. But I'm not quite sure how it works. What are the most important functions for this? Is my code a good start? I can not reach a query with it.

comments powered by Disqus