sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
125 lines • 4.32 kB
JavaScript
;
;
export var Order;
(function (Order) {
Order["ASC"] = "asc";
Order["DESC"] = "desc";
Order["NOORDER"] = "noord";
})(Order || (Order = {}));
export var AggregateFunction;
(function (AggregateFunction) {
AggregateFunction["COUNT"] = "count";
AggregateFunction["MAX"] = "max";
AggregateFunction["MIN"] = "min";
AggregateFunction["SUM"] = "sum";
AggregateFunction["GROUP_CONCAT"] = "group_concat";
AggregateFunction["SAMPLE"] = "sample";
AggregateFunction["AVG"] = "avg";
})(AggregateFunction || (AggregateFunction = {}));
//////////////////////////////////////////////////////////////////////////////////////////////
/**
* @param t1
* @param t2
* @returns true if both RDF term are equal (same type, same value, same datatype, same language)
*/
export function sameTerm(t1, t2) {
return (t1 != null
&&
t2 != null
&&
t1.type == t2.type
&&
t1.value == t2.value
&&
t1.datatype == t2.datatype
&&
t1["xml:lang"] == t2["xml:lang"]);
}
export var CriteriaType;
(function (CriteriaType) {
CriteriaType["RdfTermCriteria"] = "RdfTermCriteria";
CriteriaType["DateCriteria"] = "DateCriteria";
CriteriaType["BooleanCriteria"] = "BooleanCriteria";
CriteriaType["MapCriteria"] = "MapCriteria";
CriteriaType["NumberCriteria"] = "NumberCriteria";
CriteriaType["SearchCriteria"] = "SearchCriteria";
})(CriteriaType || (CriteriaType = {}));
/**
* Returns the type name of the given WidgetValue.
* @param value The WidgetValue to check.
* @returns The type name as a string ("MapValue", "RdfTermValue", etc.), or undefined if unknown.
*/
export function getCriteriaType(value) {
if (typeof value === "object" && value !== null) {
if ("rdfTerm" in value)
return CriteriaType.RdfTermCriteria;
if ("coordinates" in value)
return CriteriaType.MapCriteria;
if ("start" in value || "stop" in value)
return CriteriaType.DateCriteria;
if ("boolean" in value)
return CriteriaType.BooleanCriteria;
if ("min" in value || "max" in value)
return CriteriaType.NumberCriteria;
if ("search" in value)
return CriteriaType.SearchCriteria;
}
return undefined;
}
/**
* Tests the equality of two WidgetValue objects.
* @param v1 The first WidgetValue.
* @param v2 The second WidgetValue.
* @returns True if both values are equal, false otherwise.
*/
export function equalsCriteria(v1, v2) {
const type1 = getCriteriaType(v1);
const type2 = getCriteriaType(v2);
if (type1 !== type2)
return false;
switch (type1) {
case CriteriaType.RdfTermCriteria:
return sameTerm(v1.rdfTerm, v2.rdfTerm);
case CriteriaType.DateCriteria: {
const d1 = v1;
const d2 = v2;
return d1.start === d2.start && d1.stop === d2.stop;
}
case CriteriaType.BooleanCriteria:
return v1.boolean === v2.boolean;
case CriteriaType.MapCriteria: {
const m1 = v1;
const m2 = v2;
if (m1.coordType !== m2.coordType)
return false;
if (m1.coordinates.length !== m2.coordinates.length)
return false;
for (let i = 0; i < m1.coordinates.length; i++) {
const arr1 = m1.coordinates[i];
const arr2 = m2.coordinates[i];
if (arr1.length !== arr2.length)
return false;
for (let j = 0; j < arr1.length; j++) {
const c1 = arr1[j];
const c2 = arr2[j];
if (c1.lat !== c2.lat ||
c1.lng !== c2.lng ||
c1.alt !== c2.alt) {
return false;
}
}
}
return true;
}
case CriteriaType.NumberCriteria: {
const n1 = v1;
const n2 = v2;
return n1.min === n2.min && n1.max === n2.max;
}
case CriteriaType.SearchCriteria:
return v1.search === v2.search;
default:
return false;
}
}
//# sourceMappingURL=SparnaturalQueryIfc.js.map