1

I am in the process of writing a SPARQL to get results for restrictions written for an equivalent class. The restrictions are a multi level- meaning the final Union/Intersection requires the inner Union and Intersections to be solved first.

Restrictions and Their hierarchy

A,B,C,D....G are all restrictions and are connected by unions,intersection or negation operators. So, all restrictions at level 3(D,E and F,G) have to evaluated to proceed to level 2 restrictions.

I am using a distance between nodes(here, it is a union/intersection/negation block) SPARQL to get the level of the restrictions.

I am stuck at the point where I have the correct results at level 3 but need to store these results(or reuse them some way) to evaluate results for level 2 and so on till I reach the topmost level of the restrictions. I am a little stuck because we cannot use traditional Loops in SPARQl(I could just take the maximum distance of the nodes and rerun the code for each distance in other languages)

Does anyone know an effective way of using data structures or named graphs for this case?

Any input is appreciated !! :)

Update

Example class structure- Example

I am adding an example for more clarity. I have a class Address with few instances, each of these instances has properties for address description(Street,City, State etc.). Please refer to the snapshot above.

I have the following restrictions applied on the equivalent class. equivalent class description

This breaks down to [(D Union E) Intersection (F Intersection G)]

Coming to SPARQL queries - I planned to arrive at the final result in two steps

  1. Calculate distance between two nodes in my restriction. i.e., distance between A-B is 1, B-E is 1 and A-F is 2 and so on. I used the logic mentioned in Calculate length of path between nodes? to do so.

  2. Get results for each condition at a particular level and use this result to get results for upper levels. Eg. First get result for addresses in NJ state and US country (F Intersection G). Similarly get addresses in IL state or 07080 Zip (D Union E). Store these Level 3 results to calculate Level 2 (B,C). This process goes on until we arrive at Level 1 Node. There is no restriction on the number of levels.

The query I currently have gives me the following results- Query Result

The snapshot above contains the instances which satisfy each condition in last level (Ln - Here D,E;F,G) and presents the results at Ln-1 (Level 2 here). Somehow, I need to automate this recursive process - store Ln-1 to calculate Ln-2 and so on and so forth until I reach Level 1. I cannot post the query directly here, but please let me know if you want to know any specifics in query - I'll try to answer it in the generic way.

Community
  • 1
  • 1
  • Can you please give an example of the restrictions? – UninformedUser Nov 15 '16 at 13:26
  • @AKSW A restriction is an condition imposed on either a datatype or object property in my case. In this case if I talk about level 3, just imagine B = D **Union** E and C = F **Intersection** G – Shruti Chandrika Nov 15 '16 at 16:13
  • @AKSW Again some sample values would be ,D = test:hasCity only "New York" E = test:hasCity only "Seattle" , F = test:hasStreet only :XYZ G = test:hasStreet only :PQR – Shruti Chandrika Nov 15 '16 at 16:24
  • @AKSW please, add sample values, examples and whatever queries you've tried to write so far to the question. I recommend you to check http://stackoverflow.com/help/mcve. – laughedelic Nov 15 '16 at 18:44
  • @laughedelic - Your comment should have been addressed to the original poster... – TallTed Nov 15 '16 at 20:13
  • @ShrutiChandrika - Please see , and edit your sample values, trial queries, etc., directly into your question. – TallTed Nov 15 '16 at 20:14
  • @TallTed right, I mixed up. I think the OP will be notified anyway. – laughedelic Nov 15 '16 at 20:15
  • @laughedelic Please see the update :) – Shruti Chandrika Nov 15 '16 at 20:42
  • @TallTed Yeah I got notified, I have updated the question – Shruti Chandrika Nov 15 '16 at 20:43
  • I'm not sure how efficient it is to query those OWL class expressions with SPARQL. You would need to use the Turtle representation of it, which is obviously verbose: `_:x rdf:type owl:Restriction . _:x owl:onProperty y . _:x owl:someValuesFrom z .` – UninformedUser Nov 16 '16 at 10:45
  • It can be used in similar way in SPARQL too... **?class (owl:intersectionOf|owl:unionOf)/rdf:rest*/rdf:first ?i . OPTIONAL{?i owl:allValuesFrom ?val; owl:onProperty ?prop.}** – Shruti Chandrika Nov 16 '16 at 16:37

0 Answers0