Skip to content

Commit

Permalink
Merge pull request #244 from colonial-heritage/maintenance-dataset-br…
Browse files Browse the repository at this point in the history
…owser

dataset browser maintenance
  • Loading branch information
sdevalk authored Sep 20, 2023
2 parents 3bd610c + c85c3ab commit fe317c5
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 473 deletions.
4 changes: 2 additions & 2 deletions apps/dataset-browser/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# DO NOT ADD SECRETS TO THIS FILE
# If you want to add secrets use `.env.development.local` instead

SEARCH_PLATFORM_ELASTIC_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/testing/dataset-search-v2/services/dataset-search-v2-es/elasticsearch
SEARCH_PLATFORM_SPARQL_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/testing/dataset-search-v2/services/dataset-search-v2-sparql/sparql
SEARCH_PLATFORM_ELASTIC_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/data-hub-testing/search-graph/services/search/elasticsearch
SEARCH_PLATFORM_SPARQL_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/data-hub-testing/knowledge-graph/services/kg/sparql
4 changes: 2 additions & 2 deletions apps/dataset-browser/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# DO NOT ADD SECRETS TO THIS FILE
# If you want to add secrets use `.env.test.local` instead

SEARCH_PLATFORM_ELASTIC_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/testing/dataset-search-v2/services/dataset-search-v2-es/elasticsearch
SEARCH_PLATFORM_SPARQL_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/testing/dataset-search-v2/services/dataset-search-v2-sparql/sparql
SEARCH_PLATFORM_ELASTIC_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/data-hub-testing/search-graph/services/search/elasticsearch
SEARCH_PLATFORM_SPARQL_ENDPOINT_URL=https://api.colonial-heritage.triply.cc/datasets/data-hub-testing/knowledge-graph/services/kg/sparql
34 changes: 24 additions & 10 deletions apps/dataset-browser/src/lib/datasets/enricher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Dataset, Measurement} from '.';
import {isIri} from '@colonial-collections/iris';
import {SparqlEndpointFetcher} from 'fetch-sparql-endpoint';
import {EOL} from 'node:os';
import type {Readable} from 'node:stream';
import {lru, LRU} from 'tiny-lru';
import type {Stream} from '@rdfjs/types';
Expand Down Expand Up @@ -60,11 +61,15 @@ export class DatasetEnricher {
return; // No IRIs to fetch
}

const irisForValues = iris.map(iri => `<${iri}>`).join(' ');
const irisForValues = iris.map(iri => `<${iri}>`).join(EOL);

// Query can be expanded to also include other properties
const query = `
PREFIX cc: <https://colonialcollections.nl/search#>
PREFIX cc: <https://colonialcollections.nl/schema#>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX dqv: <http://www.w3.org/ns/dqv#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
CONSTRUCT {
?iri cc:measurement ?measurement .
Expand All @@ -74,13 +79,22 @@ export class DatasetEnricher {
cc:order ?order .
}
WHERE {
VALUES ?iri { ${irisForValues} }
?iri a cc:Dataset ;
cc:measurement ?measurement .
?measurement cc:value ?value ;
cc:measurementOf ?metric .
?metric cc:name ?name ;
cc:order ?order .
VALUES ?iri {
${irisForValues}
}
?iri a dcat:Dataset .
{
?iri dqv:hasQualityMeasurement ?measurement .
}
UNION {
?iri dcat:distribution/dqv:hasQualityMeasurement ?measurement .
}
?measurement dqv:value ?value ;
dqv:isMeasurementOf ?metric .
?metric skos:prefLabel ?name ;
qb:order ?order .
}
`;

Expand Down Expand Up @@ -125,7 +139,7 @@ export class DatasetEnricher {
private async processResponse(iris: string[], stream: Readable & Stream) {
const loader = new RdfObjectLoader({
context: {
cc: 'https://colonialcollections.nl/search#',
cc: 'https://colonialcollections.nl/schema#',
},
});

Expand Down
22 changes: 7 additions & 15 deletions apps/dataset-browser/src/lib/datasets/fetcher-result.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import type {RawBucket, SearchResultFilter} from '.';
import type {LabelFetcher} from '@colonial-collections/label-fetcher';

function toUnmatchedFilter(
bucket: RawBucket,
labelFetcher: LabelFetcher
): SearchResultFilter {
function toUnmatchedFilter(bucket: RawBucket): SearchResultFilter {
const totalCount = 0; // Initial count; will be overridden by the matching filter, if any
const id = bucket.key;
const name = labelFetcher.getByIri({iri: id});
const name = bucket.key;

return {totalCount, id, name};
}

function toMatchedFilter(
bucket: RawBucket,
labelFetcher: LabelFetcher
): SearchResultFilter {
function toMatchedFilter(bucket: RawBucket): SearchResultFilter {
const totalCount = bucket.doc_count; // Actual count if a filter matched the query
const id = bucket.key;
const name = labelFetcher.getByIri({iri: id});
const name = bucket.key;

return {totalCount, id, name};
}
Expand All @@ -39,14 +32,13 @@ function combineUnmatchedWithMatchedFilters(

export function buildFilters(
rawUnmatchedFilters: RawBucket[],
rawMatchedFilters: RawBucket[],
labelFetcher: LabelFetcher
rawMatchedFilters: RawBucket[]
) {
const unmatchedFilters = rawUnmatchedFilters.map(rawUnmatchedFilter => {
return toUnmatchedFilter(rawUnmatchedFilter, labelFetcher);
return toUnmatchedFilter(rawUnmatchedFilter);
});
const matchedFilters = rawMatchedFilters.map(rawMatchedFilter => {
return toMatchedFilter(rawMatchedFilter, labelFetcher);
return toMatchedFilter(rawMatchedFilter);
});
const combinedFilters = combineUnmatchedWithMatchedFilters(
unmatchedFilters,
Expand Down
Loading

2 comments on commit fe317c5

@vercel
Copy link

@vercel vercel bot commented on fe317c5 Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on fe317c5 Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.