Skip to content

Commit

Permalink
fix incorrect role in imdi if the Actor doesn't have an actual lameta…
Browse files Browse the repository at this point in the history
… person
  • Loading branch information
hatton committed Dec 20, 2024
1 parent e700abc commit 44897eb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main": "dist/src/mainProcess/main.js",
"name": "lameta",
"productName": "lameta",
"version": "2.3.14-beta",
"version": "2.3.15-beta",
"author": {
"name": "lameta",
"email": "sorryno@email.org"
Expand Down
20 changes: 12 additions & 8 deletions src/export/ImdiGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class ImdiGenerator {
} else {
this.startGroup("Actor");
this.tail.comment(`Could not find a person with name "${trimmedName}"`);
this.element("Role", contribution.role);
this.element("Role", this.getRoleOutput(contribution.role));
this.element("Name", trimmedName);
this.element("FullName", trimmedName);
this.element("Code", "");
Expand Down Expand Up @@ -773,6 +773,16 @@ export default class ImdiGenerator {
//}
}

private getRoleOutput(role: string): string {
let roleOutput = "Unspecified";
if (role && role.length > 0) {
// replace underscores with spaces
roleOutput = role.replace(/_/g, " ");
// upper case the first letter of the first word only (per ELAR's Hanna)
roleOutput = roleOutput.charAt(0).toUpperCase() + roleOutput.slice(1);
}
return roleOutput;
}
// See https://tla.mpi.nl/wp-content/uploads/2012/06/IMDI_MetaData_3.0.4.pdf for details
public actor(
person: Person,
Expand All @@ -781,13 +791,7 @@ export default class ImdiGenerator {
moreKeys?: any[]
): string | null {
return this.group("Actor", () => {
let roleOutput = "Unspecified";
if (role && role.length > 0) {
// replace underscores with spaces
roleOutput = role.replace(/_/g, " ");
// upper case the first letter of the first word only (per ELAR's Hanna)
roleOutput = roleOutput.charAt(0).toUpperCase() + roleOutput.slice(1);
}
const roleOutput = this.getRoleOutput(role);

this.element("Role", roleOutput);
this.requiredField("Name", "name", person);
Expand Down
20 changes: 19 additions & 1 deletion src/export/sessionImdi-custom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ beforeAll(async () => {
session = project.addSession();
// set the session date to a known value so that the test results are predictable

session.addFileForTestAsync(randomFileName());
await session.addFileForTestAsync(randomFileName());
const mary = project.addPerson("Mary");
mary.properties.setText("birthYear", "1980");
});
Expand Down Expand Up @@ -95,6 +95,24 @@ describe("session imdi export", () => {
expect("//Actor/Role").toHaveText("Careful speech speaker"); // this is ELAR's prefered case and spacing
});

// Regression Test
it("A contribution from a person with a missing Person should still be output correct role", () => {
session.removeAllContributionsForUnitTest();
session.addContribution(
new Contribution("I am made up", "careful_speech_speaker", "")
);
setResultXml(
ImdiGenerator.generateSession(
IMDIMode.RAW_IMDI,
session,
project,
true /*omit namespace*/
)
);
expect("//Actor").toHaveCount(1);
expect("//Actor/Role").toHaveText("Careful speech speaker"); // this is ELAR's prefered case and spacing
});

/* the actual policy is in discussion in Notion #238
It's not clear what we will do, but at the moment, we're output a minimal Actor
Expand Down

0 comments on commit 44897eb

Please sign in to comment.