简体   繁体   中英

Order by in SPARQL masking results

I have a long query in Sparql and and I want to order results by numeric field "sentiment" Everything is working fine if I include the field in SELECT and GROUPBY, otherwise is crashing. But I would like to render the query without showing the field "sentiment" like in a SQL query. Is this posible in SPARQL?

The query is:

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

How I could form the query and order the results without showing the field "sentiment" itself or improve the query in general?

Thanks.

Thanks for the report. This issue of ORDER BY potentially going wrong if the variable is not projected, is a known AllegroGraph issue (bug25806) that will be fixed in the upcoming 7.0 release.

While I don't know the specifications of SPARQL enough to decide whether this ever makes sense outside of a bug workaround, you can always "mask" results by wrapping your query as a SPARQL 1.1 subquery:

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

"masking" ?var x becomes

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM