Hi all

I am trying to do some query on a graph. The graph contains subjects
with x and y values (separate statements) and I want to retrieve all
subjects within a certain distance of a point. This seems to work
according to the code below. However, I cannot pass the point (x0, y0
and d0) as a parameter because it is not in the bindings of the query.
How can this be achieved all the same?

Is it prefereable to use the new bison sparql implementation instead?
How would this look then?


def in_range(binding):
    x0 = 100
    y0 = 100
    d0 = 25
    dx = binding['?x'] - x0
    dy = binding['?y'] - y0
    d = math.sqrt(dx*dx + dy*dy)
    if d <= d0:
        return True
    else:
        return False


context = ConjunctiveGraph()

 # fill graph with triples

sparqlGr = sparqlGraph.SPARQLGraph(graph=context)
select = ('?s', '?x', '?y')
where  = GraphPattern([('?s', 'x', '?x'), ('?s', 'y', '?y')])
where.addConstraint(in_range)
result = sparqlGr.query(select, where)


thanks a lot for your help
Andre
_______________________________________________
Dev mailing list
[email protected]
http://rdflib.net/mailman/listinfo/dev

Reply via email to