First of all, I created my own, sample ontology using Protege 4. My actual goal is developing a semantic web application that benefits from object properties to offer something to users. After I created my ontology, I'll add dynamic data, so I need to use Jena API . For the sake of demonstration I created sample instances. But when I try to retrieve results, I got nothing.
Maybe I'm missing something in my SPARQL query.
Here's what I've tried so far:
private static final String baseUri = "http://www.semanticweb.org/ontologies/alisveris.owl#";
private static void modelReadFile(String filename, Model model) {
try {
File f = new File(filename);
FileReader fr = new FileReader(f);
model.read(fr, baseUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static void printModel(Model model) {
String queryString =
"PREFIX lib: <http://www.semanticweb.com/ontologies/alisveris.owl>" +
"SELECT ?name ?surname " +
"FROM <http://www.semanticweb.com/ontologies/alisveris.owl>" +
"WHERE {" +
"?name lib:take \"JavaProgramming\" " +
"}";
System.out.println(queryString);
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
qe.close();
}
public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
modelReadFile("/home/talha/ontologies/alisveris.owl", model);
// Create properties for the different types of relationship to represent
Property take = model.createProperty(baseUri, "take");
Property isTakenBy = model.createProperty(baseUri, "isTakenBy");
Property published = model.createProperty(baseUri, "published");
Property publishedBy = model.createProperty(baseUri, "publishedBy");
// User data properties
Property userId = model.createProperty(baseUri, "userId");
Property name = model.createProperty(baseUri, "name");
Property surname = model.createProperty(baseUri, "surname");
Property username = model.createProperty(baseUri, "username");
Property password = model.createProperty(baseUri, "password");
Property gender = model.createProperty(baseUri, "gender");
Property age = model.createProperty(baseUri, "age");
// Publisher data properties
Property publisherId = model.createProperty(baseUri, "publisherId");
Property publisherName = model.createProperty(baseUri, "publisherName");
// Book data properties
Property bookId = model.createProperty(baseUri, "bookId");
Property bookName = model.createProperty(baseUri, "bookName");
Property bookGenre = model.createProperty(baseUri, "bookGenre");
Property pageCount = model.createProperty(baseUri, "pageCount");
Property isbn = model.createProperty(baseUri, "isbn");
Property bookRating = model.createProperty(baseUri, "bookRating");
Resource talha = model.createResource(baseUri + "Talha");
Resource javaProgramming = model.createResource(baseUri + "JavaProgramming");
// and so on for other family members
talha.addProperty(userId, "1");
talha.addProperty(name, "Talha");
talha.addProperty(surname, "Kabakuş");
talha.addProperty(username, "talhak");
talha.addProperty(password, "00");
talha.addProperty(gender, "1");
talha.addProperty(age, "23");
javaProgramming.addProperty(bookId, "1");
javaProgramming.addProperty(publisherId, "1");
javaProgramming.addProperty(bookName, "Java Programming");
javaProgramming.addProperty(bookGenre, "1");
javaProgramming.addProperty(pageCount, "200");
javaProgramming.addProperty(isbn, "121321312");
javaProgramming.addProperty(bookRating, "3");
// Add properties to adam describing relationships to other family members
talha.addProperty(take, javaProgramming);
Statement s = ResourceFactory.createStatement(talha, take, javaProgramming);
model.add(s); // add the statement (triple) to the model
printModel(model);
}
Here's the results I got:
------------------
| name | surname |
==================
------------------
Finally here's my ontology file which is generated by Protege (.owl)
alisveris.owl
asked
06 Jan, 13:59
talha06
23●5
accept rate:
0%
Same as http://stackoverflow.com/questions/14181617/unable-to-retrieve-results-from-owl-using-jena