How to construct RDF using Data Cube Vocabulary with SPARQL - sparql

I have CSV data set and I want to construct RDF using Data Cube Vocabulary.
Now I have triplifier, which constructs "regular" RDF with tarql:
PREFIX data1: <http://data1/#>
PREFIX data2: <http://data2/#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dbo: <http://dbpedia.org/ontology/#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
CONSTRUCT {
?URI a data1:Data1;
variale:name ?name;
variable:something ?something;
}
FROM <file:data2.csv>
WHERE {
BIND (URI(CONCAT('http://data1/', ?someValue)) AS ?URI)
BIND (STRLANG(?someName, "en") AS ?name)
BIND (xsd:string(?anotherValue) AS ?value)
}
OFFSET 1
I can find some explanations about how result RDF with Data Cube should look like, but I've found no examples about constructing it.
Here is the dataset I'm trying to process.

SPARQL can produce tabular data from RDF data using SELECT queries, or RDF data from RDF data using CONSTRUCT queries, but SPARQL is not suitable for converting CSV tabular data into RDF.

Related

Construct loop in SPARQL

The following SPARQL query
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix msc: <http://msc.org/resources/MSC/msc2020/>
construct {?s skos:broader msc:00-XX . }
where
{
?s a skos:Concept ; skos:notation ?notation.
filter regex (?notation, "00-\d\d")
}
searches all notations 00-01, 00-02, etc. and constructs a relation to the top level class 00-XX. However, this is only the first of 63 top level classes altogether, so I would like to "loop" over all top level classes automatically. On top, I would like to adapt this to other patterns. Is there a way to do this with SPARQL? If not, what would you recommend instead?
In the meantime we found a solution without SPARQL.
The SPARQL CONSTRUCT query was supposed to create a skos:broader relation between a skos:Concept with a notation like "00-01" (and all other concepts with 00-\d\d notation) and its proper subordinate concept, which for 00-01 is the skos:Concept with the notation 00-XX.
The data originate from a table and Open Refine is much faster in creating the skos:broader statements than using the SPARQL query proposed above and adjusting it to other notation patterns.
We use GREL's value.replace on the cells with the notations to create a new column:
value.replace(/-\d\d/, "-XX").replace(/\d\d>/, "xx>")
The two replacements give us the notation of the original notation's superordinate concept in one step. The second replace already adapts to the other patterns mentioned in the question (e.g. 00A01).
With the original notation and the value in the new column, we can easily create the skos:broader triples by concatenating text and the values from both columns. These can then be exported from OpenRefine and just be copy-pasted to our SKOS vocabulary.
Here is a SPARQL answer based on the query in the question. Using filters and regex (as suggested in the comment by Yahalnaut as a reply to UninforomedUser above) is needed. Creating a skos:broader relation based on two concept's notations requires them to hava an identical sequence of digits before the - . The comparison should only between the first part of the notations, so each 00- should match another 00-but not a 01-. As asked, the solution below only considers topConcepts of the Vocabulary as potential objects for skos:broader. The concepts should also not relate to themselves, therefore the last filter. This should then be adoptable to other patterns as well. Depending on the number of Concepts and the memory available for the query, this may last a while or even stop before finished. It eliminates lot of the effort though.
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix msc: <http://msc.org/resources/MSC/msc2020/>
construct {?s skos:broader ?y . }
where {
?s a skos:Concept ; skos:notation ?notation.
?y skos:topConceptOf msc: ; skos:notation ?not2.
bind (REPLACE (?not2 , "-XX" , "") as ?1)
bind (REPLACE (?notation , "-\d\d", "" ) as ?2 )
filter (?1 = ?2)
filter (?not2 != ?notation)
}

RDF + OWL reasoning

