simple-graph-query 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -27,6 +27,9 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
|
|
|
27
27
|
private getLabelAsString;
|
|
28
28
|
private getLabelAsBoolean;
|
|
29
29
|
private getLabelAsNumber;
|
|
30
|
+
private isConvertibleToNumber;
|
|
31
|
+
private isConvertibleToBoolean;
|
|
32
|
+
private convertToBoolean;
|
|
30
33
|
private dotJoin;
|
|
31
34
|
private cacheResult;
|
|
32
35
|
private getIden;
|
|
@@ -48619,28 +48619,11 @@ class ForgeExprEvaluator extends AbstractParseTreeVisitor_1.AbstractParseTreeVis
|
|
|
48619
48619
|
this.relationCache = new Map();
|
|
48620
48620
|
this.relationIndexCache = new Map();
|
|
48621
48621
|
const relations = this.instanceData.getRelations();
|
|
48622
|
-
const isConvertibleToNumber = (value) => {
|
|
48623
|
-
return typeof value === "string" && !isNaN(Number(value));
|
|
48624
|
-
};
|
|
48625
|
-
const isConvertibleToBoolean = (value) => {
|
|
48626
|
-
if (typeof value === "boolean")
|
|
48627
|
-
return false; // already boolean
|
|
48628
|
-
return value === "true" || value === "#t" || value === "false" || value === "#f";
|
|
48629
|
-
};
|
|
48630
|
-
const convertToBoolean = (value) => {
|
|
48631
|
-
if (typeof value === "boolean")
|
|
48632
|
-
return value;
|
|
48633
|
-
if (value === "true" || value === "#t")
|
|
48634
|
-
return true;
|
|
48635
|
-
if (value === "false" || value === "#f")
|
|
48636
|
-
return false;
|
|
48637
|
-
throw new Error(`Cannot convert ${value} to boolean`);
|
|
48638
|
-
};
|
|
48639
48622
|
for (const relation of relations) {
|
|
48640
48623
|
let relationAtoms = relation.tuples.map((tuple) => tuple.atoms);
|
|
48641
48624
|
// Convert numeric and boolean strings to their actual types
|
|
48642
|
-
relationAtoms = relationAtoms.map((tuple) => tuple.map((value) => isConvertibleToNumber(value) ? Number(value) : value));
|
|
48643
|
-
relationAtoms = relationAtoms.map((tuple) => tuple.map((value) => isConvertibleToBoolean(value) ? convertToBoolean(value) : value));
|
|
48625
|
+
relationAtoms = relationAtoms.map((tuple) => tuple.map((value) => this.isConvertibleToNumber(value) ? Number(value) : value));
|
|
48626
|
+
relationAtoms = relationAtoms.map((tuple) => tuple.map((value) => this.isConvertibleToBoolean(value) ? this.convertToBoolean(value) : value));
|
|
48644
48627
|
this.relationCache.set(relation.name, relationAtoms);
|
|
48645
48628
|
// Build index for this relation: first element -> all tuples starting with that element
|
|
48646
48629
|
const relationIndex = new Map();
|
|
@@ -48751,6 +48734,39 @@ class ForgeExprEvaluator extends AbstractParseTreeVisitor_1.AbstractParseTreeVis
|
|
|
48751
48734
|
}
|
|
48752
48735
|
return labelNum;
|
|
48753
48736
|
}
|
|
48737
|
+
// Helper function to check if a value can be converted to a number
|
|
48738
|
+
isConvertibleToNumber(value) {
|
|
48739
|
+
if (typeof value === "number") {
|
|
48740
|
+
return true;
|
|
48741
|
+
}
|
|
48742
|
+
if (typeof value === "string") {
|
|
48743
|
+
return !isNaN(Number(value));
|
|
48744
|
+
}
|
|
48745
|
+
return false;
|
|
48746
|
+
}
|
|
48747
|
+
// Helper function to check if a value can be converted to a boolean
|
|
48748
|
+
isConvertibleToBoolean(value) {
|
|
48749
|
+
if (typeof value === "boolean") {
|
|
48750
|
+
return true;
|
|
48751
|
+
}
|
|
48752
|
+
if (typeof value === "string") {
|
|
48753
|
+
return (value === "true" || value === "#t" || value === "false" || value === "#f");
|
|
48754
|
+
}
|
|
48755
|
+
return false;
|
|
48756
|
+
}
|
|
48757
|
+
// Helper function to convert a value to boolean
|
|
48758
|
+
convertToBoolean(value) {
|
|
48759
|
+
if (typeof value === "boolean") {
|
|
48760
|
+
return value;
|
|
48761
|
+
}
|
|
48762
|
+
if (value === "true" || value === "#t") {
|
|
48763
|
+
return true;
|
|
48764
|
+
}
|
|
48765
|
+
if (value === "false" || value === "#f") {
|
|
48766
|
+
return false;
|
|
48767
|
+
}
|
|
48768
|
+
throw new Error(`Cannot convert ${value} to boolean`);
|
|
48769
|
+
}
|
|
48754
48770
|
// Optimized dotJoin that can use pre-built relation indexes
|
|
48755
48771
|
dotJoin(left, right, rightRelationName) {
|
|
48756
48772
|
const leftExpr = isSingleValue(left) ? [[left]] : left;
|
|
@@ -49953,6 +49969,42 @@ class ForgeExprEvaluator extends AbstractParseTreeVisitor_1.AbstractParseTreeVis
|
|
|
49953
49969
|
// }
|
|
49954
49970
|
return value;
|
|
49955
49971
|
}
|
|
49972
|
+
// Handle iden (identity relation)
|
|
49973
|
+
if (constant.IDEN_TOK() !== undefined) {
|
|
49974
|
+
// The identity relation contains tuples (x, x) for every atom x in the universe
|
|
49975
|
+
const atoms = this.instanceData.getAtoms();
|
|
49976
|
+
const idenRelation = [];
|
|
49977
|
+
for (const atom of atoms) {
|
|
49978
|
+
let atomValue = atom.id;
|
|
49979
|
+
// Convert numeric and boolean strings to their actual types
|
|
49980
|
+
if (this.isConvertibleToNumber(atomValue)) {
|
|
49981
|
+
atomValue = Number(atomValue);
|
|
49982
|
+
}
|
|
49983
|
+
else if (this.isConvertibleToBoolean(atomValue)) {
|
|
49984
|
+
atomValue = this.convertToBoolean(atomValue);
|
|
49985
|
+
}
|
|
49986
|
+
idenRelation.push([atomValue, atomValue]);
|
|
49987
|
+
}
|
|
49988
|
+
return idenRelation;
|
|
49989
|
+
}
|
|
49990
|
+
// Handle univ (universal relation - all atoms)
|
|
49991
|
+
if (constant.UNIV_TOK() !== undefined) {
|
|
49992
|
+
// The universal relation contains all atoms as unary tuples
|
|
49993
|
+
const atoms = this.instanceData.getAtoms();
|
|
49994
|
+
const univRelation = [];
|
|
49995
|
+
for (const atom of atoms) {
|
|
49996
|
+
let atomValue = atom.id;
|
|
49997
|
+
// Convert numeric and boolean strings to their actual types
|
|
49998
|
+
if (this.isConvertibleToNumber(atomValue)) {
|
|
49999
|
+
atomValue = Number(atomValue);
|
|
50000
|
+
}
|
|
50001
|
+
else if (this.isConvertibleToBoolean(atomValue)) {
|
|
50002
|
+
atomValue = this.convertToBoolean(atomValue);
|
|
50003
|
+
}
|
|
50004
|
+
univRelation.push([atomValue]);
|
|
50005
|
+
}
|
|
50006
|
+
return univRelation;
|
|
50007
|
+
}
|
|
49956
50008
|
// Handle boolean constants
|
|
49957
50009
|
if (constant.text === 'true') {
|
|
49958
50010
|
return true;
|
|
@@ -50184,46 +50236,15 @@ class ForgeExprEvaluator extends AbstractParseTreeVisitor_1.AbstractParseTreeVis
|
|
|
50184
50236
|
}
|
|
50185
50237
|
}
|
|
50186
50238
|
}
|
|
50187
|
-
//
|
|
50188
|
-
const isConvertibleToNumber = (value) => {
|
|
50189
|
-
if (typeof value === "number") {
|
|
50190
|
-
return true;
|
|
50191
|
-
}
|
|
50192
|
-
if (typeof value === "string") {
|
|
50193
|
-
return !isNaN(Number(value));
|
|
50194
|
-
}
|
|
50195
|
-
return false;
|
|
50196
|
-
};
|
|
50197
|
-
const isConvertibleToBoolean = (value) => {
|
|
50198
|
-
if (typeof value === "boolean") {
|
|
50199
|
-
return true;
|
|
50200
|
-
}
|
|
50201
|
-
if (typeof value === "string") {
|
|
50202
|
-
return (value === "true" || value === "#t" || value === "false" || value === "#f");
|
|
50203
|
-
}
|
|
50204
|
-
return false;
|
|
50205
|
-
};
|
|
50206
|
-
const convertToBoolean = (value) => {
|
|
50207
|
-
if (typeof value === "boolean") {
|
|
50208
|
-
return value;
|
|
50209
|
-
}
|
|
50210
|
-
if (value === "true" || value === "#t") {
|
|
50211
|
-
return true;
|
|
50212
|
-
}
|
|
50213
|
-
if (value === "false" || value === "#f") {
|
|
50214
|
-
return false;
|
|
50215
|
-
}
|
|
50216
|
-
throw new Error(`Cannot convert ${value} to boolean`);
|
|
50217
|
-
};
|
|
50218
|
-
// end of 3 helper functions
|
|
50239
|
+
// end of type search
|
|
50219
50240
|
// check if it is a relation - use cache for faster lookups
|
|
50220
50241
|
this.buildRelationCache();
|
|
50221
50242
|
if (this.relationCache.has(identifier)) {
|
|
50222
50243
|
return this.relationCache.get(identifier);
|
|
50223
50244
|
}
|
|
50224
50245
|
if (result !== undefined) {
|
|
50225
|
-
result = result.map((tuple) => tuple.map((value) => isConvertibleToNumber(value) ? Number(value) : value));
|
|
50226
|
-
result = result.map((tuple) => tuple.map((value) => isConvertibleToBoolean(value) ? convertToBoolean(value) : value));
|
|
50246
|
+
result = result.map((tuple) => tuple.map((value) => this.isConvertibleToNumber(value) ? Number(value) : value));
|
|
50247
|
+
result = result.map((tuple) => tuple.map((value) => this.isConvertibleToBoolean(value) ? this.convertToBoolean(value) : value));
|
|
50227
50248
|
return result;
|
|
50228
50249
|
}
|
|
50229
50250
|
// return identifier;
|
package/package.json
CHANGED