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

#258 : add referencePublication to externalDataSoftware #269

Open
wants to merge 1 commit into
base: #253-developers-affiliation-on-hover
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const createPgSoftwareExternalDataRepository = (db: Kysely<Database>): So
keywords: JSON.stringify(softwareExternalData.keywords),
applicationCategories: JSON.stringify(softwareExternalData.applicationCategories),
programmingLanguages: JSON.stringify(softwareExternalData.programmingLanguages),
referencePublication: JSON.stringify(softwareExternalData.referencePublication),
description: JSON.stringify(softwareExternalData.description)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
parentWikidataSoftware: parentExternalData,
keywords: software?.keywords ?? softwareExternalData?.keywords ?? [],
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
referencePublication: softwareExternalData?.referencePublication,
applicationCategories: software.categories.concat(
softwareExternalData?.applicationCategories ?? []
),
Expand Down Expand Up @@ -296,7 +297,8 @@ export const createPgSoftwareRepository = (db: Kysely<Database>): SoftwareReposi
softwareExternalData?.applicationCategories ?? []
),
categories: undefined, // merged in applicationCategories, set to undefined to remove it
programmingLanguages: softwareExternalData?.programmingLanguages ?? []
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
referencePublication: softwareExternalData?.referencePublication
});
}
);
Expand Down Expand Up @@ -431,6 +433,7 @@ const makeGetSoftwareBuilder = (db: Kysely<Database>) =>
documentationUrl: ref("ext.documentationUrl"),
programmingLanguages: ref("ext.programmingLanguages"),
applicationCategories: ref("ext.applicationCategories"),
referencePublication: ref("ext.referencePublication"),
keywords: ref("ext.keywords"),
softwareVersion: ref("ext.softwareVersion"),
publicationTime: ref("ext.publicationTime")
Expand Down Expand Up @@ -565,6 +568,7 @@ const makeGetSoftwareById =
testUrl: testUrls[0]?.url,
parentWikidataSoftware: parentExternalData,
programmingLanguages: softwareExternalData?.programmingLanguages ?? [],
referencePublication: softwareExternalData?.referencePublication,
applicationCategories: filterDuplicate(
software.categories.concat(softwareExternalData?.applicationCategories ?? [])
),
Expand Down
3 changes: 3 additions & 0 deletions api/src/core/adapters/dbApi/kysely/kysely.database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Generated, JSONColumnType } from "kysely";
// Only allowed import on JSONColumnType
import { SILL } from "../../../../types/SILL";

// from https://schema.org/Organization
type SchemaOrganization = {
Expand Down Expand Up @@ -93,6 +95,7 @@ type SoftwareExternalDatasTable = {
keywords: JSONColumnType<string[]> | null;
programmingLanguages: JSONColumnType<string[]> | null;
applicationCategories: JSONColumnType<string[]> | null;
referencePublication: JSONColumnType<SILL.ScholarlyArticle[]> | null;
publicationTime: Date | null;
};

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("referencePublication", "jsonb").execute();
}

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

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

