Skip to content

Commit

Permalink
Update synonym display on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
haideriqbal committed Nov 11, 2024
1 parent 893de15 commit 3d7c3eb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 11 deletions.
17 changes: 12 additions & 5 deletions frontend/src/model/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ export default abstract class Entity extends Thing {
return Reified.fromJson<any>(this.extractExactMatchSynonyms()) || [];
}

getCloseMatchSynonyms(): Reified<any>[] {
return Reified.fromJson<any>(this.extractCloseMatchSynonyms()) || [];
getRelatedSynonyms(): Reified<any>[] {
return Reified.fromJson<any>(this.extractSynonyms("http://www.geneontology.org/formats/oboInOwl#hasRelatedSynonym")) || [];
}

getBroadSynonyms(): Reified<any>[] {
return Reified.fromJson<any>(this.extractSynonyms("http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym")) || [];
}

getNarrowSynonyms(): Reified<any>[] {
return Reified.fromJson<any>(this.extractSynonyms("http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym")) || [];
}

getAppearsIn(): string[] {
Expand Down Expand Up @@ -217,16 +225,15 @@ 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"];
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") {
if (synonymProperty === synonymType) {
result = result.concat(this.properties[synonymProperty]) || [];
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Fragment />;
}

Expand Down Expand Up @@ -47,10 +51,60 @@ export default function EntitySynonymsSection({
</div>
)}

{closeMatchSynonyms && closeMatchSynonyms.length > 0 && (
{relatedSynonyms && relatedSynonyms.length > 0 && (
<div className="flex flex-row flex-wrap items-center mb-2">
<div className="font-bold mr-2">Related Synonyms</div>
{relatedSynonyms
.map((synonym: Reified<any>) => {
const hasMetadata = synonym.hasMetadata();
return (
<div
key={synonym.value.toString().toUpperCase() + randomString()}
className="bg-grey-default rounded-sm font-mono py-1 px-3 mr-2 my-1 text-sm"
>
{synonym.value}
{hasMetadata && (
<MetadataTooltip
metadata={synonym.getMetadata()}
linkedEntities={linkedEntities}
/>
)}
</div>
);
})
.sort((a, b) => sortByKeys(a, b))}
</div>
)}

{narrowSynonyms && narrowSynonyms.length > 0 && (
<div className="flex flex-row flex-wrap items-center mb-2">
<div className="font-bold mr-2">Narrow Synonyms</div>
{narrowSynonyms
.map((synonym: Reified<any>) => {
const hasMetadata = synonym.hasMetadata();
return (
<div
key={synonym.value.toString().toUpperCase() + randomString()}
className="bg-grey-default rounded-sm font-mono py-1 px-3 mr-2 my-1 text-sm"
>
{synonym.value}
{hasMetadata && (
<MetadataTooltip
metadata={synonym.getMetadata()}
linkedEntities={linkedEntities}
/>
)}
</div>
);
})
.sort((a, b) => sortByKeys(a, b))}
</div>
)}

{broadSynonyms && broadSynonyms.length > 0 && (
<div className="flex flex-row flex-wrap items-center mb-2">
<div className="font-bold mr-2">CloseMatch Synonyms</div>
{closeMatchSynonyms
<div className="font-bold mr-2">Broad Synonyms</div>
{broadSynonyms
.map((synonym: Reified<any>) => {
const hasMetadata = synonym.hasMetadata();
return (
Expand Down

0 comments on commit 3d7c3eb

Please sign in to comment.