Hi,

I have created an Ontology (OWL/RDF File Project) using Protege 3.4.8 and have executed some SPARQL queries using the inbuilt SPARQL engine.

I would like to now create a front end for the Ontology using dotNet. For the same I downloaded dotNetRDF and have gone through the User Guide and also tried out successfully some of the basic examples given.

However, there is no content available for Protege and dotNetRDF connectivity. How exactly can I read the RDF or OWL File from Protege and execute some SPARQL queries on them?

asked 08 Jan '13, 03:22

George%20Abraham's gravatar image

George Abraham
24918
accept rate: 16%

edited 08 Jan '13, 03:23


There is no direct connectivity between Protege and dotNetRDF, however if you have your ontology from Protege saved on disk in a format dotNetRDF can read (RDF/XML, Turtle, NTriples, N3 or RDF/JSON) then you can load it in and query it.

Adapting the example from the Querying with SPARQL page slightly:

TripleStore store = new TripleStore();

//Load in our ontology we created in protege
store.LoadFromFile("my-ontology.rdf");

//Execute a raw SPARQL Query
//Should get a SparqlResultSet back from a SELECT query
Object results = store.ExecuteQuery("SELECT * WHERE { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }");
if (results is SparqlResultSet)
{
  //Print out the Results
  SparqlResultSet rset = (SparqlResultSet)results;
  foreach (SparqlResult result in rset)
  {
    Console.WriteLine(result.ToString());
  }
}
link

answered 08 Jan '13, 05:59

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.5k715
accept rate: 29%

@Rob Vesse Thanks a lot for the help. So I just need to save the Protege Project as a RDF/XML or export it to NTriple, N3 or Turtle format and then continue with the same...right?

(08 Jan '13, 09:18) George Abraham George%20Abraham's gravatar image
1

@George Abraham Yes that's all there is to it

(08 Jan '13, 09:19) Rob Vesse ♦ Rob%20Vesse's gravatar image

@Rob Vesse: Thank You!

(08 Jan '13, 09:36) George Abraham George%20Abraham's gravatar image

@Rob Vesse: How do you execute this query using store.ExecuteQuery?? [I am just a novice, so please excuse me for any silly blunders]

SELECT ?name ?Characteristics ?Behaviour WHERE { ?Person :hasCharacteristics ?Characteristics. ?Person :name ?name. ?Characteristics :showsBehaviour ?Behaviour } ORDER BY ?name

(09 Jan '13, 02:36) George Abraham George%20Abraham's gravatar image

@Rob Vesse:

I tried the following:

store.ExecuteQuery("SELECT ?name ?Characteristics ?Behaviour WHERE { { ?Person :hasCharacteristics ?Characteristics } UNION { ?Person :name ?name } UNION { ?Characteristics :showsBehaviour ?Behaviour } } ORDER BY ?name");

But it is giving this error:

Unhandled Exception: VDS.RDF.Parsing.RdfParseException: Cannot resolve a QName in the Default Namespace when there is no in-scope Base URI and no Default Namespace defined

(09 Jan '13, 02:36) George Abraham George%20Abraham's gravatar image
1

@George Abraham If you use prefixed names (aka QNames) such as :hasCharacteristics then you must add a prefix definition otherwise your query is invalid. Try adding PREFIX : <http://your/namespace> to your query substituting <http://your/namespace> for your actual namespace URI

(09 Jan '13, 05:01) Rob Vesse ♦ Rob%20Vesse's gravatar image

@Rob Vesse: I seem to have got it working with this query:

store.ExecuteQuery( "PREFIX pre: http://www.owl-ontologies.com/LRBrain_Simple.owl#" + "SELECT ?name ?Characteristics ?Behaviour " + "WHERE { ?Person pre:hasCharacteristics ?Characteristics. ?Person pre:name ?name. ?Characteristics pre:showsBehaviour ?Behaviour} " + "ORDER BY ?name");

But the answer that I am getting is in a cluttered format. I hope that my query is correct?

(09 Jan '13, 09:23) George Abraham George%20Abraham's gravatar image

@George Abraham What do you mean by a cluttered format?

(09 Jan '13, 09:26) Rob Vesse ♦ Rob%20Vesse's gravatar image

@Rob Vesse: The answers are coming in this format:

?Characteristics = http://www.owl-ontologies.com/LRBrain_Simple.owl#Intutive , ?Behaviour = http://www.owl-ontologies.com/LRBrain_Simple.owl#RightBrained , ?name = A^^http://www.w3.org/2001/XMLSchema#string ?Characteristics = http://www.owl-ontologies.com/LRBrain_Simple.owl#Linear , ?Behaviour = http://www.owl-ontologies.com/LRBrain_Simple.owl#LeftBrained , ?name = A^^http://www.w3.org/2001/XMLSchema#string

How can I display it in a more readable format like only the values without the namespaces?

(09 Jan '13, 09:35) George Abraham George%20Abraham's gravatar image
1

@George Abraham That's the ToString() of the SparqlResult right? See the related question http://answers.semanticweb.com/questions/14886/how-can-you-format-sparql-query-results-in-dotnetrdf which covers exactly this question

(09 Jan '13, 09:51) Rob Vesse ♦ Rob%20Vesse's gravatar image

@Rob Vesse: Thanks a lot for the help.

(09 Jan '13, 10:23) George Abraham George%20Abraham's gravatar image
showing 5 of 11 show 6 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1,162
×77

Asked: 08 Jan '13, 03:22

Seen: 1,285 times

Last updated: 09 Jan '13, 10:23