sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
49 lines • 2.28 kB
JavaScript
import { DataFactory } from 'rdf-data-factory';
import { BaseRDFReader, RDF } from "./BaseRDFReader";
import { OWLSpecificationProvider } from "./owl//OWLSpecificationProvider";
import { SH } from '../../rdf/vocabularies/SH';
import { SHACLSpecificationProvider } from './shacl/SHACLSpecificationProvider';
let DF = new DataFactory();
export class SparnaturalSpecificationFactory {
build(cfg, language, catalog, callback) {
if (cfg.includes("@prefix") || cfg.includes("<http")) {
// inline Turtle
BaseRDFReader.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());
}
});
}
BaseRDFReader.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