来自Jena Arq中的子选择的结合值的问题



我想运行以下简单测试查询:

PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT  ?givenName ?name_count ?temp
WHERE
  { BIND(if(( ?name_count = 2 ), "just two", "definitely not 2") AS ?temp)
    { SELECT DISTINCT  ?givenName (COUNT(?givenName) AS ?name_count)
      WHERE
        { ?y  vcard:Family  ?givenName }
      GROUP BY ?givenName
    }
  }

我正在查询的图是从教程https://jena.apache.org/tutorials/sparql_data.html:

@prefix vCard:   <http://www.w3.org/2001/vcard-rdf/3.0#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://somewhere/MattJones/>  vCard:FN   "Matt Jones" .
<http://somewhere/MattJones/>  vCard:N    _:b0 .
_:b0  vCard:Family "Jones" .
_:b0  vCard:Given  "Matthew" .

<http://somewhere/RebeccaSmith/> vCard:FN    "Becky Smith" .
<http://somewhere/RebeccaSmith/> vCard:N     _:b1 .
_:b1 vCard:Family "Smith" .
_:b1 vCard:Given  "Rebecca" .
<http://somewhere/JohnSmith/>    vCard:FN    "John Smith" .
<http://somewhere/JohnSmith/>    vCard:N     _:b2 .
_:b2 vCard:Family "Smith" .
_:b2 vCard:Given  "John"  .
<http://somewhere/SarahJones/>   vCard:FN    "Sarah Jones" .
<http://somewhere/SarahJones/>   vCard:N     _:b3 .
_:b3 vCard:Family  "Jones" .
_:b3 vCard:Given   "Sarah" .

现在问题是与jena一起运行:

Query query = QueryFactory.create(theAboveQueryAsString);
QueryExecution qexec = QueryExecutionFactory.create(query, theAboveGraphmodel);
ResultSet execSel = qexec.execSelect();
ResultSetRewindable results = ResultSetFactory.copyResults(execSel);;
ResultSetFormatter.out(System.out, results, query);

在控制台中散发此结果:

----------------------------------
| givenName | name_count | temp  |
==================================
| "Smith"   | 2          |       |
| "Jones"   | 2          |       |
----------------------------------

将温度值作为null。

另一方面
givenName  |  name_count  |  temp
------------------------------------
Jones      |       2      |  just two
Smith      |       2      |  just two

ARQ引擎中可能有一个错误,还是我缺少一些东西?预先感谢。

我正在使用jena-arq 3.12.0Java(TM(SE运行时环境(构建1.8.0_181-B13(Eclipse版本:2019-06(4.12.0(

绑定和子选择之间有一个连接。加入步骤的参数是在结合完成之前计算的。因此,评估了结合,分别评估子选择性并结合了结果。name_count在绑定分配中没有设置。如果您在子选择后移动它,则将应用于子选择的结果。

绑定在图案之前的结果中添加了一个结合。

(base <http://example/base/>
  (prefix ((rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
           (vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>))
    (project (?givenName ?name_count ?temp)
      (join
        (extend ((?temp (if (= ?name_count 2) "just two" "definitely not 2")))
          (table unit))
        (distinct
          (project (?givenName ?name_count)
           (extend ((?name_count ?.0))
             (group (?givenName) ((?.0 (count ?givenName)))
               (bgp (triple ?y vcard:Family ?givenName))))))))))

在这里,(extend...)(join...)的两个参数之一。 (table unit)是绑定之前的"无"。

如果以后放置,则代数为:

(base <http://example/base/>
  (prefix ((rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
           (vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>))
    (project (?givenName ?name_count ?temp)
      (extend ((?temp (if (= ?name_count 2) "just two" "definitely not 2")))
        (distinct
          (project (?givenName ?name_count)
            (extend ((?name_count ?.0))
              (group (?givenName) ((?.0 (count ?givenName)))
                (bgp (triple ?y vcard:Family ?givenName))))))))))

extend(来自语法绑定(在子查询的(distinct ...上工作。

相关内容

  • 没有找到相关文章

最新更新