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

@comunica/actor-abstract-path

Package Overview
Dependencies
Maintainers
0
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@comunica/actor-abstract-path - npm Package Compare versions

Comparing version 3.2.4-alpha.47.0 to 3.3.0

29

lib/ActorAbstractPath.d.ts

@@ -0,11 +1,10 @@

import type { BindingsFactory } from '@comunica/bindings-factory';
import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';
import { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';
import type { IActorTest, TestResult } from '@comunica/core';
import type { IQueryOperationResultBindings, Bindings, IActionContext, MetadataBindings, IQuerySourceWrapper, ComunicaDataFactory } from '@comunica/types';
import type { BindingsFactory } from '@comunica/utils-bindings-factory';
import type { IActorTest } from '@comunica/core';
import type { IQueryOperationResultBindings, Bindings, IActionContext, MetadataBindings, IQuerySourceWrapper } from '@comunica/types';
import type * as RDF from '@rdfjs/types';
import type { AsyncIterator } from 'asynciterator';
import { BufferedIterator } from 'asynciterator';
import type { Factory } from 'sparqlalgebrajs';
import { Algebra } from 'sparqlalgebrajs';
import { Algebra, Factory } from 'sparqlalgebrajs';
/**

@@ -17,7 +16,8 @@ * An abstract actor that handles Path operations.

export declare abstract class ActorAbstractPath extends ActorQueryOperationTypedMediated<Algebra.Path> {
protected static readonly FACTORY: Factory;
protected readonly predicateType: string;
protected constructor(args: IActorQueryOperationTypedMediatedArgs, predicateType: string);
testOperation(operation: Algebra.Path, _context: IActionContext): Promise<TestResult<IActorTest>>;
generateVariable(dataFactory: ComunicaDataFactory, path?: Algebra.Path, name?: string): RDF.Variable;
isPathArbitraryLengthDistinct(algebraFactory: Factory, context: IActionContext, path: Algebra.Path): Promise<{
testOperation(operation: Algebra.Path, _context: IActionContext): Promise<IActorTest>;
generateVariable(path?: Algebra.Path, name?: string): RDF.Variable;
isPathArbitraryLengthDistinct(context: IActionContext, path: Algebra.Path): Promise<{
context: IActionContext;

@@ -36,10 +36,7 @@ operation: IQueryOperationResultBindings | undefined;

* @param emitFirstSubject If the path operation is predicate*, otherwise it is predicate+.
* @param algebraFactory The algebra factory.
* @param bindingsFactory The data factory.
* @return {Promise<AsyncIterator<Bindings>} Iterator to where all bindings of query should have been pushed.
*/
getObjectsPredicateStarEval(subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, object: RDF.Variable, graph: RDF.Term, context: IActionContext, emitFirstSubject: boolean, algebraFactory: Factory, bindingsFactory: BindingsFactory): Promise<IPathResultStream>;
getObjectsPredicateStarEval(subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, object: RDF.Variable, graph: RDF.Term, context: IActionContext, emitFirstSubject: boolean, bindingsFactory: BindingsFactory): Promise<IPathResultStream>;
/**
* Pushes all terms to iterator `it` that are a solution of object predicate* ?o.
* @param algebraFactory The algebra factory.
* @param {Term} object Term of where we start the predicate* search.

@@ -54,3 +51,3 @@ * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.

*/
getObjectsPredicateStar(algebraFactory: Factory, object: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashes: Record<string, RDF.Term>, it: BufferedIterator<RDF.Term>, counter: any): Promise<IPathResultStream['metadata'] | undefined>;
getObjectsPredicateStar(object: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashes: Record<string, RDF.Term>, it: BufferedIterator<RDF.Term>, counter: any): Promise<IPathResultStream['metadata'] | undefined>;
/**

@@ -71,7 +68,5 @@ * Pushes all terms to iterator `it` that are a solution of ?s predicate* ?o.

* @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).
* @param algebraFactory The algebra factory.
* @param bindingsFactory The bindings factory.
* @return {Promise<void>} All solutions of query should have been pushed to it by then.
*/
getSubjectAndObjectBindingsPredicateStar(subjectVar: RDF.Variable, objectVar: RDF.Variable, subjectVal: RDF.Term, objectVal: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashesGlobal: Record<string, Promise<RDF.Term[]>>, termHashesCurrentSubject: Record<string, boolean>, it: BufferedIterator<Bindings>, counter: any, algebraFactory: Factory, bindingsFactory: BindingsFactory): Promise<void>;
getSubjectAndObjectBindingsPredicateStar(subjectVar: RDF.Variable, objectVar: RDF.Variable, subjectVal: RDF.Term, objectVal: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashesGlobal: Record<string, Promise<RDF.Term[]>>, termHashesCurrentSubject: Record<string, boolean>, it: BufferedIterator<Bindings>, counter: any, bindingsFactory: BindingsFactory): Promise<void>;
/**

@@ -82,3 +77,3 @@ * Find all sources recursively contained in the given path operation.

getPathSources(operation: Algebra.PropertyPathSymbol): IQuerySourceWrapper[];
assignPatternSources(algebraFactory: Factory, pattern: Algebra.Pattern, sources: IQuerySourceWrapper[]): Algebra.Operation;
assignPatternSources(pattern: Algebra.Pattern, sources: IQuerySourceWrapper[]): Algebra.Operation;
}

@@ -85,0 +80,0 @@ export interface IPathResultStream {

@@ -6,8 +6,8 @@ "use strict";

const context_entries_1 = require("@comunica/context-entries");
const core_1 = require("@comunica/core");
const utils_query_operation_1 = require("@comunica/utils-query-operation");
const asynciterator_1 = require("asynciterator");
const rdf_data_factory_1 = require("rdf-data-factory");
const rdf_string_1 = require("rdf-string");
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
const PathVariableObjectIterator_1 = require("./PathVariableObjectIterator");
const DF = new rdf_data_factory_1.DataFactory();
/**

@@ -25,16 +25,16 @@ * An abstract actor that handles Path operations.

if (operation.predicate.type !== this.predicateType) {
return (0, core_1.failTest)(`This Actor only supports ${this.predicateType} Path operations.`);
throw new Error(`This Actor only supports ${this.predicateType} Path operations.`);
}
return (0, core_1.passTestVoid)();
return true;
}
// Generates a variable that does not yet occur in the path
generateVariable(dataFactory, path, name) {
generateVariable(path, name) {
if (!name) {
return this.generateVariable(dataFactory, path, 'b');
return this.generateVariable(path, 'b');
}
// Path predicates can't contain variables
if (path && (path.subject.value === name || path.object.value === name)) {
return this.generateVariable(dataFactory, path, `${name}b`);
return this.generateVariable(path, `${name}b`);
}
return dataFactory.variable(name);
return DF.variable(name);
}

@@ -44,7 +44,7 @@ // Such connectivity matching does not introduce duplicates (it does not incorporate any count of the number

// https://www.w3.org/TR/sparql11-query/#propertypaths
async isPathArbitraryLengthDistinct(algebraFactory, context, path) {
async isPathArbitraryLengthDistinct(context, path) {
if (!context.get(context_entries_1.KeysQueryOperation.isPathArbitraryLengthDistinctKey)) {
context = context.set(context_entries_1.KeysQueryOperation.isPathArbitraryLengthDistinctKey, true);
return { context, operation: (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({
operation: algebraFactory.createDistinct(path),
return { context, operation: bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({
operation: ActorAbstractPath.FACTORY.createDistinct(path),
context,

@@ -56,13 +56,13 @@ })) };

}
async predicateStarGraphVariable(subject, object, predicate, graph, context, algebraFactory, bindingsFactory) {
async predicateStarGraphVariable(subject, object, predicate, graph, context, bindingsFactory) {
const sources = this.getPathSources(predicate);
// TODO: refactor this with an iterator just like PathVariableObjectIterator so we handle backpressure correctly
// Construct path to obtain all graphs where subject exists
const predVar = this.generateVariable(algebraFactory.dataFactory, algebraFactory
const predVar = this.generateVariable(ActorAbstractPath.FACTORY
.createPath(subject, predicate, object, graph));
const findGraphs = algebraFactory.createUnion([
this.assignPatternSources(algebraFactory, algebraFactory.createPattern(subject, predVar, object, graph), sources),
this.assignPatternSources(algebraFactory, algebraFactory.createPattern(object, predVar, subject, graph), sources),
const findGraphs = ActorAbstractPath.FACTORY.createUnion([
this.assignPatternSources(ActorAbstractPath.FACTORY.createPattern(subject, predVar, object, graph), sources),
this.assignPatternSources(ActorAbstractPath.FACTORY.createPattern(object, predVar, subject, graph), sources),
]);
const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ context, operation: findGraphs }));
const results = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({ context, operation: findGraphs }));
const passedGraphs = new Set();

@@ -79,4 +79,3 @@ const bindingsStream = new asynciterator_1.MultiTransformIterator(results.bindingsStream, {

const it = new asynciterator_1.BufferedIterator();
await this
.getObjectsPredicateStar(algebraFactory, subject, predicate, graphValue, context, {}, it, { count: 0 });
await this.getObjectsPredicateStar(subject, predicate, graphValue, context, {}, it, { count: 0 });
return it.transform({

@@ -109,12 +108,9 @@ transform(item, next, push) {

* @param emitFirstSubject If the path operation is predicate*, otherwise it is predicate+.
* @param algebraFactory The algebra factory.
* @param bindingsFactory The data factory.
* @return {Promise<AsyncIterator<Bindings>} Iterator to where all bindings of query should have been pushed.
*/
async getObjectsPredicateStarEval(subject, predicate, object, graph, context, emitFirstSubject, algebraFactory, bindingsFactory) {
async getObjectsPredicateStarEval(subject, predicate, object, graph, context, emitFirstSubject, bindingsFactory) {
if (graph.termType === 'Variable') {
return this
.predicateStarGraphVariable(subject, object, predicate, graph, context, algebraFactory, bindingsFactory);
return this.predicateStarGraphVariable(subject, object, predicate, graph, context, bindingsFactory);
}
const it = new PathVariableObjectIterator_1.PathVariableObjectIterator(algebraFactory, subject, predicate, graph, context, this.mediatorQueryOperation, emitFirstSubject);
const it = new PathVariableObjectIterator_1.PathVariableObjectIterator(subject, predicate, graph, context, this.mediatorQueryOperation, emitFirstSubject);
const bindingsStream = it.transform({

@@ -142,3 +138,2 @@ autoStart: false,

* Pushes all terms to iterator `it` that are a solution of object predicate* ?o.
* @param algebraFactory The algebra factory.
* @param {Term} object Term of where we start the predicate* search.

@@ -153,3 +148,3 @@ * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.

*/
async getObjectsPredicateStar(algebraFactory, object, predicate, graph, context, termHashes, it, counter) {
async getObjectsPredicateStar(object, predicate, graph, context, termHashes, it, counter) {
const termString = (0, rdf_string_1.termToString)(object);

@@ -162,5 +157,5 @@ if (termHashes[termString]) {

counter.count++;
const thisVariable = this.generateVariable(algebraFactory.dataFactory);
const path = algebraFactory.createPath(object, predicate, thisVariable, graph);
const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation: path, context }));
const thisVariable = this.generateVariable();
const path = ActorAbstractPath.FACTORY.createPath(object, predicate, thisVariable, graph);
const results = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({ operation: path, context }));
// TODO: fixme

@@ -170,3 +165,3 @@ // eslint-disable-next-line ts/no-misused-promises

const result = bindings.get(thisVariable);
await this.getObjectsPredicateStar(algebraFactory, result, predicate, graph, context, termHashes, it, counter);
await this.getObjectsPredicateStar(result, predicate, graph, context, termHashes, it, counter);
});

@@ -195,4 +190,2 @@ results.bindingsStream.on('end', () => {

* @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).
* @param algebraFactory The algebra factory.
* @param bindingsFactory The bindings factory.
* @return {Promise<void>} All solutions of query should have been pushed to it by then.

@@ -202,3 +195,3 @@ */

// and objectStringVariable as value all nodes reachable through predicate* beginning at objectVal
async getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, objectVal, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, algebraFactory, bindingsFactory) {
async getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, objectVal, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, bindingsFactory) {
const termString = (0, rdf_string_1.termToString)(objectVal) + (0, rdf_string_1.termToString)(graph);

@@ -219,3 +212,3 @@ // If this combination of subject and object already done, return nothing

for (const object of objects) {
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, object, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, algebraFactory, bindingsFactory);
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, object, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, bindingsFactory);
}

@@ -233,5 +226,5 @@ if (--counter.count === 0) {

// Construct path that leads us one step through predicate
const thisVariable = this.generateVariable(algebraFactory.dataFactory);
const path = algebraFactory.createPath(objectVal, predicate, thisVariable, graph);
const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation: path, context }));
const thisVariable = this.generateVariable();
const path = ActorAbstractPath.FACTORY.createPath(objectVal, predicate, thisVariable, graph);
const results = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({ operation: path, context }));
// Recursive call on all neighbours

