UNPKG

sparnatural

Version:

Visual client-side SPARQL query builder and knowledge graph exploration tool

98 lines 4.67 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _SparnaturalJsonGenerator_instances, _SparnaturalJsonGenerator_toVariables, _SparnaturalJsonGenerator_getBranch; import { Order, } from "../../SparnaturalQueryIfc"; import { OptionTypes } from "../../components/builder-section/groupwrapper/criteriagroup/optionsgroup/OptionsGroup"; import { DataFactory } from "rdf-data-factory"; const factory = new DataFactory(); /* Reads out the UI and creates the internal JSON structure described here: https://docs.sparnatural.eu/Query-JSON-format */ export class SparnaturalJsonGenerator { constructor(sparnatural) { _SparnaturalJsonGenerator_instances.add(this); this.json = { distinct: null, variables: null, order: null, branches: null, }; this.sparnatural = sparnatural; } generateQuery(variables, order, distinct, limit) { this.json.distinct = distinct; this.json.variables = __classPrivateFieldGet(this, _SparnaturalJsonGenerator_instances, "m", _SparnaturalJsonGenerator_toVariables).call(this, variables); // don't output "noord", just set it to null if (order != Order.NOORDER) { this.json.order = order; } else { this.json.order = null; } this.json.branches = __classPrivateFieldGet(this, _SparnaturalJsonGenerator_instances, "m", _SparnaturalJsonGenerator_getBranch).call(this, this.sparnatural.BgWrapper.componentsList.rootGroupWrapper, false); this.json.limit = limit; return this.json; } } _SparnaturalJsonGenerator_instances = new WeakSet(), _SparnaturalJsonGenerator_toVariables = function _SparnaturalJsonGenerator_toVariables(variables) { return variables.map((v) => { if (v.aggregateFunction) { return { expression: { type: "aggregate", aggregation: v.aggregateFunction, distinct: false, expression: { termType: "Variable", value: v.originalVariable.variable, }, }, variable: { termType: "Variable", value: v.selectedVariable.variable, }, }; } else { return { termType: "Variable", value: v.selectedVariable.variable, }; } }); }, _SparnaturalJsonGenerator_getBranch = function _SparnaturalJsonGenerator_getBranch(grpWrapper, isInOption) { let branches = []; let CrtGrp = grpWrapper.criteriaGroup; let branch = { line: { s: CrtGrp.startClassGroup.getVarName(), p: CrtGrp.objectPropertyGroup.getTypeSelected(), o: CrtGrp.endClassGroup.getVarName(), sType: CrtGrp.startClassGroup.getTypeSelected(), oType: CrtGrp.endClassGroup.getTypeSelected(), // extract only the value part, not the key criterias: CrtGrp.endClassWidgetGroup.getWidgetValues(), }, children: grpWrapper.whereChild // either we are already in an option, or one was set at this level ? __classPrivateFieldGet(this, _SparnaturalJsonGenerator_instances, "m", _SparnaturalJsonGenerator_getBranch).call(this, grpWrapper.whereChild, isInOption || (grpWrapper.currentOptionState != OptionTypes.NONE)) : undefined }; // don't set the flags if they are not true if (!isInOption && (grpWrapper.currentOptionState == OptionTypes.OPTIONAL)) { branch.optional = true; } if (!isInOption && (grpWrapper.currentOptionState == OptionTypes.NOTEXISTS)) { branch.notExists = true; } branches.push(branch); if (grpWrapper.andSibling) // pass the "isInOption" flag down branches.push(...__classPrivateFieldGet(this, _SparnaturalJsonGenerator_instances, "m", _SparnaturalJsonGenerator_getBranch).call(this, grpWrapper.andSibling, isInOption)); // spread operatore since getBranch() returns an array return branches; }; //# sourceMappingURL=SparnaturalJsonGenerator.js.map