Skip to content

Commit 4d8e514

Browse files
committed
Update columns to handle complex structures
1 parent d9bf65e commit 4d8e514

File tree

1 file changed

+173
-15
lines changed

1 file changed

+173
-15
lines changed

frontend/src/pages/ontologies/entities/EntityList.tsx

Lines changed: 173 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,94 @@ export default function EntityList({
104104
const linkedEntities = entity.getLinkedEntities();
105105
return domains
106106
.map((domain: any) => {
107+
// Handle string IRIs
107108
if (typeof domain === "string") {
108-
return (
109-
linkedEntities.getLabelForIri(domain) ||
110-
domain.split("/").pop() ||
111-
domain
112-
);
109+
return formatIri(domain, linkedEntities);
110+
}
111+
112+
// Handle array (could be a list of domains)
113+
if (Array.isArray(domain)) {
114+
return domain.map((item: any) => {
115+
if (typeof item === "string") {
116+
return formatIri(item, linkedEntities);
117+
}
118+
if (typeof item === "object") {
119+
// Handle unionOf inside an object in the array
120+
if (item["http://www.w3.org/2002/07/owl#unionOf"] &&
121+
Array.isArray(item["http://www.w3.org/2002/07/owl#unionOf"])) {
122+
123+
const unionOf = item["http://www.w3.org/2002/07/owl#unionOf"];
124+
return unionOf.map((unionItem: any) => {
125+
if (typeof unionItem === "string") {
126+
return formatIri(unionItem, linkedEntities);
127+
}
128+
if (typeof unionItem === "object" &&
129+
unionItem["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
130+
unionItem["http://www.w3.org/2002/07/owl#onProperty"]) {
131+
return formatRestriction(unionItem, linkedEntities);
132+
}
133+
return "";
134+
}).filter(Boolean).join(" or ");
135+
}
136+
}
137+
return "";
138+
}).filter(Boolean).join(", ");
113139
}
140+
141+
// Handle complex domain objects
142+
if (typeof domain === "object" && !Array.isArray(domain)) {
143+
// Check for someValuesFrom restriction
144+
if (domain["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
145+
domain["http://www.w3.org/2002/07/owl#onProperty"]) {
146+
return formatRestriction(domain, linkedEntities);
147+
}
148+
149+
// Check for unionOf
150+
const unionOf = domain["http://www.w3.org/2002/07/owl#unionOf"];
151+
if (unionOf && Array.isArray(unionOf)) {
152+
return unionOf.map((item: any) => {
153+
if (typeof item === "string") {
154+
return formatIri(item, linkedEntities);
155+
}
156+
if (typeof item === "object" &&
157+
item["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
158+
item["http://www.w3.org/2002/07/owl#onProperty"]) {
159+
return formatRestriction(item, linkedEntities);
160+
}
161+
return "";
162+
}).filter(Boolean).join(" or ");
163+
}
164+
165+
// Check for owl:intersectionOf
166+
const intersectionOf = domain["http://www.w3.org/2002/07/owl#intersectionOf"];
167+
if (intersectionOf && Array.isArray(intersectionOf)) {
168+
return intersectionOf.map((item: any) => {
169+
// Handle string IRIs in the intersection
170+
if (typeof item === "string") {
171+
return formatIri(item, linkedEntities);
172+
}
173+
174+
// Handle objects in the intersection, particularly looking for owl:oneOf
175+
if (typeof item === "object" && !Array.isArray(item)) {
176+
// Handle restriction in intersection
177+
if (item["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
178+
item["http://www.w3.org/2002/07/owl#onProperty"]) {
179+
return formatRestriction(item, linkedEntities);
180+
}
181+
182+
// Handle oneOf in intersection
183+
const oneOf = item["http://www.w3.org/2002/07/owl#oneOf"];
184+
if (oneOf && Array.isArray(oneOf)) {
185+
// Format the oneOf elements as a comma-separated list inside curly braces
186+
return `{${oneOf.join(", ")}}`;
187+
}
188+
}
189+
190+
return "";
191+
}).filter(Boolean).join(" and ");
192+
}
193+
}
194+
114195
return "";
115196
})
116197
.filter(Boolean)
@@ -132,30 +213,82 @@ export default function EntityList({
132213
const linkedEntities = entity.getLinkedEntities();
133214
return ranges
134215
.map((range: any) => {
216+
// Handle string IRIs
135217
if (typeof range === "string") {
136-
return (
137-
linkedEntities.getLabelForIri(range) ||
138-
range.split("/").pop() ||
139-
range
140-
);
218+
return formatIri(range, linkedEntities);
141219
}
220+
221+
// Handle array (could be a list of ranges)
222+
if (Array.isArray(range)) {
223+
return range.map((item: any) => {
224+
if (typeof item === "string") {
225+
return formatIri(item, linkedEntities);
226+
}
227+
if (typeof item === "object") {
228+
// Handle unionOf inside an object in the array
229+
if (item["http://www.w3.org/2002/07/owl#unionOf"] &&
230+
Array.isArray(item["http://www.w3.org/2002/07/owl#unionOf"])) {
231+
232+
const unionOf = item["http://www.w3.org/2002/07/owl#unionOf"];
233+
return unionOf.map((unionItem: any) => {
234+
if (typeof unionItem === "string") {
235+
return formatIri(unionItem, linkedEntities);
236+
}
237+
if (typeof unionItem === "object" &&
238+
unionItem["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
239+
unionItem["http://www.w3.org/2002/07/owl#onProperty"]) {
240+
return formatRestriction(unionItem, linkedEntities);
241+
}
242+
return "";
243+
}).filter(Boolean).join(" or ");
244+
}
245+
}
246+
return "";
247+
}).filter(Boolean).join(", ");
248+
}
249+
142250
// Handle complex range objects
143251
if (typeof range === "object" && !Array.isArray(range)) {
252+
// Check for someValuesFrom restriction
253+
if (range["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
254+
range["http://www.w3.org/2002/07/owl#onProperty"]) {
255+
return formatRestriction(range, linkedEntities);
256+
}
257+
258+
// Check for unionOf
259+
const unionOf = range["http://www.w3.org/2002/07/owl#unionOf"];
260+
if (unionOf && Array.isArray(unionOf)) {
261+
return unionOf.map((item: any) => {
262+
if (typeof item === "string") {
263+
return formatIri(item, linkedEntities);
264+
}
265+
if (typeof item === "object" &&
266+
item["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
267+
item["http://www.w3.org/2002/07/owl#onProperty"]) {
268+
return formatRestriction(item, linkedEntities);
269+
}
270+
return "";
271+
}).filter(Boolean).join(" or ");
272+
}
273+
144274
// Check for owl:intersectionOf
145275
const intersectionOf = range["http://www.w3.org/2002/07/owl#intersectionOf"];
146276
if (intersectionOf && Array.isArray(intersectionOf)) {
147277
return intersectionOf.map((item: any) => {
148278
// Handle string IRIs in the intersection
149279
if (typeof item === "string") {
150-
return (
151-
linkedEntities.getLabelForIri(item) ||
152-
item.split("/").pop() ||
153-
item
154-
);
280+
return formatIri(item, linkedEntities);
155281
}
156282

157283
// Handle objects in the intersection, particularly looking for owl:oneOf
158284
if (typeof item === "object" && !Array.isArray(item)) {
285+
// Handle restriction in intersection
286+
if (item["http://www.w3.org/2002/07/owl#someValuesFrom"] &&
287+
item["http://www.w3.org/2002/07/owl#onProperty"]) {
288+
return formatRestriction(item, linkedEntities);
289+
}
290+
291+
// Handle oneOf in intersection
159292
const oneOf = item["http://www.w3.org/2002/07/owl#oneOf"];
160293
if (oneOf && Array.isArray(oneOf)) {
161294
// Format the oneOf elements as a comma-separated list inside curly braces
@@ -177,6 +310,31 @@ export default function EntityList({
177310
},
178311
};
179312

313+
// Helper function to format someValuesFrom restrictions
314+
const formatRestriction = (restriction: any, linkedEntities: any) => {
315+
const someValuesFromIri = restriction["http://www.w3.org/2002/07/owl#someValuesFrom"];
316+
const onPropertyIri = restriction["http://www.w3.org/2002/07/owl#onProperty"];
317+
318+
if (!someValuesFromIri || !onPropertyIri) return "";
319+
320+
const someValuesLabel =
321+
linkedEntities.getLabelForIri(someValuesFromIri) ||
322+
(typeof someValuesFromIri === "string" && someValuesFromIri.split("/").pop()) ||
323+
someValuesFromIri;
324+
325+
const propertyLabel =
326+
linkedEntities.getLabelForIri(onPropertyIri) ||
327+
(typeof onPropertyIri === "string" && onPropertyIri.split("/").pop()) ||
328+
onPropertyIri;
329+
330+
return `${propertyLabel} some ${someValuesLabel}`;
331+
};
332+
333+
// Helper function to format IRIs
334+
const formatIri = (iri: string, linkedEntities: any) => {
335+
return linkedEntities.getLabelForIri(iri) || iri.split("/").pop() || iri;
336+
};
337+
180338
// Merge columns based on the entity type.
181339
// Merge columns based on the entity type.
182340
let columns = [...baseColumns];

0 commit comments

Comments
 (0)