basilapi / basil

Building Apis SImpLy from sparql endpoints
http://basil.kmi.open.ac.uk
24 stars 5 forks source link

is group by allowed by basil? #48

Closed richhl closed 8 years ago

richhl commented 8 years ago

i've got an error when adding a query at http://basil.kmi.open.ac.uk/ap attached query and screenshot. screenshot group by error

Line 54 is

      SELECT DISTINCT ?contrato count(?tender) AS ?numLicitadores 
PREFIX pproc: <http://contsem.unizar.es/def/sector-publico/pproc#>
PREFIX s: <http://schema.org/>
PREFIX xsd: >http://www.w3.org/2001/XMLSchema#>
PREFIX pc: <http://purl.org/procurement/public-contracts#>
PREFIX gr: <http://purl.org/goodrelations/v1#>
PREFIX dcterms: <http://purl.org/dc/terms/>

SELECT DISTINCT ?contrato ?nombreContrato ?type ?adjudicatario ?impLicitacionSinIVA ?impLicitacionConIVA ?impCanon 
?impAdjudicacionSinIVA ?impAdjudicacionConIVA ?procedimiento ?entidad ?servicio ?numLicitadores 
WHERE {
  ?contrato dcterms:title ?nombreContrato;
  pproc:contractObject ?contractObject;
  pproc:managingDepartment ?managing.
  ?tender pc:supplier ?supplier.
  ?managing dcterms:title ?servicio.
  ?supplier s:name ?adjudicatario.
  ?contractObject pproc:contractEconomicConditions ?contractEconomicConditions.
  OPTIONAL{
    ?contractEconomicConditions pproc:budgetPrice ?budgetPriceNOVAT;
    pproc:budgetPrice ?budgetPriceVAT.
    ?budgetPriceNOVAT gr:hasCurrencyValue ?impLicitacionSinIVA;
    gr:valueAddedTaxIncluded "false"^^xsd:boolean.
    ?budgetPriceVAT gr:hasCurrencyValue ?impLicitacionConIVA;
    gr:valueAddedTaxIncluded "true"^^xsd:boolean.
  }
  OPTIONAL {
    ?contractEconomicConditions pproc:feePrice ?feePrice.
    ?feePrice gr:hasCurrencyValue ?impCanon;
    gr:valueAddedTaxIncluded "false"^^xsd:boolean.
  }
  ?tender pc:offeredPrice ?offeredPriceNOVAT;
  pc:offeredPrice ?offeredPriceVAT.
  ?offeredPriceNOVAT gr:hasCurrencyValue ?impAdjudicacionSinIVA;
  gr:valueAddedTaxIncluded "false"^^xsd:boolean.
  ?offeredPriceVAT gr:hasCurrencyValue ?impAdjudicacionConIVA;
  gr:valueAddedTaxIncluded "true"^^xsd:boolean.
    {
      SELECT DISTINCT ?contrato ?procedimiento ?type ?tender ?entidad ?servicio 
        WHERE {
          ?contrato a pproc:Contract;
          a ?type;
          pproc:contractProcedureSpecifications/pproc:procedureType ?procedimiento;
          pc:contractingAuthority/dcterms:title ?entidad;
          pc:tender ?tender;
          pproc:managingDepartment ?managing.
          ?tender a pproc:FormalizedTender;
          pproc:formalizedDate ?formalizedDate.
          ?managing dcterms:title ?servicio.
          FILTER  (regex(?formalizedDate, "2014")) 
        } 
    } 
    {
      SELECT DISTINCT ?contrato count(?tender) AS ?numLicitadores 
        WHERE {
          ?contrato a pproc:Contract;
          a ?type;pc:tender ?tender.
        } 
      GROUP BY ?contrato
    }
}
enridaga commented 8 years ago

To answer the question in the issue title, yes, Basil supports the SPARQL 1.1 syntax in full.

To solve your problem, try to rewrite the query like this:

SELECT DISTINCT ?contrato (count(?tender) AS ?numLicitadores) ...

Reason: basil uses the Apache Jena ARQ query parser, that is a strict SPARQL 1.1 compliant one. It looks like your query would work with a Virtuoso Endpoint, that has a more relaxed query parser. Let me know if this solves your problem.

enridaga commented 8 years ago

BTW, This looks like a nice query :) If you need, you could also enable parameter mappings. For example for a Tax inclusion, changing this

gr:valueAddedTaxIncluded "false"^^xsd:boolean

to

gr:valueAddedTaxIncluded ?_tax_xsd_boolean

and the query the API like this: http://basil.kmi.open.ac.uk/basil/..../api?tax=true

richhl commented 8 years ago

thx a lot. It works. The query exposed i not my merit. Take a look at https://github.com/zaragoza-sedeelectronica/zaragoza-sedeelectronica.github.io/

enridaga commented 8 years ago

This looks very interesting, thank you!

ocorcho commented 8 years ago

@enridaga, if you want more queries like this you can get them in that endpoint.