【发布时间】: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