From: Rob V. <rv...@do...> - 2012-11-16 23:47:28
|
Hi Jostinah If you are having trouble getting started with SPARQL I would recommend the excellent SPARQL by Example Tutorial (http://www.cambridgesemantics.com/semantic-university/sparql-by-example) or Bob DuCharme's Learning SPARQL book (http://www.learningsparql.com) OWL can be stored as RDF/XML and many tools like Protégé either default to this or support it. dotNetRDF can read any RDF/XML so you can read your ontology file with it provided you've saved it as RDF/XML, the LoadFromFile() call you show will assume RDF/XML if given a .owl extension Yes you can query OWL with SPARQL, you are querying the RDF representation of the OWL rather than the axioms, see http://answers.semanticweb.com/questions/3172/is-it-possible-to-write-a-spar ql-query-or-use-some-api-to-retrieve-the-concept-definitions-from-any-ontolo gy/3189 for some simple examples Hope this helps, Rob Ps. For future reference please subscribe to the mailing list (dot...@li...) rather than emailing me directly, thanks! From: Jostinah Lam <89...@gm...> Date: Friday, November 16, 2012 3:50 AM To: Rob Vesse <rv...@do...> Subject: SPARQL > Hello rob, > I'm jostinah, a student who is currently doing a project.I have some questions > regarding dotnetrdf to ask.I have no basic at all in computer science,i hope > you can help me. > Here's a brief introduction of what the project is about. i have to create a > software that is able to produce the name of the disease and its management > when the user keys in the input.This project is focusing pregnancy induced > hypertension. > > For example: > input : Diastolic value =90 > output: Hypertension > > I created the ontology using protege.Right now i had integrate the owl file > into C#, but i have a problem on how to query the owl file. > The code is as below: > > private void SPARQLquery() > { > > //Define your Graph here - it may be better to use a > QueryableGraph if you plan > //on making lots of Queries against this Graph as that is > marginally more performant > IGraph g = new Graph(); > > //Load some data into your Graph using the LoadFromFile() > extension method > g.LoadFromFile("exData\\PregnancyInducedHypertension.owl"); > > //Use the extension method ExecuteQuery() to make the query > against the Graph > try > { > Object results = g.ExecuteQuery("SELECT ?x WHERE { > ?NamedDisease a ?x }"); > if (results is SparqlResultSet) > { > //SELECT/ASK queries give a SparqlResultSet > SparqlResultSet rset = (SparqlResultSet)results; > foreach (SparqlResult r in rset) > { > //Console.WriteLine(r.ToString()); > textBox1.Text += r.ToString() + "\r\n"; > } > } > else if (results is IGraph) > { > //CONSTRUCT/DESCRIBE queries give a IGraph > IGraph resGraph = (IGraph)results; > foreach (Triple t in resGraph.Triples) > { > //Console.WriteLine(t.ToString()); > textBox1.Text += t.ToString() + "\r\n"; > } > } > else > { > //If you don't get a SparqlResutlSet or IGraph something > went wrong > //but didn't throw an exception so you should handle it > here > Console.WriteLine("ERROR"); > } > } > catch (RdfQueryException queryEx) > { > //There was an error executing the query so handle it here > Console.WriteLine(queryEx.Message); > } > } > > The red words is where the query should be. i know the query should be > something like this " rdf:about,owl: class" but i have no clue at all. i > studied SPARQL how to query. SPARQL is suppose to query rdf but not owl but > since owl is made of rdf,so i think there must be a way to query owl.I copy > the code from one of the example that you gave to others. > > My questions are: > 1) Can i integrate the owl file into C# and not using remoteendpoint?Because > sparql remoteendpoint normally produce result in set,i only want to produce > one result > 2)is it possible to query owl using sparql in my case since i need to produce > one distinct result only?I understand the query for owl will be very long. > > > Thank you so much for your time.I really hope you can help me.I will try my > best to explain if there's any part that you dont understand.Thank you. > |