Skip to content

Commit ce9276f

Browse files
authored
Merge pull request #866 from EBISPOT/add-domain-range-columns
Add domain and range columns for Properties
2 parents 0a4b9d8 + 4d8e514 commit ce9276f

File tree

1 file changed

+251
-4
lines changed

1 file changed

+251
-4
lines changed

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

Lines changed: 251 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DataTable, { Column } from "../../../components/DataTable";
55
import Entity from "../../../model/Entity";
66
import { getEntities } from "../ontologiesSlice";
77
import Individual from "../../../model/Individual";
8+
import Property from "../../../model/Property";
89

910
export default function EntityList({
1011
ontologyId,
@@ -92,11 +93,257 @@ export default function EntityList({
9293
},
9394
};
9495

96+
// Define domain column for properties
97+
const domainColumn: Column = {
98+
name: "Domain",
99+
sortable: true,
100+
selector: (entity: Entity) => {
101+
if(entity instanceof Property) {
102+
const domains = entity.getDomain();
103+
if (domains && domains.length > 0) {
104+
const linkedEntities = entity.getLinkedEntities();
105+
return domains
106+
.map((domain: any) => {
107+
// Handle string IRIs
108+
if (typeof domain === "string") {
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(", ");
139+
}
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+
195+
return "";
196+
})
197+
.filter(Boolean)
198+
.join(", ");
199+
}
200+
}
201+
return "";
202+
},
203+
};
204+
205+
// Define range column for properties
206+
const rangeColumn: Column = {
207+
name: "Range",
208+
sortable: true,
209+
selector: (entity: Entity) => {
210+
if(entity instanceof Property) {
211+
const ranges = entity.getRange();
212+
if (ranges && ranges.length > 0) {
213+
const linkedEntities = entity.getLinkedEntities();
214+
return ranges
215+
.map((range: any) => {
216+
// Handle string IRIs
217+
if (typeof range === "string") {
218+
return formatIri(range, linkedEntities);
219+
}
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+
250+
// Handle complex range objects
251+
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+
274+
// Check for owl:intersectionOf
275+
const intersectionOf = range["http://www.w3.org/2002/07/owl#intersectionOf"];
276+
if (intersectionOf && Array.isArray(intersectionOf)) {
277+
return intersectionOf.map((item: any) => {
278+
// Handle string IRIs in the intersection
279+
if (typeof item === "string") {
280+
return formatIri(item, linkedEntities);
281+
}
282+
283+
// Handle objects in the intersection, particularly looking for owl:oneOf
284+
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
292+
const oneOf = item["http://www.w3.org/2002/07/owl#oneOf"];
293+
if (oneOf && Array.isArray(oneOf)) {
294+
// Format the oneOf elements as a comma-separated list inside curly braces
295+
return `{${oneOf.join(", ")}}`;
296+
}
297+
}
298+
299+
return "";
300+
}).filter(Boolean).join(" and ");
301+
}
302+
}
303+
return "";
304+
})
305+
.filter(Boolean)
306+
.join(", ");
307+
}
308+
}
309+
return "";
310+
},
311+
};
312+
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+
338+
// Merge columns based on the entity type.
95339
// Merge columns based on the entity type.
96-
const columns =
97-
entityType === "individuals"
98-
? [...baseColumns, individualTypeColumn]
99-
: baseColumns;
340+
let columns = [...baseColumns];
341+
342+
if (entityType === "individuals") {
343+
columns.push(individualTypeColumn);
344+
} else if (entityType === "properties") {
345+
columns.push(domainColumn, rangeColumn);
346+
}
100347

101348
return (
102349
<div className="mt-2">

0 commit comments

Comments
 (0)