Skip to content

Commit

Permalink
Update (#56)
Browse files Browse the repository at this point in the history
* Updated configs

Updated the configs to work with the lastest version of the Core LDWizard software (see PLDN repo).

* Updated to latest core and TN rewrite

* Activated error logging
  • Loading branch information
EnnoMeijers authored Dec 5, 2023
1 parent dd97289 commit a6d9613
Show file tree
Hide file tree
Showing 12 changed files with 5,257 additions and 8,768 deletions.
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-engines true
70 changes: 53 additions & 17 deletions config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import WizardConfig, { PrefixEntry } from "@pldn/ldwizard/types/WizardConfig";
import TermennetwerkTransformationAAT from "./termennetwerkTransformationAAT";
import TermennetwerkTransformationCHT from "./termennetwerkTransformationCHT";
import TermennetwerkTransformationWDPersons from "./termennetwerkTransformationWDPersons";
import TermennetwerkTransformationWDPlaces from "./termennetwerkTransformationWDPlaces";
const img = require("./ndelogo.png").default;
// const favIcon = require("./logo.png").default;
const homePage = require("./homePage.md");
import WizardConfig, { ColumnRefinement, PrefixEntry } from "@pldn/ldwizard/types/WizardConfig";
import { getUriOfSearchTerm, getRefinementList } from "./termennetwerk";

// @ts-ignore
import img from "./ndelogo.png";

// @ts-ignore
import favIcon from "./favicon.png";

// @ts-ignore
import homePage from "./homePage.md";

var sourceList=await getRefinementList();

const refinements:ColumnRefinement[] = [
{
label: "Verwerk als URI/IRI",
type: "single",
description:
"In this transformation the returned value should be an IRI, this can be applied to the 'IRIs' column in the example.csv file",
transformation: async (term: string) => {
return `${term}`;
},
yieldsIri: true,
keepOriginalValue: {
keepValue: false,
},
},
/*
{
label: "Termennetwerk - Concepten",
type:"single",
description:
"Deze transformatie gebruikt het Termennetwerk om waardes in deze kolom te vervangen door de AAT-URIs van deze termen mits exact gematched. Zie de 'enriched csv' voor de details van deze matching. Voer de definitieve conversie hierop uit na controle van de matches.",
transformation: async (searchTerm: string) => {
const sources = [
"http://vocab.getty.edu/aat/sparql",
"https://data.cultureelerfgoed.nl/PoolParty/sparql/term/id/cht",
];
return getUriOfSearchTerm(sources, searchTerm);
},
yieldsIri: true
},
*/
];

const list = refinements.concat(sourceList);

const wizardConfig: WizardConfig = {
appName: "LDWizard - Erfgoed",
Expand All @@ -15,7 +54,9 @@ const wizardConfig: WizardConfig = {
homepageMarkdown: homePage,
publishOrder: ["download"],
icon: img,
//favIcon: favIcon,
favIcon: favIcon,
classConfig: { method:"elastic", endpoint: "https://api.data.netwerkdigitaalerfgoed.nl/datasets/NDE/ldwizard/services/ldwizard/_search" },
predicateConfig: { method:"elastic", endpoint: "https://api.data.netwerkdigitaalerfgoed.nl/datasets/NDE/ldwizard/services/ldwizard/_search" },
dataplatformLink: "https://data.netwerkdigitaalerfgoed.nl/",
repositoryLink: "https://github.com/netwerk-digitaal-erfgoed/LDWizard-ErfgoedWizard",
getAllowedPrefixes: async () => {
Expand All @@ -27,11 +68,6 @@ const wizardConfig: WizardConfig = {
console.error("Prefixes retrieval failed")
return [];
},
columnRefinements: [
TermennetwerkTransformationAAT,
TermennetwerkTransformationCHT,
TermennetwerkTransformationWDPersons,
TermennetwerkTransformationWDPlaces,
],
};
export default wizardConfig;
columnRefinements: list
}
export default globalThis.wizardConfig = wizardConfig;
20 changes: 16 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
FROM node:14-alpine as build
RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python3
FROM node:18-alpine as build

RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python3 git
RUN npm install --quiet node-gyp -g
WORKDIR /app

COPY package.json ./
COPY yarn.lock ./
RUN yarn
COPY .yarn ./app/
COPY .yarnrc ./app/
RUN yarn

COPY . .
RUN yarn build

ARG CONFIG_FILE
RUN yarn exec ldwizard-build ${CONFIG_FILE}
# RUN yarn add "@pldn/ldwizard"
RUN yarn ldwizard-build ${CONFIG_FILE}


FROM nginx:stable-alpine

COPY --from=build /app/lib /usr/share/nginx/html
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Binary file removed favicon.ico
Binary file not shown.
Binary file added favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/netwerk-digitaal-erfgoed/LDWizard-ErfgoedWizard#readme",
"dependencies": {
"@pldn/ldwizard": "^1.1.3",
"@pldn/ldwizard": "^3.0.7",
"graphql": "^15.5.0",
"graphql-request": "^3.4.0"
}
Expand Down
136 changes: 107 additions & 29 deletions termennetwerk.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import { GraphQLClient, gql } from "graphql-request";
import { ColumnRefinement } from "@pldn/ldwizard/types/WizardConfig";

const endpoint = "https://termennetwerk-api.netwerkdigitaalerfgoed.nl/graphql";

interface GraphQlResponse {
interface Term {
uri: string;
prefLabel: string[];
altLabel: string[];
}

interface Result {
__typename: string;
terms: Term[];
message: string;
};

interface TermsResponse {
terms: {
source: {
name: string;
};
result: {
__typename: string;
terms: {
uri: string;
prefLabel: string[];
altLabel: string[];
}[];
message: string;
};
result: Result;
}[];
}
const graphQlQuery = gql`

interface SourcesResponse {
sources: {
uri: string,
name: string,
description: string
}[];
}

const queryTerms = gql`
query Terms($sources: [ID]! $query: String!) {
terms(
sources: $sources
Expand All @@ -45,29 +59,93 @@ const graphQlQuery = gql`
}
`;

const querySources = gql`
query Sources {
sources {
uri
name
}
}
`;

const cache: { [query: string]: string } = {};

const client = new GraphQLClient(endpoint);

export async function getUriOfSearchTerm(sources: string[], searchTerm: string): Promise<string> {
if (searchTerm === "") return undefined;
const cacheKey = searchTerm.toLowerCase();
if (cache[cacheKey]) return cache[cacheKey];
const response: GraphQlResponse = await client.request(graphQlQuery, { sources, query: searchTerm });
const result = response.terms[0].result;
// if (!Array.isArray(result.terms) ||
function selectTerm(result: Result, searchTerm: string, source: string): Term | undefined {

if (result.__typename === 'ServerError') { // catch server errors
console.log("Termennetwerk refinement: server error for source",source);
return undefined;
}

if (result.__typename === 'TimeoutError') { // catch timeouts errors
console.error(`Timeout error from Network-of-Terms API: "${result.message}" for keyword: "${searchTerm}"`);
console.log("Termennetwerk refinement: time out for source", source);
return undefined;
}
if (result.terms.length !== 1 ) return undefined; // allow only a single result

const term = response.terms[0].result.terms[0];
const containsSearchTerm = (label: string) => label.toLowerCase() === searchTerm.toLowerCase();
const inPrefLabel = term.prefLabel.some(containsSearchTerm); // exact match for prefLabel?
const inAltLabel = term.altLabel.some(containsSearchTerm); // exact match for altLabel?
if (!inPrefLabel && !inAltLabel ) return undefined; // no matches found

cache[cacheKey] = term.uri;
return term.uri;

if (result.terms.length === 0 ) { // no results found
//console.log("Termennetwerk refinement: no results for",searchTerm,"in",source);
return undefined;
}

var countMatches = 0;
var matchedTerm:Term = <Term>{};
for( const nr in result.terms ) {
const term = result.terms[nr];
const containsSearchTerm = (label: string) => label.toLowerCase() === searchTerm.toLowerCase();
const inPrefLabel = term.prefLabel.some(containsSearchTerm); // exact match for prefLabel?
const inAltLabel = term.altLabel.some(containsSearchTerm); // exact match for altLabel?
if ( inPrefLabel || inAltLabel ) {
countMatches=+1;
matchedTerm=term;
}
}
if(countMatches==1){
//console.log("Termennetwerk refinement: found single exact match for",searchTerm,"in",source);
return matchedTerm;
}
else {
//console.log("Termennetwerk refinement: no single exact match found for",searchTerm,"in",source);
return undefined; // no matches found
}
}

export async function getUriOfSearchTerm(sources: string[], searchTerm: string): Promise<string | undefined> {
if (searchTerm.trim() === "") return undefined;
const cacheKey = searchTerm.toLowerCase();
if (cache[cacheKey]) return cache[cacheKey];
const response: TermsResponse = await client.request(queryTerms, { sources, query: searchTerm });
for( const term in response){
for( const sourcenr in response[term]) {
const source = response[term][sourcenr].source.name;
const result = response[term][sourcenr].result;
const selectedTerm = selectTerm(result, searchTerm, source);
if( selectedTerm ) {
cache[cacheKey] = selectedTerm.uri;
return selectedTerm.uri;
}
}
}
return undefined;
}

export async function getRefinementList():Promise<ColumnRefinement[]> {
const response: SourcesResponse = await client.request(querySources);
var refinementList: ColumnRefinement[] = [];
for( const sourcenr in response.sources ){
//console.log("Source loop index",sourcenr);
const refinement:ColumnRefinement = {
label: "Termennetwerk: "+response.sources[sourcenr].name,
type: "single",
description: response.sources[sourcenr].description,
transformation: async (searchTerm: string) => {
const sources = [response.sources[sourcenr].uri];
return getUriOfSearchTerm(sources, searchTerm);
},
yieldsIri: true
}
refinementList.push(refinement)
}
return refinementList;
}
14 changes: 0 additions & 14 deletions termennetwerkTransformationAAT.ts

This file was deleted.

14 changes: 0 additions & 14 deletions termennetwerkTransformationCHT.ts

This file was deleted.

14 changes: 0 additions & 14 deletions termennetwerkTransformationWDPersons.ts

This file was deleted.

14 changes: 0 additions & 14 deletions termennetwerkTransformationWDPlaces.ts

This file was deleted.

Loading

0 comments on commit a6d9613

Please sign in to comment.