sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
48 lines • 2.24 kB
JavaScript
import { DataFactory } from 'rdf-data-factory';
import { OWLSpecificationProvider } from "./owl//OWLSpecificationProvider";
import { SHACLSpecificationProvider } from './shacl/SHACLSpecificationProvider';
import { RDF, RdfStoreReader, SH } from 'rdf-shacl-commons';
let DF = new DataFactory();
export class SparnaturalSpecificationFactory {
build(cfg, language, catalog, callback) {
if (cfg.includes("@prefix") || cfg.includes("<http")) {
// inline Turtle
RdfStoreReader.buildStoreFromString(cfg, "https://sparnatural.eu", (theStore) => {
if (theStore.asDataset().has(DF.quad(null, RDF.TYPE, SH.NODE_SHAPE, null))) {
let provider = new SHACLSpecificationProvider(theStore, language);
callback(provider);
}
else {
let provider = new OWLSpecificationProvider(theStore, language);
callback(provider);
}
});
}
else {
// split on whitespace and load all files
let configs = cfg.split(/\s+/).filter((e) => e.length > 0);
console.log("Configuring from " + configs.length + " configs");
if (catalog) {
// also add all statistics files of selected endpoints
// note that endpoint filtering happened before
catalog.getServices().forEach(s => {
if (s.getExtent()) {
configs.push(s.getExtent());
console.log("Adding a statistics file to store : " + s.getExtent());
}
});
}
RdfStoreReader.buildStore(configs, (theStore) => {
if (theStore.asDataset().has(DF.quad(null, RDF.TYPE, SH.NODE_SHAPE, null))) {
let provider = new SHACLSpecificationProvider(theStore, language);
callback(provider);
}
else {
let provider = new OWLSpecificationProvider(theStore, language);
callback(provider);
}
});
}
}
}
//# sourceMappingURL=SparnaturalSpecificationFactory.js.map