Skip to content

Commit

Permalink
Merge pull request #778 from EBISPOT/fix-cardinality-issue
Browse files Browse the repository at this point in the history
Update cardinality handling
  • Loading branch information
haideriqbal authored Nov 12, 2024
2 parents b85e4c1 + 05b6297 commit da4c9f8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
34 changes: 29 additions & 5 deletions frontend/src/components/ClassExpression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ export default function ClassExpression({

const types = asArray(expr['type'])

if(types && types.indexOf('datatype') !== -1) {
function getCardinality(value) {
if (value === null || value === undefined) {
return [];
} else if (Array.isArray(value)) {
return value;
} else {
return [value];
}
}

if(types && types.indexOf('datatype') !== -1) {
// rdfs:Datatype
let equivClass = expr['http://www.w3.org/2002/07/owl#equivalentClass'];
if(equivClass) {
Expand Down Expand Up @@ -150,14 +160,19 @@ export default function ClassExpression({
</span>,
];

for (const subExpr of oneOf) {
for (let subExpr of oneOf) {
if (nodes.length > 1) {
nodes.push(
<span key={randomString()} className="text-neutral-default">
&#44;&nbsp;
</span>
);
}

if (typeof subExpr === "number") {
subExpr = subExpr.toString();
}

nodes.push(
<ClassExpression
key={randomString()}
Expand Down Expand Up @@ -301,9 +316,12 @@ export default function ClassExpression({
);
}

const minCardinality = asArray(
let minCardinality = getCardinality(
expr["http://www.w3.org/2002/07/owl#minCardinality"]
)[0];
if(typeof minCardinality === 'number') {
minCardinality = minCardinality.toString()
}
if (minCardinality) {
return (
<span>
Expand All @@ -314,9 +332,12 @@ export default function ClassExpression({
);
}

let maxCardinality = asArray(
let maxCardinality = getCardinality(
expr["http://www.w3.org/2002/07/owl#maxCardinality"]
)[0];
if(typeof maxCardinality === 'number') {
maxCardinality = maxCardinality.toString()
}
if (maxCardinality) {
return (
<span>
Expand All @@ -326,9 +347,12 @@ export default function ClassExpression({
</span>
);
}
let exactCardinality = asArray(
let exactCardinality = getCardinality(
expr["http://www.w3.org/2002/07/owl#cardinality"]
)[0];
if(typeof exactCardinality === 'number') {
exactCardinality = exactCardinality.toString()
}
if (exactCardinality) {
return (
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export default function IndividualPropertyAssertionsSection({
linkedEntities={linkedEntities}
/>
&thinsp;
{
<span>
{typeof v === "string" && v.includes("http") ? (
<span>
<span className="pr-1 text-sm" style={{ color: "gray" }}>
&#9656;
</span>
Expand All @@ -107,7 +107,21 @@ export default function IndividualPropertyAssertionsSection({
linkedEntities={linkedEntities}
/>
</span>
}
) : (
<Tooltip
title={
typeof v === "string"
? v
: typeof v === "object" && !Array.isArray(v) && v.value
? JSON.stringify(v.value)
: JSON.stringify(v)
}
placement="top"
arrow
>
<i className="icon icon-common icon-info text-neutral-default text-sm ml-1" />
</Tooltip>
)}
</span>
);
}
Expand Down

0 comments on commit da4c9f8

Please sign in to comment.