Obtaining a tree efficiently

0 views
Skip to first unread message

justforthe...@gmail.com

unread,
Mar 9, 2016, 6:56:18 AM3/9/16
to Stardog
I am not too experienced, bare with me please...

I have three classes A, B and C. The ABox contains triples like:

objA does objB
objB uses objC
Then it is inferred  objA uses objC.

I need to extract this from Stardog with a Java application, to end up creating a JSON tree structure for Javascript. Actually, I need two trees:
 1. One with objA being the root, all its children objB (coming from objA does objB) in the second level, and all objC (coming from objB uses objC) in the third level.
 2. Another one with objA being the root, all its children objC (coming from the inferred objA uses objC) in the second level, and all objB (coming from objB uses objC) in the third level.

My question (perhaps basic) is how I can extract this efficiently from Stardog. I know I could do a query:
SELECT ?objB  WHERE { <objA> does ?objB }

And then do one query per each objB obtained:
SELECT ?objC  WHERE { <objB> uses ?objC }

Then do the same for tree (2), or, if Javascript performs faster, somehow create a function that swaps level 2 and 3 in the JSON.

This seems to me that it will perform badly because I need to query Stardog a lot of times ( one to get all Bs + one per each B to get all Cs). My question is: is there an alternative faster way to do this in Stardog? Sorry because I have no knowledge of Gremlin or TinkerPop3 - if they can be useful in here at all.

Thanks.

nata...@gmail.com

unread,
Mar 17, 2016, 5:32:57 AM3/17/16
to Stardog, justforthe...@gmail.com
Try
SELECT ?objB ?objC WHERE { <A> does ?objB. ?objB uses ?objC. }

and programmatically build your tree (whichever way you want).

N

justforthe...@gmail.com

unread,
Apr 18, 2016, 4:28:42 AM4/18/16
to Stardog, justforthe...@gmail.com, nata...@gmail.com
This helped. I had to do some extra things, and tune performance in other parts of the code, but as a whole I could improve performance in this terms (time in sec):


Old method loop 1:  15.350025788
Old method loop 2: 0.942766633
New method: 1.019458523

Old method loop 1:  14.678996678
Old method loop 2: 0.42890678
New method: 1.038359142

Old method loop 1: 13.612516078
Old method loop 2: 1.341648403
New method: 1.015541819

Old method loop 1:  4.822533897
Old method loop 2: 0.736539789
New method: 1.01482446

Old method loop 1:  7.604511852
Old method loop 2: 0.687368932
New method: 1.059300404

Old method loop 1:  1.124831244
Old method loop 2: 1.140141764
New method: 1.01924885

Natan Cox

unread,
Apr 18, 2016, 7:25:29 AM4/18/16
to Jeremy Iron, Stardog

Cool. Thanks for the update. Glad to hear that it helped.

Reply all
Reply to author
Forward
0 new messages