cmungall / sparqlprog

logic programming with SPARQL
http://www.swi-prolog.org/pack/list?p=sparqlprog
46 stars 7 forks source link

sparql query formatting #13

Open justin2004 opened 3 years ago

justin2004 commented 3 years ago

note: indentation and URI shortening are on the cards for future releases.

just wanted to share that there is a command line utility in apache jena that can do the sparql query formatting.

e.g.

justin@parens:/tmp$ cat a.sparql 
SELECT ?g ?h WHERE {?g <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/SO_0001217> . ?g <http://biohackathon.org/resource/faldo#location> ?l . ?l <http://biohackathon.org/resource/faldo#begin> ?v0 . ?v0 <http://biohackathon.org/resource/faldo#position> ?b . ?v0 <http://biohackathon.org/resource/faldo#reference> <http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11> . ?l <http://biohackathon.org/resource/faldo#end> ?v1 . ?v1 <http://biohackathon.org/resource/faldo#position> ?e . ?v1 <http://biohackathon.org/resource/faldo#reference> <http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11> . FILTER (?b >= 101100523) . FILTER (?e <= 101190725) . ?g <http://semanticscience.org/resource/SIO_000558> ?h . ?h <http://purl.obolibrary.org/obo/RO_0002162> <http://identifiers.org/taxonomy/9606>}
justin@parens:/tmp$ 
justin@parens:/tmp$ qparse --query a.sparql 
SELECT  ?g ?h
WHERE
  { ?g   a                     <http://purl.obolibrary.org/obo/SO_0001217> ;
         <http://biohackathon.org/resource/faldo#location>  ?l .
    ?l   <http://biohackathon.org/resource/faldo#begin>  ?v0 .
    ?v0  <http://biohackathon.org/resource/faldo#position>  ?b ;
         <http://biohackathon.org/resource/faldo#reference>  <http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11> .
    ?l   <http://biohackathon.org/resource/faldo#end>  ?v1 .
    ?v1  <http://biohackathon.org/resource/faldo#position>  ?e ;
         <http://biohackathon.org/resource/faldo#reference>  <http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11>
    FILTER ( ?b >= 101100523 )
    FILTER ( ?e <= 101190725 )
    ?g  <http://semanticscience.org/resource/SIO_000558>  ?h .
    ?h  <http://purl.obolibrary.org/obo/RO_0002162>  <http://identifiers.org/taxonomy/9606>
  }
justin2004 commented 3 years ago

and i bet if you prepend prefixes it'll shorten the URIs

cmungall commented 3 years ago

Nice! I have been using a hacky perl script

On Sun, May 2, 2021, 07:09 justin2004 @.***> wrote:

note: indentation and URI shortening are on the cards for future releases.

just wanted to share that there is a command line utility in apache jena https://jena.apache.org/ that can do the sparql query formatting.

e.g.

@.:/tmp$ cat a.sparql SELECT ?g ?h WHERE {?g http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://purl.obolibrary.org/obo/SO_0001217 . ?g http://biohackathon.org/resource/faldo#location ?l . ?l http://biohackathon.org/resource/faldo#begin ?v0 . ?v0 http://biohackathon.org/resource/faldo#position ?b . ?v0 http://biohackathon.org/resource/faldo#reference http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11 . ?l http://biohackathon.org/resource/faldo#end ?v1 . ?v1 http://biohackathon.org/resource/faldo#position ?e . ?v1 http://biohackathon.org/resource/faldo#reference http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11 . FILTER (?b >= 101100523) . FILTER (?e <= 101190725) . ?g http://semanticscience.org/resource/SIO_000558 ?h . ?h http://purl.obolibrary.org/obo/RO_0002162 http://identifiers.org/taxonomy/9606} @.:/tmp$ @.***:/tmp$ qparse --query a.sparql SELECT ?g ?h WHERE { ?g a http://purl.obolibrary.org/obo/SO_0001217 ; http://biohackathon.org/resource/faldo#location ?l . ?l http://biohackathon.org/resource/faldo#begin ?v0 . ?v0 http://biohackathon.org/resource/faldo#position ?b ; http://biohackathon.org/resource/faldo#reference http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11 . ?l http://biohackathon.org/resource/faldo#end ?v1 . ?v1 http://biohackathon.org/resource/faldo#position ?e ; http://biohackathon.org/resource/faldo#reference http://rdf.ebi.ac.uk/resource/ensembl/90/mus_musculus/GRCm38/11 FILTER ( ?b >= 101100523 ) FILTER ( ?e <= 101190725 ) ?g http://semanticscience.org/resource/SIO_000558 ?h . ?h http://purl.obolibrary.org/obo/RO_0002162 http://identifiers.org/taxonomy/9606 }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cmungall/sparqlprog/issues/13, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMMOPSJX6AFECDZUYLTH3TLVMKNANCNFSM437N6H2A .