rubensworks / graphql-to-sparql.js

Converts GraphQL queries to SPARQL queries
MIT License
112 stars 17 forks source link

SPARQL Filter #30

Open nvbach91 opened 5 years ago

nvbach91 commented 5 years ago

Hi, is it possible to use SPARQL Filter to match strings with Regex?

Something like

const context = {
    'Company': `http://ontology.com/Company`,
    'name': `http://ontology.com/hasName`,
    'Name': `http://ontology.com/Name`,
    'a': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
    'value': `http://ontology.com/hasStringValue`
};
const query = `
{
    id ... on Company {
        name(a:Name) {
            value(first:20 regex:"/corp/i")
        }
    }
}
`;
PREFIX o: <http://ontology.com/>

SELECT ?id ?name_value WHERE {
  OPTIONAL {
    ?id a o:Company .
    {
      SELECT * WHERE {
        ?id o:hasName ?name .
        ?name a o:Name .
        ?name o:hasStringValue ?name_value .
        FILTER REGEX(?name_value, "corp", "i") .
      }
      LIMIT 20
    }
  }
}

Thanks in advance. Btw, I'm your fan!

rubensworks commented 5 years ago

Not possible at the moment, but this has been on my todo-list for a while, so this is definitely coming in the future! :-)