在 SPARQL 屏蔽结果中排序



我在 Sparql 中有一个很长的查询,我想按数值字段"情绪"对结果进行排序 如果我在 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))

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

谢谢。

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

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

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

"掩蔽"?varx变为

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

相关内容

  • 没有找到相关文章

最新更新