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.
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
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.
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
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.
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-
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.