VOS.VirtTipsAndTricksGuideSpChar

  • Topic
  • Discussion
  • VOS.VirtTipsAndTricksGuideSpChar(Last) -- DAVWikiAdmin? , 2017-06-13 05:37:09 Edit WebDAV System Administrator 2017-06-13 00:37:09

    How Can I execute SPARQL queries containing '$' character using ISQL?

    Assuming a SPARQL query should filter on the length of labels:


    SELECT ?label
    FROM <http://mygraph.com>
    WHERE 
      { 
        ?s ?p ?label
        FILTER(regex(str(?label), "^.{1,256}$") )
      } 
    

    View the results of the query execution on the LOD instance.

    ISQL uses '$' character as a prefix for macro names of its preprocessor. When '$' character is used in SPARQL query to be executed in ISQL, the character should be replaced with '$$' notation or an escape char + numeric code:


    SQL> SPARQL 
    SELECT ?label
    FROM <http://mygraph.com>
    WHERE 
      { 
        ?s ?p ?label
        FILTER(REGEX(str(?label), "^.{1,256}$$") )
      } 
    

    View the results of the query execution on the LOD instance.

    Note also that the FILTER written in this way, finds ?label-s with length less than 256.

    To achieve fast results, REGEX should be replaced with the bif:length function:


    SQL> SPARQL 
    SELECT ?label
    FROM <http://mygraph.com>
    WHERE 
      { 
        ?s ?p ?label
        FILTER (bif:length(str(?label))<= 256)
      } 
    

    In this way the SPARQL query execution can work much faster if the interoperability is not required and ?label-s are numerous.

    View the results of the query execution on the LOD instance.

    Related