@@ -243,3 +236,3 @@ // TODO: fixme

objectsArray.push(result);
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, result, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, algebraFactory, bindingsFactory);
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, result, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, bindingsFactory);
});

@@ -274,3 +267,3 @@ results.bindingsStream.on('error', reject);

case sparqlalgebrajs_1.Algebra.types.NPS: {
const source = (0, utils_query_operation_1.getOperationSource)(operation);
const source = bus_query_operation_1.ActorQueryOperation.getOperationSource(operation);
if (!source) {

@@ -283,3 +276,3 @@ throw new Error(`Could not find a required source on a link path operation`);

}
assignPatternSources(algebraFactory, pattern, sources) {
assignPatternSources(pattern, sources) {
if (sources.length === 0) {

@@ -289,9 +282,10 @@ throw new Error(`Attempted to assign zero sources to a pattern during property path handling`);

if (sources.length === 1) {
return (0, utils_query_operation_1.assignOperationSource)(pattern, sources[0]);
return bus_query_operation_1.ActorQueryOperation.assignOperationSource(pattern, sources[0]);
}
return algebraFactory.createUnion(sources
.map(source => (0, utils_query_operation_1.assignOperationSource)(pattern, source)), true);
return ActorAbstractPath.FACTORY.createUnion(sources
.map(source => bus_query_operation_1.ActorQueryOperation.assignOperationSource(pattern, source)), true);
}
}
exports.ActorAbstractPath = ActorAbstractPath;
ActorAbstractPath.FACTORY = new sparqlalgebrajs_1.Factory();
//# sourceMappingURL=ActorAbstractPath.js.map

@@ -5,3 +5,3 @@ import type { MediatorQueryOperation } from '@comunica/bus-query-operation';

import { BufferedIterator } from 'asynciterator';
import type { Algebra, Factory } from 'sparqlalgebrajs';
import type { Algebra } from 'sparqlalgebrajs';
/**

@@ -12,3 +12,2 @@ * An iterator that implements the multi-length property path operation (* and +)

export declare class PathVariableObjectIterator extends BufferedIterator<RDF.Term> {
private readonly algebraFactory;
private readonly subject;

@@ -23,3 +22,3 @@ private readonly predicate;

private readonly pendingOperations;
constructor(algebraFactory: Factory, subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, emitFirstSubject: boolean, maxRunningOperations?: number);
constructor(subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, emitFirstSubject: boolean, maxRunningOperations?: number);
protected _end(destroy?: boolean): void;

@@ -26,0 +25,0 @@ protected _push(item: RDF.Term, pushAsResult?: boolean): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PathVariableObjectIterator = void 0;
const utils_query_operation_1 = require("@comunica/utils-query-operation");
const bus_query_operation_1 = require("@comunica/bus-query-operation");
const asynciterator_1 = require("asynciterator");
const rdf_data_factory_1 = require("rdf-data-factory");
const rdf_string_1 = require("rdf-string");
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
const DF = new rdf_data_factory_1.DataFactory();
const FACTORY = new sparqlalgebrajs_1.Factory();
/**

@@ -12,6 +16,5 @@ * An iterator that implements the multi-length property path operation (* and +)

class PathVariableObjectIterator extends asynciterator_1.BufferedIterator {
constructor(algebraFactory, subject, predicate, graph, context, mediatorQueryOperation, emitFirstSubject, maxRunningOperations = 16) {
constructor(subject, predicate, graph, context, mediatorQueryOperation, emitFirstSubject, maxRunningOperations = 16) {
// The autoStart flag must be true to kickstart metadata collection
super({ autoStart: true });
this.algebraFactory = algebraFactory;
this.subject = subject;

@@ -46,6 +49,6 @@ this.predicate = predicate;

// Add a pending path operation for this item
const variable = this.algebraFactory.dataFactory.variable('b');
const variable = DF.variable('b');
this.pendingOperations.push({
variable,
operation: this.algebraFactory.createPath(item, this.predicate, variable, this.graph),
operation: FACTORY.createPath(item, this.predicate, variable, this.graph),
});

@@ -68,3 +71,3 @@ // Otherwise, push the subject

const pendingOperation = self.pendingOperations.pop();
const results = (0, utils_query_operation_1.getSafeBindings)(await self.mediatorQueryOperation.mediate({ operation: pendingOperation.operation, context: self.context }));
const results = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await self.mediatorQueryOperation.mediate({ operation: pendingOperation.operation, context: self.context }));
const runningOperation = results.bindingsStream.transform({

@@ -71,0 +74,0 @@ autoStart: false,

{
"name": "@comunica/actor-abstract-path",
"version": "3.2.4-alpha.47.0",
"version": "3.3.0",
"description": "An abstract actor for handling mediatypes",
"lsd:module": true,
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/comunica-association"
},
"homepage": "https://comunica.dev/",

@@ -44,14 +40,14 @@ "repository": {

"dependencies": {
"@comunica/bus-query-operation": "3.2.4-alpha.47.0",
"@comunica/context-entries": "3.2.4-alpha.47.0",
"@comunica/core": "3.2.4-alpha.47.0",
"@comunica/types": "3.2.4-alpha.47.0",
"@comunica/utils-bindings-factory": "3.2.4-alpha.47.0",
"@comunica/utils-query-operation": "3.2.4-alpha.47.0",
"@comunica/bindings-factory": "^3.3.0",
"@comunica/bus-query-operation": "^3.3.0",
"@comunica/context-entries": "^3.3.0",
"@comunica/core": "^3.3.0",
"@comunica/types": "^3.3.0",
"@rdfjs/types": "*",
"asynciterator": "^3.9.0",
"rdf-data-factory": "^1.1.1",
"rdf-string": "^1.6.1",
"sparqlalgebrajs": "^4.3.8"
"sparqlalgebrajs": "^4.3.7"
},
"gitHead": "85bd4c5cf07dfc293ebbc3a1416b70e2db8bfc48"
"gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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