我有几个SPARQL查询需要获取一个或多个URI或文本值的用户参数。 SPARQL查询采用Virtuoso重写规则。为了说明这一点,我将使用DBpedia的查询,询问今天和接下来7天出生的哲学家。
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
#all philosophers born today and in the next 7 days with influences
SELECT DISTINCT ?name ?wikipedia_page ?born (Group_Concat(DISTINCT ?influencerSTR; separator = "\n") as ?influenced_by) (Group_Concat(DISTINCT ?_influencedSTR; separator = '\n') as ?influenced) ?full_description_in_dbpedia #?influenced ?ideas ?indegree ?person
WHERE {
{?person rdf:type o:Philosopher ;
rdfs:label ?label;
^foaf:primaryTopic ?wikipedia_page ;
o:birthDate ?born ;
o:influencedBy|^o:influenced ?influencer.}
values ?d {0 1 2 3 4 5 6 7}
BIND ((SUBSTR(STR(?born),6) as ?bornSTR))
BIND ((SUBSTR(STR(bif:dateadd("day", ?d, now())),6,5)) as ?day)
FILTER (STRLEN(STR(?born)) > 6 && STR(?bornSTR) = STR(?day))
FILTER (lang(?label) = "en") .
OPTIONAL {?person o:influenced|^o:influencedBy ?_influenced.}
OPTIONAL {?person o:abstract ?abstract . FILTER (lang(?abstract) = "en") .}
BIND (str(?label) AS ?name)
BIND (str(?abstract) AS ?description)
BIND (STRAFTER((STR(?influencer)), "resource/") as ?influencerSTR ).
BIND (STRAFTER((STR(?_influenced)), "resource/") as ?_influencedSTR ).
BIND (?person AS ?full_description_in_dbpedia)
}
GROUP BY ?name ?wikipedia_page ?born ?day ?full_description_in_dbpedia
ORDER BY ?day
因此,忽略此特定示例查询是否为最佳,如何更改查询以便它可以接受各种参数,例如{1 4}
或{0 5 6 7}
。
我并不是说“应该使用价值”。这是我想到的第一件事。任何其他建议都非常受欢迎。
请注意,如果我放
values (?d) {("0") ("1") }
查询不起作用。
答案 0 :(得分:0)
解决方案似乎是使用这些形式之一(对于示例中的整数值) -
fit <- fitted(km)
factor(fit, labels = 1:nlevels(factor(fit)))
rank(km$centers)[km$cluster])
match(fitted(km), sort(km$centers))
values (?d) {(0) (1)}