Expand Down Expand Up @@ -441,9 +443,10 @@ describe("pgDbApi", () => {
developers: JSON.stringify(softExtData.developers),
label: JSON.stringify(softExtData.label),
description: JSON.stringify(softExtData.description),
keywords: JSON.stringify(softwareExternalData.keywords),
applicationCategories: JSON.stringify(softwareExternalData.applicationCategories),
programmingLanguages: JSON.stringify(softwareExternalData.programmingLanguages)
keywords: JSON.stringify(softExtData.keywords),
applicationCategories: JSON.stringify(softExtData.applicationCategories),
programmingLanguages: JSON.stringify(softExtData.programmingLanguages),
referencePublication: JSON.stringify(softExtData.referencePublication)
guillermau marked this conversation as resolved.
Show resolved Hide resolved
}))
)
.execute();
Expand Down
4 changes: 4 additions & 0 deletions api/src/core/adapters/fetchExternalData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ describe("fetches software extra data (from different providers)", () => {
sourceUrl: "https://github.com/facebook/create-react-app",
websiteUrl: "https://create-react-app.dev/",
programmingLanguages: [],
referencePublication: null,
softwareVersion: "5.0.1",
publicationTime: new Date("2022-04-12T00:00:00.000Z")
},
Expand All @@ -213,6 +214,7 @@ describe("fetches software extra data (from different providers)", () => {
externalId: "Q111590996",
framaLibreId: null,
isLibreSoftware: true,

keywords: [],
label: "Vite",
license: "MIT licence",
Expand All @@ -221,6 +223,7 @@ describe("fetches software extra data (from different providers)", () => {
sourceUrl: "https://github.com/vitejs/vite",
websiteUrl: "https://vitejs.dev/",
programmingLanguages: ["JavaScript"],
referencePublication: null,
softwareVersion: expect.any(String),
publicationTime: expect.any(Date)
}
Expand Down Expand Up @@ -278,6 +281,7 @@ describe("fetches software extra data (from different providers)", () => {
"//upload.wikimedia.org/wikipedia/commons/thumb/1/10/Apache_HTTP_server_logo_%282019-present%29.svg/220px-Apache_HTTP_server_logo_%282019-present%29.svg.png",
sourceUrl: "https://github.com/apache/httpd",
websiteUrl: "https://httpd.apache.org/",
referencePublication: null,
programmingLanguages: ["C"],
softwareVersion: "2.5.0-alpha",
publicationTime: new Date("2017-11-08T00:00:00.000Z")
Expand Down
1 change: 1 addition & 0 deletions api/src/core/adapters/hal/getHalSoftware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("HAL", () => {
"keywords": undefined,
"programmingLanguages": undefined,
"applicationCategories": ["Computer Science [cs]"],
"referencePublication": undefined,
"publicationTime": new Date(1521545908000)
});
});
Expand Down
69 changes: 68 additions & 1 deletion api/src/core/adapters/hal/getHalSoftwareExternalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,72 @@ const buildParentOrganizationTree = async (
);
};

const parseReferencePublication = (key: string, value: string | string[]): SILL.ScholarlyArticle[] => {
const arrayValue = typeof value === "string" ? value.split(",") : value;
switch (key) {
case "hal":
return arrayValue.map((halThing): SILL.ScholarlyArticle => {
return {
"@id": halThing,
"@type": "ScholarlyArticle",
identifier: {
"@type": "PropertyValue",
value: halThing,
propertyID: "HAL",
url: halThing.includes("https") ? new URL(halThing) : new URL(`https://hal.science/${halThing}`)
}
};
});
case "doi":
return arrayValue.map((doi): SILL.ScholarlyArticle => {
return {
"@id": doi,
"@type": "ScholarlyArticle",
identifier: {
"@type": "PropertyValue",
value: doi,
propertyID: "doi",
url: doi.includes("https") ? URL.parse(doi) : URL.parse(`https://doi.org/${doi}`)
}
};
});
case "arxiv":
return arrayValue.map((arxivId): SILL.ScholarlyArticle => {
return {
"@id": arxivId,
"@type": "ScholarlyArticle",
identifier: {
"@type": "PropertyValue",
value: arxivId,
propertyID: "arxiv",
url: arxivId.includes("https")
? URL.parse(arxivId)
: URL.parse(`https://arxiv.org/abs/${arxivId}`)
}
};
});
default:
return [];
}
};

const codeMetaToReferencePublication = (HALReferencePublication: string[] | Object | undefined) => {
if (HALReferencePublication) {
if (Array.isArray(HALReferencePublication)) {
console.error("Issue with HAL data. This data need to be curated", HALReferencePublication);
return undefined;
}

return Object.entries(HALReferencePublication).reduce(
(publicationArray: SILL.ScholarlyArticle[], [key, value]) => {
return publicationArray.concat(parseReferencePublication(key, value));
},
[]
);
}
return undefined;
};

export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
async (halDocId): Promise<SoftwareExternalData | undefined> => {
const halRawSoftware = await fetchHalSoftwareById(halDocId).catch(error => {
Expand Down Expand Up @@ -125,7 +191,8 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
applicationCategories: sciencesCategories,
publicationTime: halRawSoftware?.releasedDate_tdate
? new Date(halRawSoftware?.releasedDate_tdate)
: undefined
: undefined,
referencePublication: codeMetaToReferencePublication(codemetaSoftware.referencePublication)
};
},
{
Expand Down
1 change: 1 addition & 0 deletions api/src/core/adapters/hal/types/HAL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export namespace HAL {
developmentStatus?: string;
author: Role[]; // Non regular Schema.org / CodeMeta
contributor?: Person[];
referencePublication?: string[] | string | Object;
};

// HAL implementation of https://codemeta.github.io/terms/
Expand Down
1 change: 1 addition & 0 deletions api/src/core/adapters/wikidata/getWikidataSoftware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const getWikidataSoftware: GetSoftwareExternalData = memoize(
keywords: getClaimDataValue<"string">("P921"),
programmingLanguages: programmingLanguageString ? [programmingLanguageString] : [],
applicationCategories: undefined, // doesn't exit on wiki data
referencePublication: undefined, // doesn't exit on wiki data
publicationTime: publicationTimeDate
};
},
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 @@ -32,6 +32,7 @@ export type SoftwareExternalData = {
programmingLanguages: string[];
applicationCategories: string[];
publicationTime: Date;
referencePublication: SILL.ScholarlyArticle[];
}>;

export type SimilarSoftwareExternalData = Pick<
Expand Down
15 changes: 15 additions & 0 deletions api/src/types/SILL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
export namespace SILL {
// from https://schema.org/ScholarlyArticle
export type ScholarlyArticle = {
"@id": string;
"@type": "ScholarlyArticle";
identifier?: PropertyValue;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Créer un typage plus fort

};

// from https://schema.org/PropertyValue
export type PropertyValue = {
"@type"?: "PropertyValue";
value?: string;
propertyID?: string;
url?: URL | null;
};

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