data-pipeline-information-system-sparql
Version:
Sparql function to query/update RDF through SPARQL 1.1
189 lines • 11.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var arithmetic_filter_1 = require("./arithmetic_filter");
var aggregate_filter_1 = require("./aggregate_filter");
var DefinitionPattern_1 = __importDefault(require("./DefinitionPattern"));
var _values_1 = __importDefault(require("./_values"));
var _filter_regex_1 = __importDefault(require("./_filter_regex"));
var UnaryOperationType;
(function (UnaryOperationType) {
UnaryOperationType["LOOK_ALIKE"] = "LOOK_ALIKE";
UnaryOperationType["FILTER"] = "FILTER";
UnaryOperationType["GREATER"] = "GREATER";
UnaryOperationType["LOWER"] = "LOWER";
UnaryOperationType["EQUAL"] = "EQUAL";
UnaryOperationType["AVG"] = "AVG";
UnaryOperationType["AVG_GREATER"] = "AVG_GREATER";
UnaryOperationType["AVG_LOWER"] = "AVG_LOWER";
UnaryOperationType["SUM"] = "SUM";
UnaryOperationType["SUM_GREATER"] = "SUM_GREATER";
UnaryOperationType["SUM_LOWER"] = "SUM_LOWER";
UnaryOperationType["COUNT"] = "COUNT";
UnaryOperationType["COUNT_GREATER"] = "COUNT_GREATER";
UnaryOperationType["COUNT_LOWER"] = "COUNT_LOWER";
UnaryOperationType["MIN"] = "MIN";
UnaryOperationType["MIN_GREATER"] = "MIN_GREATER";
UnaryOperationType["MIN_LOWER"] = "MIN_LOWER";
UnaryOperationType["MAX"] = "MAX";
UnaryOperationType["MAX_GREATER"] = "MAX_GREATER";
UnaryOperationType["MAX_LOWER"] = "MAX_LOWER";
})(UnaryOperationType = exports.UnaryOperationType || (exports.UnaryOperationType = {}));
function unaryFunction(unaryOperation, definition, reference) {
switch (unaryOperation.operation) {
case UnaryOperationType.FILTER:
if (Array.isArray(unaryOperation.json_pointers)) {
return _values_1.default(reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
return _values_1.default(reference, definition, [unaryOperation.json_pointers], unaryOperation.arguments);
}
case UnaryOperationType.LOOK_ALIKE:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return _filter_regex_1.default(reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.EQUAL:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return arithmetic_filter_1.arithmetic_filter(arithmetic_filter_1.ARITHMETIC_SYMBOL.EQUAL, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Attributes and arguments must be non array';
}
case UnaryOperationType.GREATER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return arithmetic_filter_1.arithmetic_filter(arithmetic_filter_1.ARITHMETIC_SYMBOL.GREATER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Attributes and arguments must be non array';
}
case UnaryOperationType.LOWER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return arithmetic_filter_1.arithmetic_filter(arithmetic_filter_1.ARITHMETIC_SYMBOL.LOWER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Attributes and arguments must be non array';
}
case UnaryOperationType.AVG:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.AVG, arithmetic_filter_1.ARITHMETIC_SYMBOL.EQUAL, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.AVG_GREATER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.AVG, arithmetic_filter_1.ARITHMETIC_SYMBOL.GREATER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.AVG_LOWER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.AVG, arithmetic_filter_1.ARITHMETIC_SYMBOL.LOWER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.COUNT:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.COUNT, arithmetic_filter_1.ARITHMETIC_SYMBOL.EQUAL, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.COUNT_GREATER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.COUNT, arithmetic_filter_1.ARITHMETIC_SYMBOL.GREATER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.COUNT_LOWER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.COUNT, arithmetic_filter_1.ARITHMETIC_SYMBOL.LOWER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.SUM:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.SUM, arithmetic_filter_1.ARITHMETIC_SYMBOL.EQUAL, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.SUM_GREATER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.SUM, arithmetic_filter_1.ARITHMETIC_SYMBOL.GREATER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.SUM_LOWER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.SUM, arithmetic_filter_1.ARITHMETIC_SYMBOL.LOWER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.MAX:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.MAX, arithmetic_filter_1.ARITHMETIC_SYMBOL.EQUAL, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.MAX_GREATER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.MAX, arithmetic_filter_1.ARITHMETIC_SYMBOL.GREATER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.MAX_LOWER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.MAX, arithmetic_filter_1.ARITHMETIC_SYMBOL.LOWER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.MIN:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.MIN, arithmetic_filter_1.ARITHMETIC_SYMBOL.EQUAL, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.MIN_GREATER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.MIN, arithmetic_filter_1.ARITHMETIC_SYMBOL.GREATER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
case UnaryOperationType.MIN_LOWER:
if (!Array.isArray(unaryOperation.arguments) && !Array.isArray(unaryOperation.json_pointers)) {
return aggregate_filter_1.aggregate_filter(aggregate_filter_1.AGGREGATE_KEYORD.MIN, arithmetic_filter_1.ARITHMETIC_SYMBOL.LOWER, reference, definition, unaryOperation.json_pointers, unaryOperation.arguments);
}
else {
throw 'Look alike parameters and arguments must be non array';
}
default:
throw 'Not a valid unary operation';
}
}
exports.unaryFunction = unaryFunction;
function operationUnroller(reference, unaryOperationArray) {
var _body = new DefinitionPattern_1.default(reference);
return unaryOperationArray.reduce(function (body, operation) {
return unaryFunction(operation, body, reference);
}, _body);
}
exports.operationUnroller = operationUnroller;
exports.default = unaryFunction;
//# sourceMappingURL=unaryFunctions.js.map