SPARQL: is there any path between two nodes?

While you can’t use variables in property paths, you can use a wildcard by taking advantage of the fact that for any URI, every property either is that property or isn’t. E.g., (<>|!<>) matches any property, since every property either is <> or isn’t. You can make a wildcard that goes in either direction by … Read more

Exploratory SPARQL queries?

Well, the obvious first start is to look at the classes and properties present in the data. Here is how to see what classes are being used: SELECT DISTINCT ?class WHERE { ?s a ?class . } LIMIT 25 OFFSET 0 (LIMIT and OFFSET are there for paging. It is worth getting used to these … Read more

DBpedia Jena Query returning null

that is so embarassing, there is space problem in the query: String service = “http://dbpedia.org/sparql”; String queryString = “”; queryString = “PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?label ” + “WHERE {” + “<http://dbpedia.org/resource/Quatre_Bornes> <http://dbpedia.org/ontology/country> ?y .”+ “?y rdfs:label ?label .”+ “FILTER (LANG(?label) = ‘en’)”+ “}”;

Finding all steps in property path

While there are some limitations in what property paths can do, depending on your exact requirements, you may be able to get what you need here. Consider this data: @prefix : <urn:ex:>. :a :relatedTo :b . :b :relatedTo :c . :c :relatedTo :d . :a :relatedTo :e . :e :relatedTo :f . :f :relatedTo :g … Read more

Calculate length of path between nodes?

This is based on the same technique used to compute the position of an element in an RDF list using SPARQL that is described in: Is it possible to get the position of an element in an RDF Collection in SPARQL? If you have data like this: @prefix : <http://example.org> . :orgA :hasSuborganization :orgB, :orgC, … Read more

Aggregating results from SPARQL query

You can GROUP BY by the variables that identify the tweet and then use GROUP_CONCAT to concatenate the hashtags into something like an array, but it will still be a string that you’ll need to parse afterward. For instance, given data like @prefix smo: <http://example.org/> . @prefix : <http://example.org/> . :tweet1 smo:tweeted_at “1” ; smo:has_hashtag … Read more