UNPKG

sparnatural

Version:

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

78 lines 2.49 kB
import { BaseRDFReader } from "../BaseRDFReader"; import { DataFactory } from 'rdf-data-factory'; import { VOLIPI } from "../../../rdf/vocabularies/VOLIPI"; import { SH } from "../../../rdf/vocabularies/SH"; const factory = new DataFactory(); export class SHACLSpecificationEntry extends BaseRDFReader { constructor(uri, provider, n3store, lang) { super(n3store, lang); this.uri = uri; this.provider = provider; } getId() { return this.uri; } getColor() { return this.graph.readSingleProperty(factory.namedNode(this.uri), VOLIPI.COLOR)?.value; } getIcon() { var faIcon = this.graph.readProperty(factory.namedNode(this.uri), VOLIPI.ICON_NAME); if (faIcon.length > 0) { return faIcon[0].value; } else { var icons = this.graph.readProperty(factory.namedNode(this.uri), VOLIPI.ICON); if (icons.length > 0) { return icons[0].value; } } } /** * @returns always return an empty icon. TODO : implement */ getHighlightedIcon() { return ""; } getOrder() { let order = this.graph.readSingleProperty(factory.namedNode(this.uri), SH.ORDER)?.value; return order; } static sort(items) { // sort according to order or label items.sort(SHACLSpecificationEntry.compare); return items; } static compare(item1, item2) { var order1 = item1.getOrder(); var order2 = item2.getOrder(); if (order1) { if (order2) { if (order1 == order2) { return item1.getLabel().localeCompare(item2.getLabel()); } else { // if the order is actually a number, convert it to number and use a number conversion if (!isNaN(Number(order1)) && !isNaN(Number(order2))) { return Number(order1) - Number(order2); } else { return (order1 > order2) ? 1 : -1; } } } else { return -1; } } else { if (order2) { return 1; } else { return item1.getLabel().localeCompare(item2.getLabel()); } } } ; } //# sourceMappingURL=SHACLSpecificationEntry.js.map