RubenVerborgh / SPARQL.js

A parser for the SPARQL query language in JavaScript
Other
342 stars 66 forks source link

FunctionCallExpression doesn't work with string function #156

Closed SteinerPascal closed 1 year ago

SteinerPascal commented 2 years ago

Hi I'm using sparql.js to create a filter pattern with function call in SPARQL it should look like this:

FILTER (geof:sfWithin(?fWKT, '''
        <http://www.opengis.net/def/crs/OGC/1.3/CRS84>
            Polygon ((-83.4 34.0, -83.1 34.0,
                      -83.1 34.2, -83.4 34.2,
                      -83.4 34.0))
        '''^^geo:wktLiteral))

I followed as an example here: https://github.com/RubenVerborgh/SPARQL.js/blob/48363ab7c4bb54cf98287a715a8c1800a2e0fc78/test/parsedQueries/sparql/sparql-16-2-2a.json#L49-L63

my example:

{
  type: "filter",
  expression: {
    type: "functionCall",
    function: "geof:sfWithin",
    args: [
      {
        id: "?aWKT",
      },
      {
        id: "\"'''<http://www.opengis.net/def/crs/OGC/1.3/CRS84> \n        Polygon(( 46.19325970519137 6.127480741124601, 46.21737666278269 6.127480741124601, 46.21737666278269 6.158036466222257, 46.19325970519137 6.158036466222257, LatLng(46.19326, 6.127481)))\n        '''\"^^http://www.opengis.net/ont/geosparql#wktLiteral",
      },
    ],
  },
}

But i don't think this still works? It seems the type now must be of NamedNode or IRI

SteinerPascal commented 2 years ago

Okay i think i figured it out. The example from the repo won't work i think. It works when I use the function: <NamedNode> and not a string.

{
  type: "functionCall",
  function: {
    id: "geof:sfWithin",
  },
  args: [
    {
      id: "?aWKT",
    },
    {
      id: "\"'''<http://www.opengis.net/def/crs/OGC/1.3/CRS84>       Polygon(( 46.1952797580882 6.131257291417569, 46.21856441662584 6.131257291417569, 46.21856441662584 6.161469693761319, 46.1952797580882 6.161469693761319, LatLng(46.19528, 6.131257)))      '''\"^^http://www.opengis.net/ont/geosparql#wktLiteral",
    },
  ],
}

My suggestion:

  1. change type definition in https://github.com/DefinitelyTyped/DefinitelyTyped from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b453d9d1b99c48c8711c31c2a64e9dffb6ce729d/types/sparqljs/index.d.ts#L298-L302

to:

export interface FunctionCallExpression extends BaseExpression {
    type: 'functionCall';
    function: Term;
    args: Expression[];
}

Can you confirm that?

SteinerPascal commented 1 year ago

closing this since it is resolved