rdf - Duplicated SPARQL subquery -
in order cartesian product of results of subquery, duplicated query , bound result different variables. inner queries quite long, , same except select
line. there way simplify this?
i added simplified version of query below. i'm trying find timetable conflicts in set of events. events selected subqueries.
select ?a1 ?b1 ?a2 ?b2 { select (?a ?a1) (?b ?b1) { # long query ?a , ?b } select (?a ?a2) (?b ?b2) { # long query ?a , ?b } filter (?a1 < ?a2) }
you're doing query, , getting results (twice):
{ < x1, y1>, < x2, y2 >, < x3, y3 >, ... } { < x1, y1>, < x2, y2 >, < x3, y3 >, ... }
you want filter pairs of results first value in first set less first of second.
now number of results going increment fast, o(n^2). , don't need bother anyway. suppose (without loss of generality) order results first value, ascending. first lot of results (indicated *
) are:
{ *< x1, y1>*, < x2, y2 >, < x3, y3 >, ... } { < x1, y1>, *< x2, y2 >*, *< x3, y3 >*, ... , else ... }
the second:
{ < x1, y1>, *< x2, y2 >*, < x3, y3 >, ... } { < x1, y1>, < x2, y2 >, *< x3, y3 >*, ... , else ... }
etc etc
so you're much improve off space wise, , time wise, issuing query:
select ?a ?b { # long query ?a , ?b } order ?a # defaults ascending
putting in array or similar, , looping through fetching items results[i], results[j] > j
.
rdf sparql semantic-web
No comments:
Post a Comment