Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sparqlalgebrajs

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparqlalgebrajs - npm Package Compare versions

Comparing version 4.3.2 to 4.3.3

86

lib/sparqlAlgebra.js

@@ -83,3 +83,3 @@ "use strict";

const group = { type: 'group', patterns: sparql.where || [] };
res = translateGroupGraphPattern(group);
res = translateGraphPattern(group);
res = translateAggregates(sparql, res);

@@ -198,43 +198,54 @@ }

}
function translateGroupGraphPattern(thingy) {
function translateGraphPattern(thingy) {
// 18.2.2.1
// already done by sparql parser
// 18.2.2.2
let filters = [];
let nonfilters = [];
if ('patterns' in thingy)
for (let pattern of thingy.patterns)
(pattern.type === 'filter' ? filters : nonfilters).push(pattern);
// 18.2.2.3
// 18.2.2.4
// 18.2.2.5
if (thingy.type === 'bgp')
// In Sparql.js, a group with a single BGP in it is a single object.
if (thingy.type === 'bgp') {
return translateBgp(thingy);
// 18.2.2.6
let result;
}
// 18.2.2.6 - GroupOrUnionGraphPattern
if (thingy.type === 'union')
result = factory.createUnion(nonfilters.map((p) => {
return factory.createUnion(thingy.patterns.map((p) => {
// sparqljs doesn't always indicate the children are groups
if (p.type !== 'group')
p = { type: 'group', patterns: [p] };
return translateGroupGraphPattern(p);
return translateGraphPattern(p);
}));
else if (thingy.type === 'graph')
// need to handle this separately since the filters need to be in the graph
return translateGraph(thingy);
else if (thingy.type === 'group')
result = nonfilters.reduce(accumulateGroupGraphPattern, factory.createBgp([]));
// custom values operation
else if (thingy.type === 'values')
result = translateInlineData(thingy);
else if (thingy.type === 'query')
result = translateQuery(thingy, useQuads, false);
else
throw new Error(`Unexpected type: ${thingy.type}`);
if (filters.length > 0) {
// 18.2.2.6 - GraphGraphPattern
if (thingy.type === 'graph') {
// Sparql.js combines the group graph pattern and the graph itself in the same object.
// We split here so the group graph pattern can be interpreted correctly.
const group = { type: 'group', patterns: thingy.patterns };
let result = translateGraphPattern(group);
// Output depends on if we use quads or not
if (useQuads)
result = recurseGraph(result, thingy.name);
else
result = factory.createGraph(result, thingy.name);
return result;
}
// 18.2.2.6 - InlineData
if (thingy.type === 'values')
return translateInlineData(thingy);
// 18.2.2.6 - SubSelect
if (thingy.type === 'query')
return translateQuery(thingy, useQuads, false);
if (thingy.type === 'group') {
// 18.2.2.2
let filters = [];
let nonfilters = [];
for (let pattern of thingy.patterns)
(pattern.type === 'filter' ? filters : nonfilters).push(pattern);
// 18.2.2.6 - GroupGraphPattern
let result = nonfilters.reduce(accumulateGroupGraphPattern, factory.createBgp([]));
// 18.2.2.7
let expressions = filters.map(filter => translateExpression(filter.expression));
if (expressions.length > 0)
result = factory.createFilter(result, expressions.reduce((acc, exp) => factory.createOperatorExpression('&&', [acc, exp])));
return result;
}
return result;
throw new Error(`Unexpected type: ${thingy.type}`);
}

@@ -263,3 +274,3 @@ function translateExpression(exp) {

if (exp.operator === 'exists' || exp.operator === 'notexists')
return factory.createExistenceExpression(exp.operator === 'notexists', translateGroupGraphPattern(exp.args[0]));
return factory.createExistenceExpression(exp.operator === 'notexists', translateGraphPattern(exp.args[0]));
if (exp.operator === 'in' || exp.operator === 'notin')

@@ -384,11 +395,2 @@ exp.args = [exp.args[0]].concat(exp.args[1]); // sparql.js uses 2 arguments with the second one being a list

}
function translateGraph(graph) {
const group = { type: 'group', patterns: graph.patterns };
let result = translateGroupGraphPattern(group);
if (useQuads)
result = recurseGraph(result, graph.name);
else
result = factory.createGraph(result, graph.name);
return result;
}
let typeVals = Object.values(types);

@@ -463,3 +465,3 @@ function recurseGraph(thingy, graph, replacement) {

// optional input needs to be interpreted as a group
const A = translateGroupGraphPattern({ type: 'group', patterns: E.patterns });
const A = translateGraphPattern({ type: 'group', patterns: E.patterns });
if (A.type === types.FILTER) {

@@ -473,3 +475,3 @@ G = factory.createLeftJoin(G, A.input, A.expression);

// minus input needs to be interpreted as a group
const A = translateGroupGraphPattern({ type: 'group', patterns: E.patterns });
const A = translateGraphPattern({ type: 'group', patterns: E.patterns });
G = factory.createMinus(G, A);

@@ -482,7 +484,7 @@ }

const group = { type: 'group', patterns: E.patterns };
const A = factory.createService(translateGroupGraphPattern(group), E.name, E.silent);
const A = factory.createService(translateGraphPattern(group), E.name, E.silent);
G = simplifiedJoin(G, A);
}
else {
const A = translateGroupGraphPattern(E);
const A = translateGraphPattern(E);
G = simplifiedJoin(G, A);

@@ -674,3 +676,3 @@ }

if (thingy.where && thingy.where.length > 0) {
where = translateGroupGraphPattern({ type: 'group', patterns: thingy.where });
where = translateGraphPattern({ type: 'group', patterns: thingy.where });
// Wrong typings, see test "using" in Sparql.js

@@ -677,0 +679,0 @@ const using = thingy.using;

{
"name": "sparqlalgebrajs",
"version": "4.3.2",
"version": "4.3.3",
"description": "Convert SPARQL to SPARQL algebra",

@@ -33,3 +33,3 @@ "author": "Joachim Van Herwegen",

"@types/node": "^20.0.0",
"chai": "^4.3.6",
"chai": "^5.0.0",
"jest": "^28.1.3",

@@ -36,0 +36,0 @@ "pre-commit": "^1.2.2",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc