Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update exact synonym display on frontend #796

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions frontend/src/model/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export default abstract class Entity extends Thing {
return Reified.fromJson<any>(this.properties["synonym"]);
}

getExactSynonyms(): Reified<any>[] {
return Reified.fromJson<any>(this.extractExactMatchSynonyms()) || [];
}

getCloseMatchSynonyms(): Reified<any>[] {
return Reified.fromJson<any>(this.extractCloseMatchSynonyms()) || [];
}

getAppearsIn(): string[] {
return (this.properties["appearsIn"] || []) as string[];
}
Expand Down Expand Up @@ -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 || [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Fragment />;
}

return (
<div className="flex flex-row flex-wrap items-center mb-2">
<div className="font-bold mr-2">Synonym</div>
{synonyms
.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 className="flex flex-col mb-2">
{exactSynonyms && exactSynonyms.length > 0 && (
<div className="flex flex-row flex-wrap items-center mb-2">
<div className="font-bold mr-2">Exact Synonyms</div>
{exactSynonyms
.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>
)}

{closeMatchSynonyms && closeMatchSynonyms.length > 0 && (
<div className="flex flex-row flex-wrap items-center mb-2">
<div className="font-bold mr-2">CloseMatch Synonyms</div>
{closeMatchSynonyms
.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>
);
})
.sort((a, b) => sortByKeys(a, b))}
</div>
)}
</div>
);
}
Loading