Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Identify datasets by their URI #1426

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4,
statements: 91.4,
branches: 95.45,
functions: 92.62,
},
},
transform: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": "https://schema.org/docs/jsonldcontext.jsonld",
"@id": "http://vocab.getty.edu/aat/materials",
"@id": "http://vocab.getty.edu/aat#materials",
"@type": "Dataset",
"name": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": "https://schema.org/docs/jsonldcontext.jsonld",
"@id": "http://vocab.getty.edu/aat/processes-and-techniques",
"@id": "http://vocab.getty.edu/aat#processes-and-techniques",
"@type": "Dataset",
"name": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": "https://schema.org/docs/jsonldcontext.jsonld",
"@id": "http://vocab.getty.edu/aat/styles-and-periods",
"@id": "http://vocab.getty.edu/aat#styles-and-periods",
"@type": "Dataset",
"name": [
{
Expand All @@ -20,7 +20,7 @@
},
{
"@id": "https://data.cultureelerfgoed.nl/termennetwerk/onderwerpen/Stijlen"
}
}
],
"creator": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": "https://schema.org/docs/jsonldcontext.jsonld",
"@id": "https://data.cultureelerfgoed.nl/term/id/cht/materials",
"@id": "https://data.cultureelerfgoed.nl/term/id/cht#materials",
"@type": "Dataset",
"name": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@context": "https://schema.org/docs/jsonldcontext.jsonld",
"@id": "https://data.cultureelerfgoed.nl/term/id/cht/styles-and-periodes",
"@id": "https://data.cultureelerfgoed.nl/term/id/cht#styles-and-periodes",
"@type": "Dataset",
"name": [
{
Expand Down
6 changes: 2 additions & 4 deletions packages/network-of-terms-graphql/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ async function queryTerms(object: any, args: any, context: any): Promise<any> {
comunica: context.comunica,
});
const results = await service.queryAll({
sources: args.sources.map(
(distributionIri: string) => new IRI(distributionIri)
),
sources: args.sources.map((datasetIri: string) => new IRI(datasetIri)),
query: args.query,
queryMode: QueryMode[args.queryMode as keyof typeof QueryMode],
timeoutMs: args.timeoutMs,
Expand Down Expand Up @@ -141,7 +139,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
27 changes: 20 additions & 7 deletions packages/network-of-terms-graphql/test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ describe('Server', () => {
`
);
expect(body.data.sources).toHaveLength(catalog.datasets.length);
expect(body.data.sources[0].uri).toEqual(
'https://data.netwerkdigitaalerfgoed.nl/rkd/rkdartists/sparql'
);
expect(body.data.sources[0].uri).toEqual('https://data.rkd.nl/rkdartists');
expect(body.data.sources[0].mainEntityOfPage).toEqual([
'https://example.com/rkdartists',
]);
Expand Down Expand Up @@ -93,13 +91,13 @@ describe('Server', () => {

it('responds to successful GraphQL terms query', async () => {
const body = await query(
termsQuery(
['https://data.netwerkdigitaalerfgoed.nl/rkd/rkdartists/sparql'],
'.*'
)
termsQuery(['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'
);
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 @@ -137,6 +135,20 @@ describe('Server', () => {
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'],
'.*'
)
);
expect(body.data.terms).toHaveLength(1); // Source.
expect(body.data.terms[0].source.uri).toEqual(
'https://data.rkd.nl/rkdartists'
);
expect(body.data.terms[0].result.terms).toHaveLength(5); // Terms found.
});

it('responds to GraphQL lookup query', async () => {
const body = await query(
lookupQuery(
Expand All @@ -151,6 +163,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
6 changes: 6 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,12 @@ export class Dataset {
readonly alternateName?: string
) {}

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

public getDistributionByIri(iri: IRI): Distribution | undefined {
return this.distributions.find(
distribution => distribution.iri.toString() === iri.toString()
Expand Down
6 changes: 4 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,13 @@ 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);
if (dataset === undefined) {
throw Error(`Source with URI "${args.source}" not found`);
}
const distribution = dataset.getDistributionByIri(args.source)!;
const distribution = dataset.getSparqlDistribution()!;
const queryService = new QueryTermsService({
logger: this.logger,
comunica: this.comunica,
Expand Down