lamalama69
lamalama69

Reputation: 29

Getting instance - SPARQL query in Protege

I have an ontology in Protege and want to write some SPARQL queries.

The ontology is set up like this:

Thing > Beverages > Wine > Red_wine

Then I have added different red wines as instances. They also have some object properties like fromCountry, goesWellWith and priceRange

How do I create a SPARQL query for returning for example a red wine from France, that goes well with pork, and priceRange 100-199?

Upvotes: 0

Views: 745

Answers (1)

Konrad Höffner
Konrad Höffner

Reputation: 12217

If you want to return certain resources in your knowledge base you need a SELECT query.

As the commenters have stated, it is not possible to answer your question exactly as you didn't provide enough information on how your data is modelled and you are expected to show your own efforts and where they failed.

You can find an detailed overview of SPARQL 1.1 at https://www.w3.org/TR/2013/REC-sparql11-overview-20130321/ or a more approachable tutorial at https://www.w3.org/2009/Talks/0615-qbe/.

As far as I can guess from your question, your query should look similar to this:

SELECT ?wine WHERE
{
 ?wine a :RedWine;
       :goesWellWith :Pork;
       :priceRange :PriceRange100To199.
}

Please adapt this query to your exact model and show us your results.

If you mean "just one result" with "a red wine", you can add "LIMIT 1".

You could also model the price range differently, for example by having a minPrice and maxPrice, as this would enable more precise queries using filters.

P.S.: I changed your :Red_wine to :RedWine as camel case is usually used for class URIs.

Upvotes: 1

Related Questions