Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
sparqlalgebrajs
Advanced tools
2 components get exposed: the translate function and the Algebra object, which contains all the output types that can occur.
Note that this is still a work in progress so naming conventions could change. There is also support for 'non-algebra' entities such as ASK, FROM, etc. to make sure the output contains all relevant information from the query.
Input for the translate function should either be a SPARQL string or a result from calling SPARQL.js.
const { translate } = require('sparqlalgebrajs');
translate('SELECT * WHERE { ?x ?y ?z }');
Returns:
{ type: 'project',
input: { type: 'bgp', patterns: [
{ type: 'pattern', subject: '?x', predicate: '?y', object: '?z' } ] },
variables: [ '?x', '?y', '?z' ] }
Translating back to SPARQL can be done with the toSparql
(or toSparqlJs
) function.
The algebra object contains a types
object,
which contains all possible values for the type
field in the output results.
Besides that it also contains all the TypeScript interfaces of the possible output results.
The output of the translate
function will always be an Algebra.Operation
instance.
This implementation tries to stay as close to the SPARQL 1.1 specification, but some changes were made for ease of use. These are mostly based on the Jena ARQ implementation. What follows is a non-exhaustive list of deviations:
This is the biggest visual change. The functions no longer take an ordered list of parameters but a named list instead. The reason for this is to prevent having to memorize the order of parameters and also due to seeing some differences between the spec and the Jena ARQ SSE output when ordering parameters.
The functions toMultiset
and toList
have been removed for brevity.
Conversions between the two are implied by the operations used.
The translate
function has an optional second parameter
indicating whether patterns should be translated to triple or quad patterns.
In the case of quads the graph
operation will be removed
and embedded into the patterns it contained.
The default value for this parameter is false
.
PREFIX : <http://www.example.org/>
SELECT ?x WHERE {
GRAPH ?g {?x ?y ?z}
}
Default result:
{ type: 'project',
input: { type: 'graph', graph: '?g', input:
{ type: 'bgp', patterns:
[ { type: 'pattern', subject: '?x', predicate: '?y', object: '?z' } ] } },
variables: [ '?x' ] }
With quads:
{ type: 'project',
input: { type: 'bgp', patterns:
[ { type: 'pattern', subject: '?x', predicate: '?y', object: '?z', graph: '?g' } ] },
variables: [ '?x' ] }
For the VALUES block we return the following output:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://example.org/book/>
PREFIX ns: <http://example.org/ns#>
SELECT ?book ?title ?price
{
VALUES ?book { :book1 :book3 }
?book dc:title ?title ;
ns:price ?price .
}
{ type: 'project',
input:
{ type: 'join',
left: { type: 'values',
variables: ['?book'],
bindings: [
{ '?book': 'http://example.org/book/book1' },
{ '?book': 'http://example.org/book/book3' },
] },
right: { type: 'bgp',
patterns: [
{
type: 'pattern',
subject: '?book',
predicate: 'http://purl.org/dc/elements/1.1/title',
object: '?title'
},
{
type: 'pattern',
subject: '?book',
predicate: 'http://example.org/ns#price',
object: '?price'
}
] } },
variables: [ '?book', '?title', '?price' ] }
Some differences from Jena (again, non-exhaustive):
no prefixes are used (all uris get expanded)
and the project operation always gets used (even in the case of SELECT *
).
Every test consists of a sparql file and a corresponding json file containing the algebra result.
Tests ending with (quads)
in their name are tested/generated with quads: true
in the options.
FAQs
Convert SPARQL to SPARQL algebra
The npm package sparqlalgebrajs receives a total of 2,392 weekly downloads. As such, sparqlalgebrajs popularity was classified as popular.
We found that sparqlalgebrajs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.