gpt4 book ai didi

sparql - SPARQL 中的 IF 语句

转载 作者:行者123 更新时间:2023-12-02 01:17:23 24 4
gpt4 key购买 nike

我有以下 SPARQL 查询:

PREFIX yago: <http://dbpedia.org/class/yago/>
SELECT distinct count (?Montreal) as ?Montreal count(?Toronto) as ?Toronto
WHERE
{
{?Montreal rdf:type yago:HospitalsInMontreal} UNION {?Toronto rdf:type yago:HospitalsInToronto}.
}

此查询结果:

蒙特利尔 = 20多伦多= 28

我想要的是:我想编辑查询而不是给出 20 和 28,我想比较结果如果蒙特利尔的医院数量大于多伦多的医院数量,那么:

蒙特利尔 = 1多伦多= 2

如果多伦多的医院数量大于蒙特利尔的医院数量,那么:

蒙特利尔 = 2
多伦多= 1

我试过这个查询,但没有成功:

PREFIX yago: <http://dbpedia.org/class/yago/>
SELECT distinct count (?Montreal) as ?Montreal count(?Toronto) as ?Toronto
WHERE
{
{?Montreal rdf:type yago:HospitalsInMontreal} UNION {?Toronto rdf:type yago:HospitalsInToronto}.
LET( ?Montreal := IF( ?Montreal > ?Toronto, -1, 1 ).
}

谢谢

最佳答案

SPARQL 中没有 LET 表达式,但上面的查询不需要:

PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT distinct if(count(?MontrealC)>count(?TorontoC),1,2) as ?Montreal if(count(?TorontoC)>count(?MontrealC),1,2) as ?Toronto
WHERE
{
{?MontrealC rdf:type yago:HospitalsInMontreal} UNION {?TorontoC rdf:type yago:HospitalsInToronto}.
}

关于sparql - SPARQL 中的 IF 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9560192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com