Skip to content

Commit

Permalink
feat: Identity datasets by their URI
Browse files Browse the repository at this point in the history
BREAKING CHANGE: terminology sources are no longer identifier by their
distribution URI. Keep BC by still allowing the distribution URI to be
used when searching. However, the sources query now returns source
instead of distribution URIs.
  • Loading branch information
ddeboer committed Sep 17, 2024
1 parent dda4951 commit b2ffd74
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default {
],
coverageThreshold: {
global: {
lines: 91.37,
statements: 91.37,
branches: 95.08,
functions: 92.56,
lines: 91.39,
statements: 91.39,
branches: 95.45,
functions: 92.62,
},
},
transform: {
Expand Down
4 changes: 2 additions & 2 deletions packages/network-of-terms-graphql/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function queryTerms(object: any, args: any, context: any): Promise<any> {
});
const results = await service.queryAll({
sources: args.sources.map(

Check failure on line 42 in packages/network-of-terms-graphql/src/resolvers.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎······(datasetIri:·string)·=>·new·IRI(datasetIri)⏎····` with `(datasetIri:·string)·=>·new·IRI(datasetIri)`
(distributionIri: string) => new IRI(distributionIri)
(datasetIri: string) => new IRI(datasetIri)
),
query: args.query,
queryMode: QueryMode[args.queryMode as keyof typeof QueryMode],
Expand Down Expand Up @@ -141,7 +141,7 @@ function term(term: Term) {

async function source(distribution: Distribution, dataset: Dataset) {
return {
uri: distribution.iri,
uri: dataset.iri,
name: dataset.name,
alternateName: dataset.alternateName,
description: dataset.description,
Expand Down
51 changes: 50 additions & 1 deletion packages/network-of-terms-graphql/test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Server', () => {
);
expect(body.data.sources).toHaveLength(catalog.datasets.length);
expect(body.data.sources[0].uri).toEqual(

Check failure on line 48 in packages/network-of-terms-graphql/test/server.test.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎······'https://data.rkd.nl/rkdartists'⏎····` with `'https://data.rkd.nl/rkdartists'`
'https://data.netwerkdigitaalerfgoed.nl/rkd/rkdartists/sparql'
'https://data.rkd.nl/rkdartists'
);
expect(body.data.sources[0].mainEntityOfPage).toEqual([
'https://example.com/rkdartists',
Expand Down Expand Up @@ -92,6 +92,53 @@ describe('Server', () => {
});

it('responds to successful GraphQL terms query', async () => {
const body = await query(
termsQuery(

Check failure on line 96 in packages/network-of-terms-graphql/test/server.test.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎········['https://data.rkd.nl/rkdartists'],⏎········'.*'⏎······` with `['https://data.rkd.nl/rkdartists'],·'.*'`
['https://data.rkd.nl/rkdartists'],
'.*'
)
);
expect(body.data.terms).toHaveLength(1); // Source.
expect(body.data.terms[0].source.name).toEqual('RKDartists');
expect(body.data.terms[0].source.uri).toEqual('https://data.rkd.nl/rkdartists');

Check failure on line 103 in packages/network-of-terms-graphql/test/server.test.ts

View workflow job for this annotation

GitHub Actions / test

Replace `'https://data.rkd.nl/rkdartists'` with `⏎······'https://data.rkd.nl/rkdartists'⏎····`
expect(body.data.terms[0].source.inLanguage).toEqual(['nl']);
expect(body.data.terms[0].result.__typename).toEqual('Terms');
expect(body.data.terms[0].result.terms).toHaveLength(5); // Terms found.
expect(body.data.terms[0].responseTimeMs).toBeGreaterThan(0);

const artwork = body.data.terms[0].result.terms.find(
(term: {uri: string}) =>
term.uri === 'https://example.com/resources/artwork'
);
expect(artwork.seeAlso).toEqual(['https://example.com/html/artwork']);
expect(artwork.description).toEqual([
'One of the most famous Dutch paintings',
]);
expect(artwork.exactMatch).toEqual([
{
prefLabel: ['Exact match'],
uri: 'https://example.com/resources/match',
},
]);

const prefLabels = body.data.terms[0].result.terms.map(
({prefLabel}: {prefLabel: string[]}) => prefLabel[0] ?? ''
);
expect(prefLabels).toEqual([
'Rembrandt',
'Nachtwacht',
'All things art',
'',
'',
]); // Results with score must come first.

const relatedPrefLabels = artwork.related.map(
({prefLabel}: {prefLabel: string[]}) => prefLabel[0] ?? ''
);
expect(relatedPrefLabels).toEqual(['', 'All things art', 'Rembrandt']); // Sorted alphabetically.
});

it('responds to successful GraphQL terms query with backwards compatible distribution URI', async () => {
const body = await query(
termsQuery(
['https://data.netwerkdigitaalerfgoed.nl/rkd/rkdartists/sparql'],
Expand All @@ -100,6 +147,7 @@ describe('Server', () => {
);
expect(body.data.terms).toHaveLength(1); // Source.
expect(body.data.terms[0].source.name).toEqual('RKDartists');
expect(body.data.terms[0].source.uri).toEqual('https://data.rkd.nl/rkdartists');

Check failure on line 150 in packages/network-of-terms-graphql/test/server.test.ts

View workflow job for this annotation

GitHub Actions / test

Replace `'https://data.rkd.nl/rkdartists'` with `⏎······'https://data.rkd.nl/rkdartists'⏎····`
expect(body.data.terms[0].source.inLanguage).toEqual(['nl']);
expect(body.data.terms[0].result.__typename).toEqual('Terms');
expect(body.data.terms[0].result.terms).toHaveLength(5); // Terms found.
Expand Down Expand Up @@ -151,6 +199,7 @@ describe('Server', () => {
const term = body.data.lookup[0];
expect(term.uri).toEqual('https://example.com/resources/art');
expect(term.source.name).toEqual('RKDartists');
expect(term.source.uri).toEqual('https://data.rkd.nl/rkdartists');
expect(term.result.__typename).toEqual('Term');
expect(term.result.uri).toEqual('https://example.com/resources/art');
expect(term.responseTimeMs).toBeGreaterThan(0);
Expand Down
4 changes: 4 additions & 0 deletions packages/network-of-terms-query/src/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class Dataset {
readonly alternateName?: string
) {}

public getSparqlDistributions(): Distribution | undefined {
return this.distributions.find(distribution => distribution instanceof SparqlDistribution);

Check failure on line 55 in packages/network-of-terms-query/src/catalog.ts

View workflow job for this annotation

GitHub Actions / test

Replace `distribution·=>·distribution·instanceof·SparqlDistribution` with `⏎······distribution·=>·distribution·instanceof·SparqlDistribution⏎····`
}

public getDistributionByIri(iri: IRI): Distribution | undefined {
return this.distributions.find(
distribution => distribution.iri.toString() === iri.toString()
Expand Down
4 changes: 2 additions & 2 deletions packages/network-of-terms-query/src/distributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export class DistributionsService {
async query(options: QueryOptions): Promise<TermsResponse> {
const args = Joi.attempt(options, schemaQuery);
this.logger.info(`Preparing to query source "${args.source}"...`);
const dataset = await this.catalog.getDatasetByDistributionIri(args.source);
const dataset = this.catalog.getDatasetByIri(args.source) ?? this.catalog.getDatasetByDistributionIri(args.source);

Check failure on line 56 in packages/network-of-terms-query/src/distributions.ts

View workflow job for this annotation

GitHub Actions / test

Replace `·this.catalog.getDatasetByIri(args.source)·??` with `⏎······this.catalog.getDatasetByIri(args.source)·??⏎·····`
if (dataset === undefined) {
throw Error(`Source with URI "${args.source}" not found`);
}
const distribution = dataset.getDistributionByIri(args.source)!;
const distribution = dataset.getSparqlDistributions()!;
const queryService = new QueryTermsService({
logger: this.logger,
comunica: this.comunica,
Expand Down

0 comments on commit b2ffd74

Please sign in to comment.