From f5c8976f0b240129d409ce78d4086dd693b28af0 Mon Sep 17 00:00:00 2001 From: haider Date: Mon, 28 Oct 2024 15:23:20 +0000 Subject: [PATCH] Update cardinality handling --- frontend/src/components/ClassExpression.tsx | 27 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/ClassExpression.tsx b/frontend/src/components/ClassExpression.tsx index 22e7ab6f6..f469bc28d 100644 --- a/frontend/src/components/ClassExpression.tsx +++ b/frontend/src/components/ClassExpression.tsx @@ -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) { @@ -301,9 +311,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 ( @@ -314,9 +327,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 ( @@ -326,9 +342,12 @@ export default function ClassExpression({ ); } - 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 (