Let's suppose I have an RDF data about Socrates. The data is shown below
subject, predicate, object
man, being, mortal
Socrates, being, man
To check whether Socrates is mortal I have a request
SELECT *
FROM RDFData t1
JOIN RDFData t2
ON t1.subject = t2.object
Then I have a filter on "Socrates" and "mortal" and if result is not empty, then Socrates is mortal.
It works fine, but my teacher asks to add OWL information.
For example, if we have the next data
subject, predicate, object
man, being, mortal
Socrates, being, Greek
Greek, being, man
My approach does not work, because we have additional step in the chain.
I need to add an OWL static data here and implement a request for arbitrary number of steps in the chain.
What are my next steps?
If we turn your example data into actual RDF (using Turtle syntax), you'd get something like this:
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix : <http://example.org/> .
:socrates rdf:type :Greek .
:Man rdfs:subClassOf :Mortal .
:Greek rdfs:subClassOf :Man .
If you upload this data into an RDF database (such as RDF4J, Jena, GraphDB, Stardog, Blazegraph, or a host of other options), you can use the following SPARQL query:
ASK WHERE { :socrates rdf:type/rdfs:subClassOf* :Mortal }
This checks if :socrates is of a type that is either :Mortal, or a (direct or indirect) subclass of :Mortal. It returns true if Socrates is a mortal, false otherwise. You don't even need a reasoner for this, you can just use the expressivity of the query language.
If your RDF database supports basic RDFS reasoning, you can simplify your query even further:
ASK WHERE { :socrates rdf:type :Mortal }

owl:equivalentProperty relations between DBPedia and Yago

Is there any graph that contains mappings between equivalent properties in DBPedia and Yago? My application requires to "merge" triples that express the same meaning in both datasets, but I couldn't find any.
The following query returns an empty result at the Yago endpoint and only very few entries at the DBPedia endpoint.
prefix owl: <http://www.w3.org/2002/07/owl#>
select ?s ?o
where {
?s owl:equivalentProperty ?o .
}
There are some tools that automatically generated mappings between classes and properties of DBpedia and Yago. You can download some of these files here:
Yago to DBpedia linking

How to create RDF model from DBPedia data using SPARQL

I am a new one on semantic web. I would like to get all object/values for Microsoft from DBPedia using SPARQL query and save result in RDF format. I have made a query on http://dbpedia.org/sparql which works well and returns all pair/values regarding Microsoft.The code is as follows:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
select * where
{{ <http://dbpedia.org/resource/Microsoft> ?property ?value }
UNION
{?property ?value <http://dbpedia.org/resource/Microsoft>}}
What I want is to create RDF format for the results. I read tutorial on https://www.w3.org/TR/rdf-sparql-query/#construct and understood it can be done by using CONSTRUCT query. I changed SELECT to CONSTRUCT, but that did not work. If possible could you tell me what is my mistake and how can I apply CONSTRUCT to my query to get RDF model from the query please? Thanks in advance!
In order to get more clear distinction of the actual triples you retrieve, I'd suggest changing the variables in the following way:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
select * where
{{ <http://dbpedia.org/resource/Microsoft> ?property ?value }
UNION
{?subject ?property <http://dbpedia.org/resource/Microsoft>}}
And regarding the result format, just choose "Turtle" or "RDF/XML", instead of "HTML" from the results menu of the SPARQL interface.

Jena fuseki owl ontology

I installed Jena Fuseki and want to be able to get classes from my own OWL file.
The following query returns the classes from owl and rdfs but not from ont. How can I retrieve them? I eventually want to add data to TDB using parts from my own OWL ontology when querying with Fuseki. I'm using Fuseki version: 2.3.1.
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix ont: <http://wad.nistorandrei.com/ontology.owl#>
SELECT ?class ?label ?description
WHERE {
?class a owl:Class.
OPTIONAL { ?class rdfs:label ?label}
OPTIONAL { ?class rdfs:comment ?description}
}
The description of your issue makes me suspect that you did not load your ontology in Fuseki.
Declaring prefix ont: http://wad.nistorandrei.com/ontology.owl# will not allow you to query the distant ontology.owl file.
You have to create a dataset (in manage datasets -> create dataset)
and add data to it (existing dataset -> upload data or with a SPARQL UPDATE query)
Then only you can query your data.