sparqlex v0.1.0 Sparql View Source
Overview
This module offers some functionality to parse SPARQL queries. To do this I have build a parser with the :leex and :yecc erlang libraries.
:leex and :yecc
You can find the source files as well as the compiled erlang files for this under ../parser-generator/
Since this uses raw erlang libraries under the hood all queries that get send are assumed to be single quoted strings
TODOs
TODO add a function to remove all graph statements TODO add a function to override all graph statements with a set of graph statements
Link to this section Summary
Functions
Converts all same-subject-paths into simple subject paths in SPARQL itself this is the equivalent of converting.
?s ?p ?o ; ?p2 ?o2 , ?o3 .
to
?s ?p ?o .
?s ?p2 ?o2 .
?s ?p2 ?o3 .
Parses a SPARQL query that gets passed in a single quoted string (see erlang documentation on the issues with double quoted strings)
Link to this section Functions
Converts all same-subject-paths into simple subject paths in SPARQL itself this is the equivalent of converting.
?s ?p ?o ; ?p2 ?o2 , ?o3 .
to
?s ?p ?o .
?s ?p2 ?o2 .
?s ?p2 ?o3 .
Examples
iex> Sparql.convert_to_simple_triples({:"same-subject-path", {:subject, {:variable, :s}},
iex> {:"predicate-list",
iex> [
iex> {{:predicate, {:variable, :p}},
iex> {:"object-list", [object: {:variable, :o}]}}
iex> ]}})
[
{{:subject, {:variable, :s}}, {:predicate, {:variable, :p}}, {:object, {:object, {:variable, :o}}}}
]
Parses a SPARQL query that gets passed in a single quoted string (see erlang documentation on the issues with double quoted strings)
Examples
iex> Sparql.parse('SELECT ?s ?p ?o WHERE { ?s ?p ?o }')
{:ok,
{:sparql,
{:select,
{:"select-clause", {:"var-list", [variable: :s, variable: :p, variable: :o]}},
{:where,
[
{:"same-subject-path", {:subject, {:variable, :s}},
{:"predicate-list",
[
{{:predicate, {:variable, :p}},
{:"object-list", [object: {:variable, :o}]}}
]}}
]}}
}
}