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

How to convert RDF to pretty nested JSON using java rdf4j

Use framing import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringWriter; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFHandlerException; import org.eclipse.rdf4j.rio.RDFParser; import org.eclipse.rdf4j.rio.RDFWriter; import org.eclipse.rdf4j.rio.Rio; import org.eclipse.rdf4j.rio.helpers.StatementCollector; import org.junit.Test; import com.github.jsonldjava.core.JsonLdOptions; import com.github.jsonldjava.core.JsonLdProcessor; import com.github.jsonldjava.utils.JsonUtils; import com.google.common.base.Charsets; public class HowToConvertRdfToJson { @Test public void convertRdfToPrettyJson(){ try(InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(“book.ttl”)){ System.out.println(getPrettyJsonLdString(in,RDFFormat.TURTLE)); }catch(Exception e){ … 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

How can I express additional information (time, probability) about a relation in RDF?

There are several options to do this. I’ll illustrate some of the more popular ones. Named Graphs / Quads In RDF, named graphs are subsets of an RDF dataset that are assigned a specific identifier (the “graph name”). In most RDF databases, this is implemented by adding a fourth element to the RDF triple, turning … Read more

tech