Skip to content

Commit

Permalink
Enable a service to be renamed into several services when exporting a…
Browse files Browse the repository at this point in the history
… dataset (#1076)
  • Loading branch information
Ndpnt authored May 22, 2024
2 parents d111b7e + 1545f05 commit 184d182
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 40 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased [minor]

> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs.
### Added

- Enable a service to be renamed into several services when exporting a dataset

## 1.2.2 - 2024-05-22

_Full changeset and discussions: [#1075](https://github.com/OpenTermsArchive/engine/pull/1075)._
Expand Down
31 changes: 16 additions & 15 deletions scripts/dataset/export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,28 @@ export default async function generate({ archivePath, releaseDate }) {

for await (const version of versionsRepository.iterate()) {
const { content, fetchDate } = version;
const { serviceId, termsType } = renamer.applyRules(version.serviceId, version.termsType);

if (firstVersionDate > fetchDate) {
firstVersionDate = fetchDate;
}
for (const { serviceId, termsType } of renamer.applyRules(version.serviceId, version.termsType)) {
if (firstVersionDate > fetchDate) {
firstVersionDate = fetchDate;
}

if (fetchDate > lastVersionDate) {
lastVersionDate = fetchDate;
}
if (fetchDate > lastVersionDate) {
lastVersionDate = fetchDate;
}

services.add(serviceId);
services.add(serviceId);

const versionPath = generateVersionPath({ serviceId, termsType, fetchDate });
const versionPath = generateVersionPath({ serviceId, termsType, fetchDate });

logger.info({ message: versionPath, counter: index, hash: version.id });
logger.info({ message: versionPath, counter: index, hash: version.id });

archive.stream.append(
content,
{ name: `${archive.basename}/${versionPath}` },
);
index++;
archive.stream.append(
content,
{ name: `${archive.basename}/${versionPath}` },
);
index++;
}
}

archive.stream.append(
Expand Down
50 changes: 26 additions & 24 deletions scripts/utils/renamer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@ export async function loadRules() {
export function applyRules(serviceId, termsType) {
const renamedServiceId = renamingRules.serviceNames[serviceId];

if (renamedServiceId) {
console.log(`⌙ Rename service "${serviceId}" to "${renamedServiceId}"`);
serviceId = renamedServiceId;
}

const renamedTermsType = renamingRules.termsTypes[termsType];

if (renamedTermsType) {
console.log(`⌙ Rename terms type "${termsType}" to "${renamedTermsType}" of "${serviceId}" service`);
termsType = renamedTermsType;
}

const renamedServiceTermsType = renamingRules.termsTypesByService[serviceId]
&& renamingRules.termsTypesByService[serviceId][termsType];

if (renamedServiceTermsType) {
console.log(`⌙ Specific rename terms type "${termsType}" to "${renamedServiceTermsType}" of "${serviceId}" service`);
termsType = renamedServiceTermsType;
}

return {
serviceId,
termsType,
};
return [].concat(renamedServiceId).map(renamedServiceId => {
if (renamedServiceId) {
console.log(`⌙ Rename service "${serviceId}" to "${renamedServiceId}"`);
serviceId = renamedServiceId;
}

const renamedTermsType = renamingRules.termsTypes[termsType];

if (renamedTermsType) {
console.log(`⌙ Rename terms type "${termsType}" to "${renamedTermsType}" of "${serviceId}" service`);
termsType = renamedTermsType;
}

const renamedServiceTermsType = renamingRules.termsTypesByService[serviceId]
&& renamingRules.termsTypesByService[serviceId][termsType];

if (renamedServiceTermsType) {
console.log(`⌙ Specific rename terms type "${termsType}" to "${renamedServiceTermsType}" of "${serviceId}" service`);
termsType = renamedServiceTermsType;
}

return {
serviceId,
termsType,
};
});
}
7 changes: 6 additions & 1 deletion scripts/utils/renamer/rules/serviceNames.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@
"XfinityResidentialSubscription": "Xfinity Residential Services",
"XfinityWebServices": "Xfinity Web Services",
"Youtube": "YouTube",
"Verbaudet": "Vertbaudet"
"Verbaudet": "Vertbaudet",
"OpenAI": [
"ChatGPT",
"DALL·E"
],
"Grok": "xAI"
}

0 comments on commit 184d182

Please sign in to comment.