diff --git a/frontend/src/model/Entity.ts b/frontend/src/model/Entity.ts index b3ed61c0f..cf5ac102c 100644 --- a/frontend/src/model/Entity.ts +++ b/frontend/src/model/Entity.ts @@ -68,6 +68,26 @@ export default abstract class Entity extends Thing { return Reified.fromJson(this.properties["synonym"]); } + getExactSynonyms(): Reified[] { + const exactSynonymTypes = [ + "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym", + "http://www.geneontology.org/formats/oboInOwl#hasSynonym", + ]; + return Reified.fromJson(this.extractSynonyms(exactSynonymTypes)) || []; + } + + 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[] { return (this.properties["appearsIn"] || []) as string[]; } @@ -189,4 +209,33 @@ export default abstract class Entity extends Thing { } } } + + 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 + } + 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; + } } diff --git a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx index d6c3f9a67..7d56cdf94 100644 --- a/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx +++ b/frontend/src/pages/ontologies/entities/entityPageSections/EntitySynonymsSection.tsx @@ -12,34 +12,52 @@ export default function EntitySynonymsSection({ entity: Entity; linkedEntities: LinkedEntities; }) { - let synonyms = entity.getSynonyms(); + 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 (!synonyms || synonyms.length === 0) { - return ; - } + if (synonymsData.every(({synonyms}) => !synonyms || synonyms.length === 0)) { + return ; + } - return ( -
-
Synonym
- {synonyms - .map((synonym: Reified) => { - const hasMetadata = synonym.hasMetadata(); - return ( -
- {synonym.value} - {hasMetadata && ( - - )} -
- ); - }) - .sort((a, b) => sortByKeys(a, b))} -
- ); + return ( +
+ {synonymsData.map( + ({label, synonyms}) => + synonyms && + synonyms.length > 0 && ( +
+
{label}
+ {synonyms + .map((synonym: Reified) => { + const hasMetadata = synonym.hasMetadata(); + return ( +
+ {synonym.value} + {hasMetadata && ( + + )} +
+ ); + }) + .sort((a, b) => sortByKeys(a, b))} +
+ ) + )} +
+ ); } \ No newline at end of file