0

我在 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))

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

谢谢。

4

2 回答 2

1

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

于 2019-12-31T14:00:14.637 回答
0

虽然我不知道 SPARQL 的规范足以决定这在错误解决方法之外是否有意义,但您始终可以通过将查询包装为 SPARQL 1.1 子查询来“屏蔽”结果:

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

“掩蔽” ?var x变为

SELECT ?var1 ?var2 ... ?var(x-1) ?var(x+1) ... ?varn
{
 SELECT ?var1 ?var2 ... ... ?varn
 {
  ...
 }
}
于 2019-12-27T13:33:43.100 回答