我正在学习sparql并且我正在处理一个select查询,我想将ASK查询的结果绑定到对象变量.
ASK查询正在处理它自己,但我在另一个查询中使用查询时遇到问题.
这是ASK查询:
PREFIX schema: <http://domain.com/app/schema/>
ASK { GRAPH <http://domain.com/app/data/something> {
?s schema:code "ANS"^^<http://www.w3.org/2001/XMLSchema#string> ;
schema:someid "12345678"^^<http://www.w3.org/2001/XMLSchema#string> ;
schema:startdate ?startdate .
OPTIONAL { ?s schema:enddate ?enddate }
BIND(IF(BOUND(?enddate), ?enddate, now()) AS ?resultdate)
FILTER(?resultdate >= now() && ?startdate < now())
}
}
Run Code Online (Sandbox Code Playgroud)
这将返回true或false,具体取决于id.
我现在想要的是一个返回两列的查询:
+----------+--------+
| ID | STATUS |
+----------+--------+
| 12345678 | true |
| 87654321 | false |
+----------+--------+
Run Code Online (Sandbox Code Playgroud)
我做了一些尝试,但我无法生成具有有效语法的查询:
PREFIX schema2: <http://domain.com/app2/schema/>
PREFIX schema: <http://domain.com/app/schema/>
select ?s ?p ?o
where
{ GRAPH <http://http://domain.com/app2/data/something>
{?s ?p ?o } .
BIND() {
ASK { GRAPH <http://domain.com/app/data/something> {
?s schema:code "ANS"^^<http://www.w3.org/2001/XMLSchema#string> ;
schema:someid "12345678"^^<http://www.w3.org/2001/XMLSchema#string> ;
schema:startdate ?startdate .
OPTIONAL { ?s schema:enddate ?enddate }
BIND(IF(BOUND(?enddate), ?enddate, now()) AS ?resultdate)
FILTER(?resultdate >= now() && ?startdate < now())
}
}
}
FILTER(?s = <http://domain.com/app2/data/something/100024>)
}
Run Code Online (Sandbox Code Playgroud)
有关如何实现这一目标的任何建议/示例?
你可以用BIND与表达,但不与查询表(SELECT,ASK,等).
你可以做的是替换ASK一个exists模式.像这样的东西
PREFIX schema2: <http://domain.com/app2/schema/>
PREFIX schema: <http://domain.com/app/schema/>
select ?id ?status
where
{
GRAPH <http://http://domain.com/app2/data/something>
{
?s schema:someid ?id ;
}
BIND( exists
{
GRAPH <http://domain.com/app/data/something>
{
?s schema:code "ANS"^^<http://www.w3.org/2001/XMLSchema#string> ;
schema:startdate ?startdate .
OPTIONAL { ?s schema:enddate ?enddate }
BIND(IF(BOUND(?enddate), ?enddate, now()) AS ?resultdate)
FILTER(?resultdate >= now() && ?startdate < now())
}
} as ?status)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
716 次 |
| 最近记录: |