Skip to content

Commit

Permalink
#202 : save identifiers and expose it on API
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermau committed Feb 10, 2025
1 parent 57f7cdb commit 35a05f0
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const createPgSoftwareExternalDataRepository = (db: Kysely<Database>): So
applicationCategories: JSON.stringify(softwareExternalData.applicationCategories),
programmingLanguages: JSON.stringify(softwareExternalData.programmingLanguages),
referencePublication: JSON.stringify(softwareExternalData.referencePublication),
identifiers: JSON.stringify(softwareExternalData.identifiers),
description: JSON.stringify(softwareExternalData.description)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
keywords: software?.keywords ?? softwareExternalData?.keywords ?? [],
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
referencePublication: softwareExternalData?.referencePublication,
identifiers: softwareExternalData?.identifiers,
applicationCategories: software.categories.concat(
softwareExternalData?.applicationCategories ?? []
),
Expand Down Expand Up @@ -298,7 +299,8 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
),
categories: undefined, // merged in applicationCategories, set to undefined to remove it
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
referencePublication: softwareExternalData?.referencePublication
referencePublication: softwareExternalData?.referencePublication,
identifiers: softwareExternalData?.identifiers
});
}
);
Expand Down Expand Up @@ -434,6 +436,7 @@ const makeGetSoftwareBuilder = (db: Kysely<Database>) =>
programmingLanguages: ref("ext.programmingLanguages"),
applicationCategories: ref("ext.applicationCategories"),
referencePublication: ref("ext.referencePublication"),
identifiers: ref("ext.identifiers"),
keywords: ref("ext.keywords"),
softwareVersion: ref("ext.softwareVersion"),
publicationTime: ref("ext.publicationTime")
Expand Down Expand Up @@ -569,6 +572,7 @@ const makeGetSoftwareById =
parentWikidataSoftware: parentExternalData,
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
referencePublication: softwareExternalData?.referencePublication,
identifiers: softwareExternalData?.identifiers,
applicationCategories: filterDuplicate(
software.categories.concat(softwareExternalData?.applicationCategories ?? [])
),
Expand Down
1 change: 1 addition & 0 deletions api/src/core/adapters/dbApi/kysely/kysely.database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type SoftwareExternalDatasTable = {
applicationCategories: JSONColumnType<string[]> | null;
referencePublication: JSONColumnType<SILL.ScholarlyArticle[]> | null;
publicationTime: Date | null;
identifiers: JSONColumnType<SILL.Identification[]> | null;
};

type SoftwareType =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Kysely } from "kysely";

export async function up(db: Kysely<any>): Promise<void> {
await db.schema.alterTable("software_external_datas").addColumn("identifiers", "jsonb").execute();
}

