Reputation: 93
I am working in DBPedia. i want to run some sparql. so i downloaded files from here: http://wiki.dbpedia.org/services-resources/ontology.
As you see, DBpedia seperated its triples into different files. A file for rdf:type properties and another file for others properties.
I import each file into MySQL (Persist a model); Condsider i named models "A" and "B" in order! the code is below:
for DBpedia Ontology RDF type statements
private Model AModel;
private Model BModel;
DBConnection connection = new DBConnection(DB_URL, DB_USER, DB_PASSWORD, DB_TYPE);
AModel = maker.createModel("A",true);
model.begin();
InputStream in =this.getClass().getClassLoader().getResourceAsStream("some address /instance_types_en.nt);
model.read(in,null);// Commit the database transactionmodel.commit();
------------
and again for DBpedia Ontology other A-Box properties
DBConnection connection = new DBConnection(DB_URL, DB_USER, DB_PASSWORD, DB_TYPE);
BModel = maker.createModel("B",true);
model.begin();
InputStream in =this.getClass().getClassLoader().getResourceAsStream("some address /mappingbased_properties_en.nt);
model.read(in,null);// Commit the database transactionmodel.commit();
so till here, we have two models, ones for DBpedia Ontology RDF type statements and another for DBpedia Ontology other A-Box properties.
The problen is where we have a sparql that need both inforamtion. (rdf:type properties and non rdf:type prpperties); such as:
Who was the wife of President Lincoln?
its equivalence sparql is:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?uri ?string
WHERE
{
?person rdf:type onto:President .
?person foaf:surname "Lincoln"@en .
?person onto:spouse ?uri.
OPTIONAL {?uri rdfs:label ?string .}
FILTER (lang(?string) = "en")
}
so i should run this sparql in models. but jena just let me to perform sparql in just one model:
so i have to run it like:
QueryExecution qe1 = QueryExecutionFactory.create(query, AModel));
or
QueryExecution qe1 = QueryExecutionFactory.create(query, BModel));
**
?person onto:spouse ?uri. is in AModel and ?person rdf:type onto:Presiden is in BModel!
So this query returns no record!
so what is the solution. my program generate the right sparql but i do not have the appropriate data set to return the response! Because i have different models, so i can not use Union operator here!!
Upvotes: 0
Views: 76
Reputation: 16630
There are several approaches:
If you are using a version of Jena which has DBConnection, some of these may not work as the code is so old.
Upvotes: 0