From 893de15010dcdf364e67005fe7da816d3d2d07ef Mon Sep 17 00:00:00 2001 From: haider Date: Mon, 11 Nov 2024 11:56:07 +0000 Subject: [PATCH 1/3] Update exact synonym on frontend --- frontend/src/model/Entity.ts | 44 +++++++++++ .../EntitySynonymsSection.tsx | 77 +++++++++++++------ 2 files changed, 98 insertions(+), 23 deletions(-) diff --git a/frontend/src/model/Entity.ts b/frontend/src/model/Entity.ts index b3ed61c0f..e647a651e 100644 --- a/frontend/src/model/Entity.ts +++ b/frontend/src/model/Entity.ts @@ -68,6 +68,14 @@ export default abstract class Entity extends Thing { return Reified.fromJson(this.properties["synonym"]); } + getExactSynonyms(): Reified[] { + return Reified.fromJson(this.extractExactMatchSynonyms()) || []; + } + + getCloseMatchSynonyms(): Reified[] { + return Reified.fromJson(this.extractCloseMatchSynonyms()) || []; + } + getAppearsIn(): string[] { return (this.properties["appearsIn"] || []) as string[]; } @@ -189,4 +197,40 @@ export default abstract class Entity extends Thing { } } } + + + extractExactMatchSynonyms(): string[] { + let result = [] + + if(this.properties["synonymProperty"]) { + let synonymProperties = this.properties["synonymProperty"]; + if (!Array.isArray(synonymProperties)) { + synonymProperties = [synonymProperties]; + } + synonymProperties.map((synonymProperty: string) => { + if (synonymProperty === "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym" || + synonymProperty === "http://www.geneontology.org/formats/oboInOwl#hasSynonym") { + result = result.concat(this.properties[synonymProperty]) || []; + } + }) + } + return result || []; + } + + extractCloseMatchSynonyms(): string[] { + let result = [] + if(this.properties["synonymProperty"]) { + let synonymProperties = this.properties["synonymProperty"]; + if (!Array.isArray(synonymProperties)) { + synonymProperties = [synonymProperties]; + } + synonymProperties.map((synonymProperty: string) => { + if (synonymProperty !== "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym" && + synonymProperty !== "http://www.geneontology.org/formats/oboInOwl#hasSynonym") { + result = result.concat(this.properties[synonymProperty]) || []; + } + }) + } + return result || []; + } } diff --git a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx index d6c3f9a67..80d3e0f33 100644 --- a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx +++ b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx @@ -12,34 +12,65 @@ export default function EntitySynonymsSection({ entity: Entity; linkedEntities: LinkedEntities; }) { - let synonyms = entity.getSynonyms(); + let exactSynonyms = entity.getExactSynonyms(); - if (!synonyms || synonyms.length === 0) { + let closeMatchSynonyms = entity.getCloseMatchSynonyms(); + + if ((!exactSynonyms || exactSynonyms.length === 0) && (!closeMatchSynonyms || closeMatchSynonyms.length === 0)) { return ; } return ( -
-
Synonym
- {synonyms - .map((synonym: Reified) => { - const hasMetadata = synonym.hasMetadata(); - return ( -
- {synonym.value} - {hasMetadata && ( - - )} +
+ {exactSynonyms && exactSynonyms.length > 0 && ( +
+
Exact Synonyms
+ {exactSynonyms + .map((synonym: Reified) => { + const hasMetadata = synonym.hasMetadata(); + return ( +
+ {synonym.value} + {hasMetadata && ( + + )} +
+ ); + }) + .sort((a, b) => sortByKeys(a, b))} +
+ )} + + {closeMatchSynonyms && closeMatchSynonyms.length > 0 && ( +
+
CloseMatch Synonyms
+ {closeMatchSynonyms + .map((synonym: Reified) => { + const hasMetadata = synonym.hasMetadata(); + return ( +
+ {synonym.value} + {hasMetadata && ( + + )} +
+ ); + }) + .sort((a, b) => sortByKeys(a, b))}
- ); - }) - .sort((a, b) => sortByKeys(a, b))} -
+ )} +
); } \ No newline at end of file From 3d7c3ebe61e4b390fe521ed5dfcac4f62f6de362 Mon Sep 17 00:00:00 2001 From: haider Date: Mon, 11 Nov 2024 13:22:35 +0000 Subject: [PATCH 2/3] Update synonym display on frontend --- frontend/src/model/Entity.ts | 17 +++-- .../EntitySynonymsSection.tsx | 66 +++++++++++++++++-- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/frontend/src/model/Entity.ts b/frontend/src/model/Entity.ts index e647a651e..02db00b4c 100644 --- a/frontend/src/model/Entity.ts +++ b/frontend/src/model/Entity.ts @@ -72,8 +72,16 @@ export default abstract class Entity extends Thing { return Reified.fromJson(this.extractExactMatchSynonyms()) || []; } - getCloseMatchSynonyms(): Reified[] { - return Reified.fromJson(this.extractCloseMatchSynonyms()) || []; + getRelatedSynonyms(): Reified[] { + return Reified.fromJson(this.extractSynonyms("http://www.geneontology.org/formats/oboInOwl#hasRelatedSynonym")) || []; + } + + getBroadSynonyms(): Reified[] { + return Reified.fromJson(this.extractSynonyms("http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym")) || []; + } + + getNarrowSynonyms(): Reified[] { + return Reified.fromJson(this.extractSynonyms("http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym")) || []; } getAppearsIn(): string[] { @@ -217,7 +225,7 @@ export default abstract class Entity extends Thing { return result || []; } - extractCloseMatchSynonyms(): string[] { + extractSynonyms(synonymType: string): string[] { let result = [] if(this.properties["synonymProperty"]) { let synonymProperties = this.properties["synonymProperty"]; @@ -225,8 +233,7 @@ export default abstract class Entity extends Thing { synonymProperties = [synonymProperties]; } synonymProperties.map((synonymProperty: string) => { - if (synonymProperty !== "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym" && - synonymProperty !== "http://www.geneontology.org/formats/oboInOwl#hasSynonym") { + if (synonymProperty === synonymType) { result = result.concat(this.properties[synonymProperty]) || []; } }) diff --git a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx index 80d3e0f33..9b1ca7840 100644 --- a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx +++ b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx @@ -13,10 +13,14 @@ export default function EntitySynonymsSection({ linkedEntities: LinkedEntities; }) { let exactSynonyms = entity.getExactSynonyms(); + let relatedSynonyms = entity.getRelatedSynonyms(); + let narrowSynonyms = entity.getNarrowSynonyms(); + let broadSynonyms = entity.getBroadSynonyms(); - let closeMatchSynonyms = entity.getCloseMatchSynonyms(); - - if ((!exactSynonyms || exactSynonyms.length === 0) && (!closeMatchSynonyms || closeMatchSynonyms.length === 0)) { + if ((!exactSynonyms || exactSynonyms.length === 0) && + (!relatedSynonyms || relatedSynonyms.length === 0) && + (!narrowSynonyms || narrowSynonyms.length === 0) && + (!broadSynonyms || broadSynonyms.length === 0)) { return ; } @@ -47,10 +51,60 @@ export default function EntitySynonymsSection({
)} - {closeMatchSynonyms && closeMatchSynonyms.length > 0 && ( + {relatedSynonyms && relatedSynonyms.length > 0 && ( +
+
Related Synonyms
+ {relatedSynonyms + .map((synonym: Reified) => { + const hasMetadata = synonym.hasMetadata(); + return ( +
+ {synonym.value} + {hasMetadata && ( + + )} +
+ ); + }) + .sort((a, b) => sortByKeys(a, b))} +
+ )} + + {narrowSynonyms && narrowSynonyms.length > 0 && ( +
+
Narrow Synonyms
+ {narrowSynonyms + .map((synonym: Reified) => { + const hasMetadata = synonym.hasMetadata(); + return ( +
+ {synonym.value} + {hasMetadata && ( + + )} +
+ ); + }) + .sort((a, b) => sortByKeys(a, b))} +
+ )} + + {broadSynonyms && broadSynonyms.length > 0 && (
-
CloseMatch Synonyms
- {closeMatchSynonyms +
Broad Synonyms
+ {broadSynonyms .map((synonym: Reified) => { const hasMetadata = synonym.hasMetadata(); return ( From 7d22f87f5f54b7ea98075240eab5c3c5eb377da5 Mon Sep 17 00:00:00 2001 From: haider Date: Mon, 11 Nov 2024 13:49:03 +0000 Subject: [PATCH 3/3] Simplify code logic --- frontend/src/model/Entity.ts | 62 ++++--- .../EntitySynonymsSection.tsx | 153 +++++------------- 2 files changed, 73 insertions(+), 142 deletions(-) diff --git a/frontend/src/model/Entity.ts b/frontend/src/model/Entity.ts index 02db00b4c..cf5ac102c 100644 --- a/frontend/src/model/Entity.ts +++ b/frontend/src/model/Entity.ts @@ -69,7 +69,11 @@ export default abstract class Entity extends Thing { } getExactSynonyms(): Reified[] { - return Reified.fromJson(this.extractExactMatchSynonyms()) || []; + const exactSynonymTypes = [ + "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym", + "http://www.geneontology.org/formats/oboInOwl#hasSynonym", + ]; + return Reified.fromJson(this.extractSynonyms(exactSynonymTypes)) || []; } getRelatedSynonyms(): Reified[] { @@ -206,38 +210,32 @@ export default abstract class Entity extends Thing { } } - - extractExactMatchSynonyms(): string[] { - let result = [] - - if(this.properties["synonymProperty"]) { - let synonymProperties = this.properties["synonymProperty"]; - if (!Array.isArray(synonymProperties)) { - synonymProperties = [synonymProperties]; - } - synonymProperties.map((synonymProperty: string) => { - if (synonymProperty === "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym" || - synonymProperty === "http://www.geneontology.org/formats/oboInOwl#hasSynonym") { - result = result.concat(this.properties[synonymProperty]) || []; - } - }) + extractSynonyms(synonymTypes: string | string[]): string[] { + const result : string[] = []; + // Check if 'synonymProperty' exists in 'this.properties' + if (!this.properties || !this.properties.hasOwnProperty("synonymProperty")) { + return result; // Return empty array if 'synonymProperty' doesn't exist } - return result || []; - } - - extractSynonyms(synonymType: string): string[] { - let result = [] - if(this.properties["synonymProperty"]) { - let synonymProperties = this.properties["synonymProperty"]; - if (!Array.isArray(synonymProperties)) { - synonymProperties = [synonymProperties]; - } - synonymProperties.map((synonymProperty: string) => { - if (synonymProperty === synonymType) { - result = result.concat(this.properties[synonymProperty]) || []; + const synonymProperties = this.properties["synonymProperty"]; + const synonymPropsArray = Array.isArray(synonymProperties) + ? synonymProperties + : [synonymProperties]; + + const synonymTypesArray = Array.isArray(synonymTypes) + ? synonymTypes + : [synonymTypes]; + + synonymPropsArray.forEach((synonymProperty: string) => { + if (synonymTypesArray.includes(synonymProperty)) { + if (this.properties.hasOwnProperty(synonymProperty)) { + const synonyms = this.properties[synonymProperty]; + if (synonyms) { + result.push(...(Array.isArray(synonyms) ? synonyms : [synonyms])); + } } - }) - } - return result || []; + } + }); + + return result; } } diff --git a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx index 9b1ca7840..7d56cdf94 100644 --- a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx +++ b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx @@ -12,119 +12,52 @@ export default function EntitySynonymsSection({ entity: Entity; linkedEntities: LinkedEntities; }) { - let exactSynonyms = entity.getExactSynonyms(); - let relatedSynonyms = entity.getRelatedSynonyms(); - let narrowSynonyms = entity.getNarrowSynonyms(); - let broadSynonyms = entity.getBroadSynonyms(); + const synonymsData = [ + {label: "Exact Synonyms", synonyms: entity.getExactSynonyms()}, + {label: "Related Synonyms", synonyms: entity.getRelatedSynonyms()}, + {label: "Narrow Synonyms", synonyms: entity.getNarrowSynonyms()}, + {label: "Broad Synonyms", synonyms: entity.getBroadSynonyms()}, + ]; - if ((!exactSynonyms || exactSynonyms.length === 0) && - (!relatedSynonyms || relatedSynonyms.length === 0) && - (!narrowSynonyms || narrowSynonyms.length === 0) && - (!broadSynonyms || broadSynonyms.length === 0)) { - return ; - } + if (synonymsData.every(({synonyms}) => !synonyms || synonyms.length === 0)) { + return ; + } - return ( -
- {exactSynonyms && exactSynonyms.length > 0 && ( -
-
Exact Synonyms
- {exactSynonyms - .map((synonym: Reified) => { - const hasMetadata = synonym.hasMetadata(); - return ( + return ( +
+ {synonymsData.map( + ({label, synonyms}) => + synonyms && + synonyms.length > 0 && (
- {synonym.value} - {hasMetadata && ( - - )} +
{label}
+ {synonyms + .map((synonym: Reified) => { + const hasMetadata = synonym.hasMetadata(); + return ( +
+ {synonym.value} + {hasMetadata && ( + + )} +
+ ); + }) + .sort((a, b) => sortByKeys(a, b))}
- ); - }) - .sort((a, b) => sortByKeys(a, b))} -
- )} - - {relatedSynonyms && relatedSynonyms.length > 0 && ( -
-
Related Synonyms
- {relatedSynonyms - .map((synonym: Reified) => { - const hasMetadata = synonym.hasMetadata(); - return ( -
- {synonym.value} - {hasMetadata && ( - - )} -
- ); - }) - .sort((a, b) => sortByKeys(a, b))} -
- )} - - {narrowSynonyms && narrowSynonyms.length > 0 && ( -
-
Narrow Synonyms
- {narrowSynonyms - .map((synonym: Reified) => { - const hasMetadata = synonym.hasMetadata(); - return ( -
- {synonym.value} - {hasMetadata && ( - - )} -
- ); - }) - .sort((a, b) => sortByKeys(a, b))} -
- )} - - {broadSynonyms && broadSynonyms.length > 0 && ( -
-
Broad Synonyms
- {broadSynonyms - .map((synonym: Reified) => { - const hasMetadata = synonym.hasMetadata(); - return ( -
- {synonym.value} - {hasMetadata && ( - - )} -
- ); - }) - .sort((a, b) => sortByKeys(a, b))} -
- )} -
- ); + ) + )} +
+ ); } \ No newline at end of file