export async function down(db: Kysely<any>): Promise<void> {
await db.schema.alterTable("software_external_datas").dropColumn("identifiers").execute();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const softwareExternalData: SoftwareExternalData = {
programmingLanguages: ["C++"],
applicationCategories: ["Software Cat I", "Software Cat II"],
referencePublication: undefined,
identifiers: undefined,
publicationTime: new Date(1561566581000)
};

Expand Down Expand Up @@ -83,6 +84,7 @@ const similarSoftwareExternalData: SoftwareExternalData = {
programmingLanguages: ["Python3"],
applicationCategories: ["Software Cat I", "Software Cat II"],
referencePublication: undefined,
identifiers: undefined,
publicationTime: new Date(1561566581000)
};

Expand Down Expand Up @@ -446,6 +448,7 @@ describe("pgDbApi", () => {
keywords: JSON.stringify(softExtData.keywords),
applicationCategories: JSON.stringify(softExtData.applicationCategories),
programmingLanguages: JSON.stringify(softExtData.programmingLanguages),
identifiers: JSON.stringify(softExtData.identifiers),
referencePublication: JSON.stringify(softExtData.referencePublication)
}))
)
Expand Down
3 changes: 3 additions & 0 deletions api/src/core/adapters/fetchExternalData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ describe("fetches software extra data (from different providers)", () => {
websiteUrl: "https://create-react-app.dev/",
programmingLanguages: [],
referencePublication: null,
identifiers: null,
softwareVersion: "5.0.1",
publicationTime: new Date("2022-04-12T00:00:00.000Z")
},
Expand Down Expand Up @@ -224,6 +225,7 @@ describe("fetches software extra data (from different providers)", () => {
websiteUrl: "https://vitejs.dev/",
programmingLanguages: ["JavaScript"],
referencePublication: null,
identifiers: null,
softwareVersion: expect.any(String),
publicationTime: expect.any(Date)
}
Expand Down Expand Up @@ -282,6 +284,7 @@ describe("fetches software extra data (from different providers)", () => {
sourceUrl: "https://github.com/apache/httpd",
websiteUrl: "https://httpd.apache.org/",
referencePublication: null,
identifiers: null,
programmingLanguages: ["C"],
softwareVersion: "2.5.0-alpha",
publicationTime: new Date("2017-11-08T00:00:00.000Z")
Expand Down
27 changes: 27 additions & 0 deletions api/src/core/adapters/hal/getHalSoftware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ describe("HAL", () => {
"programmingLanguages": undefined,
"applicationCategories": ["Computer Science [cs]"],
"referencePublication": undefined,
"identifiers": [
{
"@type": "PropertyValue",
"subjectOf": {
"@type": "Website",
"additionalType": "HAL",
"name": "HAL instance",
"url": new URL("https://hal.science/")
},
"url": new URL("https://hal.science/hal-01715545"),
"value": "hal-01715545"
},
{
"@type": "PropertyValue",
"subjectOf": {
"@type": "Website",
"additionalType": "SWH",
"name": "Software Heritage instance",
"url": new URL("https://www.softwareheritage.org/")
},
"url": new URL(
"https://archive.softwareheritage.org/swh:1:dir:424f2533fe51aa8a49d891f8413dd089995cc851;origin=https://hal.archives-ouvertes.fr/hal-01715545;visit=swh:1:snp:9f3237e88d818d975a63da2d5e04d9ad38b42581;anchor=swh:1:rev:8b71800feca2e28cc0f7f78d248e49244b554875;path=/"
),
"value":
"swh:1:dir:424f2533fe51aa8a49d891f8413dd089995cc851;origin=https://hal.archives-ouvertes.fr/hal-01715545;visit=swh:1:snp:9f3237e88d818d975a63da2d5e04d9ad38b42581;anchor=swh:1:rev:8b71800feca2e28cc0f7f78d248e49244b554875;path=/"
}
],
"publicationTime": new Date(1521545908000)
});
});
Expand Down
48 changes: 47 additions & 1 deletion api/src/core/adapters/hal/getHalSoftwareExternalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ const codeMetaToReferencePublication = (HALReferencePublication: string[] | Obje
return undefined;
};

const HALSource: SILL.WebSite = {
"@type": "Website" as const,
name: "HAL instance",
url: new URL("https://hal.science"),
additionalType: "HAL"
};

const SWHSource: SILL.WebSite = {
"@type": "Website" as const,
name: "Software Heritage instance",
url: new URL("https://www.softwareheritage.org/"),
additionalType: "SWH"
};

const DOISource: SILL.WebSite = {
"@type": "Website" as const,
name: "DOI instance",
url: new URL("https://www.doi.org"),
additionalType: "doi"
};

export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
async (halDocId): Promise<SoftwareExternalData | undefined> => {
const halRawSoftware = await fetchHalSoftwareById(halDocId).catch(error => {
Expand Down Expand Up @@ -170,6 +191,30 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
})
);

const identifiers: SILL.Identification[] =
codemetaSoftware?.identifier?.map(halIdentifier => {
const base = {
"@type": "PropertyValue" as const,
value: halIdentifier.value,
url: new URL(halIdentifier.propertyID)
};
switch (halIdentifier["@type"]) {
case "hal":
return { ...base, subjectOf: HALSource };
case "swhid":
return { ...base, subjectOf: SWHSource };
case "doi":
return { ...base, subjectOf: DOISource };
case "bibcode":
case "cern":
case "prodinra":
case "arxiv":
case "biorxiv":
default:
return base;
}
}) ?? [];

return {
externalId: halRawSoftware.docid,
externalDataOrigin: "HAL",
Expand Down Expand Up @@ -197,7 +242,8 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
publicationTime: halRawSoftware?.releasedDate_tdate
? new Date(halRawSoftware?.releasedDate_tdate)
: undefined,
referencePublication: codeMetaToReferencePublication(codemetaSoftware.referencePublication)
referencePublication: codeMetaToReferencePublication(codemetaSoftware.referencePublication),
identifiers: identifiers
};
},
{
Expand Down
3 changes: 2 additions & 1 deletion api/src/core/adapters/wikidata/getWikidataSoftware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ export const getWikidataSoftware: GetSoftwareExternalData = memoize(
programmingLanguages: programmingLanguageString ? [programmingLanguageString] : [],
applicationCategories: undefined, // doesn't exit on wiki data
referencePublication: undefined, // doesn't exit on wiki data
publicationTime: publicationTimeDate
publicationTime: publicationTimeDate,
identifiers: undefined
};
},
{
Expand Down
1 change: 1 addition & 0 deletions api/src/core/ports/GetSoftwareExternalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type SoftwareExternalData = {
applicationCategories: string[];
publicationTime: Date;
referencePublication: SILL.ScholarlyArticle[];
identifiers: SILL.Identification[];
}>;

export type SimilarSoftwareExternalData = Pick<
Expand Down
1 change: 1 addition & 0 deletions api/src/core/usecases/readWriteSillData/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type Software = {
keywords: string[];
programmingLanguages: string[];
referencePublication?: SILL.ScholarlyArticle[];
identifiers?: SILL.Identification[];
};

export namespace Software {
Expand Down
18 changes: 18 additions & 0 deletions api/src/types/SILL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
export namespace SILL {
export type Sources = "GitLab" | "HAL" | "WikiData" | "SWH" | "Orcid" | "doi" | "GitHub";

// from https://schema.org/PropertyValue
export type Identification = {
"@type": "PropertyValue";
value: string;
url: URL;
subjectOf?: WebSite;
};

// from https://schema.org/WebSite
export type WebSite = {
"@type": "Website";
name: string;
url: URL;
additionalType?: Sources;
};

// from https://schema.org/ScholarlyArticle
export type ScholarlyArticle = {
"@id": string;
Expand Down

0 comments on commit 35a05f0

Please sign in to comment.