Skip to content

Commit

Permalink
feat: Analyze vocabularies
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Dec 7, 2023
1 parent 2dc8fcc commit de3c3d4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
10 changes: 5 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
preset: 'ts-jest/presets/default-esm',
extensionsToTreatAsEsm: ['.ts'],
testTimeout: 10000,
testTimeout: 20000,
collectCoverage: true,
collectCoverageFrom: [
'**/src/**/*.ts', // Include files that are not covered by tests.
Expand All @@ -10,10 +10,10 @@ export default {
coverageReporters: ['json-summary', 'text'],
coverageThreshold: {
global: {
lines: 20.19,
statements: 20.19,
branches: 15.23,
functions: 17.39,
lines: 18.89,
statements: 18.89,
branches: 14.54,
functions: 16.32,
},
},
transform: {
Expand Down
54 changes: 54 additions & 0 deletions src/analyzer/vocabulary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {Analyzer} from '../analyzer.js';
import {Dataset} from '../dataset.js';
import {DataFactory} from 'n3';
import {Failure, NotSupported, Success} from '../pipeline.js';
import namedNode = DataFactory.namedNode;

const vocabularyPrefixes = new Map([
['http://schema.org/', 'http://schema.org'],
['https://schema.org/', 'http://schema.org'],
[
'https://www.ica.org/standards/RiC/ontology#',
'https://www.ica.org/standards/RiC/ontology',
],
['http://www.cidoc-crm.org/cidoc-crm/', 'http://www.cidoc-crm.org/cidoc-crm'],
['http://purl.org/ontology/bibo/', 'http://purl.org/ontology/bibo/'],
['http://purl.org/dc/elements/1.1/', 'http://purl.org/dc/elements/1.1/'],
['http://purl.org/dc/terms/', 'http://purl.org/dc/terms/'],
['http://purl.org/dc/dcmitype/', 'http://purl.org/dc/dcmitype/'],
[
'http://www.w3.org/2004/02/skos/core#',
'http://www.w3.org/2004/02/skos/core#',
],
]);

export class VocabularyAnalyzer implements Analyzer {
constructor(private readonly decorated: Analyzer) {}

async execute(dataset: Dataset): Promise<Success | NotSupported | Failure> {
const result = await this.decorated.execute(dataset);
if (result instanceof NotSupported || result instanceof Failure) {
return result;
}

for (const quad of result.data) {
if ('http://rdfs.org/ns/void#property' === quad.predicate.value) {
const match = [...vocabularyPrefixes].find(([prefix]) =>
quad.object.value.startsWith(prefix)
);
if (match) {
const [, vocabulary] = match;
result.data.add(
DataFactory.quad(
namedNode(dataset.iri),
namedNode('http://rdfs.org/ns/void#vocabulary'),
namedNode(vocabulary)
)
);
}
}
}

return new Success(result.data);
}
}
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {SparqlWriter} from './writer/sparql.js';
import {config} from './config.js';
import {RdfDumpImporter} from './importer.js';
import {GraphDBClient} from './graphdb.js';
import {VocabularyAnalyzer} from './analyzer/vocabulary.js';

const queryEngine = new QueryEngine();
new Pipeline({
Expand All @@ -37,7 +38,6 @@ new Pipeline({
})
),
await SparqlQueryAnalyzer.fromFile(queryEngine, 'class-partition.rq'),
await SparqlQueryAnalyzer.fromFile(queryEngine, 'entity-properties.rq'),
await SparqlQueryAnalyzer.fromFile(queryEngine, 'object-literals.rq'),
await SparqlQueryAnalyzer.fromFile(queryEngine, 'object-uris.rq'),
await SparqlQueryAnalyzer.fromFile(queryEngine, 'properties.rq'),
Expand All @@ -47,6 +47,9 @@ new Pipeline({
new UriSpaceAnalyzer(
await SparqlQueryAnalyzer.fromFile(queryEngine, 'object-uri-space.rq')
),
new VocabularyAnalyzer(
await SparqlQueryAnalyzer.fromFile(queryEngine, 'entity-properties.rq')
),
],
writers: [
new FileWriter(),
Expand Down

0 comments on commit de3c3d4

Please sign in to comment.