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 cardinality handling #778

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading