terseason
terseason

Reputation: 80

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.

Upvotes: 0

Views: 367

Answers (2)

Willem Broekema
Willem Broekema

Reputation: 15

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.

Upvotes: 1

Konrad Höffner
Konrad Höffner

Reputation: 12217

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" ?varx becomes

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

Upvotes: 0

Related Questions