【问题标题】:Order by in SPARQL masking results在 SPARQL 屏蔽结果中排序
【发布时间】:2020-04-11 22:52:55
【问题描述】:

我在 Sparql 中有一个很长的查询,我想按数字字段“sentiment”对结果进行排序 如果我在 SELECT 和 GROUPBY 中包含该字段,一切正常,否则会崩溃。但我想呈现查询而不像在 SQL 查询中那样显示“情绪”字段。这在 SPARQL 中可行吗?

查询是:

SELECT  ?Sentiment ?Restaurant ?Name ?Address ?Score ?City ?State (SAMPLE(?photo) as ?image) SAMPLE(?Text) as ?text) (SAMPLE(?Review) as ?review) (SAMPLE(?TStyle) as ?style) (SAMPLE(?TAmbiance) as   ?ambient) (SAMPLE(?TService) as ?service)
where { ?Restaurant :hasName ?Name;
                :Dish ?Dish;
                :Score ?Score;
                :hasAddress ?Address;
                :photo ?photo;
                :HasReview ?Review;
                :Parking ?Parking;
                :CreditCard ?CreditCard;
                :Delivery ?Delivery;
                :Kids ?Kids;
                   :hasTopic ?o;
                   :Sentiment ?Sentiment.
   ?Address :hasCity ?City;
            :hasState ?State;
            :Lat ?Lat;
            :Long ?Long.
   ?Review :Text ?Text.
   BIND (exists{?Restaurant :hasTopic :style} AS ?TStyle).              
   BIND (exists{?Restaurant :hasTopic :ambiance} AS ?TAmbiance).
   BIND (exists{?Restaurant :hasTopic :service} AS ?TService).

   FILTER(contains(str(?Text), "sushi"))
   } GROUP BY ?Restaurant ?Name ?Address ?Score ?City ?State ?Sentiment
   ORDER BY DESC((?Sentiment))

如何在不显示“情绪”字段本身的情况下形成查询并对结果进行排序,或者总体上改进查询?

谢谢。

【问题讨论】:

  • 那你为什么不能从SELECT 部分中删除?Sentiment?
  • 那么查询没有正确排序结果。
  • 你的 SPARQL 引擎是什么?这听起来像一个错误。可能该错误是由ORDER BY DESC((?Sentiment)) 中的双括号触发的——所以我尝试将其更改为ORDER BY DESC(?Sentiment)(并从SELECT 中删除?Sentiment)。
  • 我正在使用 Allegrograph。是的,我已经尝试退出括号并选择,并且顺序不正确。
  • 在添加 SAMPLE(?Text) 作为 ?text) 之前工作正常。添加 GROUPBY 时出现问题。

标签: performance sparql rdf allegrograph knowledge-graph


【解决方案1】:

感谢您的报告。如果变量没有被投影,这个 ORDER BY 问题可能会出错,这是一个已知的 AllegroGraph 问题 (bug25806),将在即将发布的 7.0 版本中修复。

【讨论】:

    【解决方案2】:

    虽然我对 SPARQL 的规范了解得不够多,无法确定这在解决错误时是否有意义,但您始终可以通过将查询包装为 SPARQL 1.1 子查询来“屏蔽”结果:

    SELECT ?var1 ?var2 ... ?varn
    {
     ...
    }
    

    “屏蔽” ?varx 变为

    SELECT ?var1 ?var2 ... ?var(x-1) ?var(x+1) ... ?varn
    {
     SELECT ?var1 ?var2 ... ... ?varn
     {
      ...
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多