2016-06-07 11 views
0

Ich schreibe folgende SPARQL-Abfrage.FILTER mit MIN in SPARQL

select ?o1, ?o2, ?e from <http://ndssl.bi.vt.edu/chicago/> 
where{ 
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infector_pid> ?o1. 
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infectee_pid> ?o2. 
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_iteration> '0'^^xsd:decimal. 
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_exposureday> ?e. 
?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_pid1> ?o1. 
?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_pid2> ?o2. 
?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_acttype1> '5'^^xsd:decimal. 
?s1 <http://ndssl.bi.vt.edu/chicago/vocab/contactnetwork_acttype1> '5'^^xsd:decimal 
} 

Abfrage gibt das Ergebnis wie folgt zurück.

<http://ndssl.bi.vt.edu/chicago/person/pid#449563560> <http://ndssl.bi.vt.edu/chicago/person/pid#446718746> 32 
<http://ndssl.bi.vt.edu/chicago/person/pid#449563560> <http://ndssl.bi.vt.edu/chicago/person/pid#446734805> 5 
<http://ndssl.bi.vt.edu/chicago/person/pid#450309500> <http://ndssl.bi.vt.edu/chicago/person/pid#450261482> 30 

Ich möchte nur das Triple, wo "? E" ist minimal. Das bedeutet Folgendes:

<http://ndssl.bi.vt.edu/chicago/person/pid#449563560> <http://ndssl.bi.vt.edu/chicago/person/pid#446734805> 5 

Wie kann ich es tun? Ich habe versucht zu folgen, aber es funktioniert nicht.

............. 
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_exposureday> ?e.FILTER (MIN (?e)) 
............. 

Ich brauche den minimalen Wert des Objekts „? E“ in „WHERE“ -Klausel, weil einige andere Teil der Abfrage hängt von ihm zu finden.

+3

'ORDER BY ASC (? E) LIMIT 1' – AKSW

+0

Warum ist dies markiert jena? – AndyS

Antwort

1

Wenn Sie Ergebnisse mit einem minimalen Wert erhalten möchten, ist es am einfachsten, nach diesem Wert zu sortieren und die Anzahl der Lösungen auf eins zu beschränken. Zum Beispiel (sollten Sie in der Lage sein, diese Technik auf Ihre Anfrage anzuwenden):

select ?x { 
    values ?x { 8 2 0 2 -3 1 5 } 
} 
order by ?x 
limit 1 

Dies wird produzieren -3 als einziges Ergebnis, weil es zuerst war, nachdem die Ergebnisse bestellt wurden, und nur das erste Ergebnis wurde zugelassen durch das Limit.