35
35
* Created by @ssz on 13.07.2019.
36
36
*/
37
37
public enum OWLComponentType {
38
- IRI (org .semanticweb .owlapi .model .IRI .class , Resource .class , true ) {
38
+ IRI (org .semanticweb .owlapi .model .IRI .class , Resource .class , false , true ) {
39
39
@ Override
40
40
List <OWLComponentType > includes () {
41
41
return Collections .emptyList ();
@@ -70,7 +70,7 @@ ExtendedIterator<Resource> listObjects(OntGraphModel model) {
70
70
}
71
71
72
72
},
73
- ANNOTATION_PROPERTY (OWLAnnotationProperty .class , OntNAP .class , true ) {
73
+ ANNOTATION_PROPERTY (OWLAnnotationProperty .class , OntNAP .class , true , true ) {
74
74
@ Override
75
75
Stream <OWLAnnotationProperty > components (OWLObject o ) {
76
76
return o .annotationPropertiesInSignature ();
@@ -81,7 +81,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
81
81
return df .getProperty (n .as (OntNAP .class ));
82
82
}
83
83
},
84
- DATATYPE_PROPERTY (OWLDataProperty .class , OntNDP .class , true ) {
84
+ DATATYPE_PROPERTY (OWLDataProperty .class , OntNDP .class , true , true ) {
85
85
@ Override
86
86
Stream <OWLDataProperty > components (OWLObject o ) {
87
87
return o .dataPropertiesInSignature ();
@@ -92,7 +92,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
92
92
return df .getProperty (n .as (OntNDP .class ));
93
93
}
94
94
},
95
- NAMED_OBJECT_PROPERTY (OWLObjectProperty .class , OntNOP .class , true ) {
95
+ NAMED_OBJECT_PROPERTY (OWLObjectProperty .class , OntNOP .class , true , true ) {
96
96
@ Override
97
97
Stream <OWLObjectProperty > components (OWLObject o ) {
98
98
return o .objectPropertiesInSignature ();
@@ -103,7 +103,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
103
103
return df .getProperty (n .as (OntNOP .class ));
104
104
}
105
105
},
106
- NAMED_INDIVIDUAL (OWLNamedIndividual .class , OntIndividual .Named .class , true ) {
106
+ NAMED_INDIVIDUAL (OWLNamedIndividual .class , OntIndividual .Named .class , true , true ) {
107
107
@ Override
108
108
Stream <OWLNamedIndividual > components (OWLObject o ) {
109
109
return o .individualsInSignature ();
@@ -114,7 +114,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
114
114
return df .getIndividual (n .as (OntIndividual .Named .class ));
115
115
}
116
116
},
117
- CLASS (OWLClass .class , OntClass .class , true ) {
117
+ CLASS (OWLClass .class , OntClass .class , true , true ) {
118
118
@ Override
119
119
Stream <OWLClass > components (OWLObject o ) {
120
120
return o .classesInSignature ();
@@ -125,7 +125,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
125
125
return df .getClass (n .as (OntClass .class ));
126
126
}
127
127
},
128
- DATATYPE (OWLDatatype .class , OntDT .class , true ) {
128
+ DATATYPE (OWLDatatype .class , OntDT .class , true , true ) {
129
129
@ Override
130
130
Stream <OWLDatatype > components (OWLObject o ) {
131
131
return o .datatypesInSignature ();
@@ -136,7 +136,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
136
136
return df .getDatatype (n .as (OntDT .class ));
137
137
}
138
138
},
139
- ENTITY (OWLEntity .class , OntEntity .class , false ) {
139
+ ENTITY (OWLEntity .class , OntEntity .class , true , false ) {
140
140
@ Override
141
141
List <OWLComponentType > includes () {
142
142
return Arrays .asList (ANNOTATION_PROPERTY , DATATYPE_PROPERTY , NAMED_OBJECT_PROPERTY ,
@@ -153,7 +153,7 @@ Stream<OWLEntity> components(OWLObject o) {
153
153
return o .signature ();
154
154
}
155
155
},
156
- LITERAL (OWLLiteral .class , Literal .class , true ) {
156
+ LITERAL (OWLLiteral .class , Literal .class , false , true ) {
157
157
@ Override
158
158
List <OWLComponentType > includes () {
159
159
return Collections .singletonList (DATATYPE );
@@ -176,7 +176,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
176
176
return df .getLiteral (n .asLiteral ());
177
177
}
178
178
},
179
- INDIVIDUAL (OWLIndividual .class , OntIndividual .class , false ) {
179
+ INDIVIDUAL (OWLIndividual .class , OntIndividual .class ) {
180
180
@ Override
181
181
List <OWLComponentType > includes () {
182
182
return Arrays .asList (NAMED_INDIVIDUAL , ANONYMOUS_INDIVIDUAL );
@@ -192,7 +192,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
192
192
return df .getIndividual (n .as (OntIndividual .class ));
193
193
}
194
194
},
195
- ANONYMOUS_INDIVIDUAL (OWLAnonymousIndividual .class , OntIndividual .Anonymous .class , true ) {
195
+ ANONYMOUS_INDIVIDUAL (OWLAnonymousIndividual .class , OntIndividual .Anonymous .class , false , true ) {
196
196
@ Override
197
197
Stream <OWLAnonymousIndividual > components (OWLObject o ) {
198
198
return o .anonymousIndividuals ();
@@ -203,7 +203,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
203
203
return df .getIndividual (n .as (OntIndividual .Anonymous .class ));
204
204
}
205
205
},
206
- ANONYMOUS_DATA_RANGE (OWLDataRange .class , OntDR .class , false ) {
206
+ ANONYMOUS_DATA_RANGE (OWLDataRange .class , OntDR .class ) {
207
207
/**
208
208
* {@inheritDoc}
209
209
* + literals ({@code DataOneOf}, {@code DatatypeRestriction})
@@ -231,7 +231,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
231
231
return df .getDatatype (n .as (OntDR .class ));
232
232
}
233
233
},
234
- DATA_RANGE (OWLDataRange .class , OntDR .class , false ) {
234
+ DATA_RANGE (OWLDataRange .class , OntDR .class ) {
235
235
/**
236
236
* {@inheritDoc}
237
237
* + literals ({@code DataOneOf}, {@code DatatypeRestriction})
@@ -246,7 +246,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
246
246
return df .getDatatype (n .as (OntDR .class ));
247
247
}
248
248
},
249
- ANONYMOUS_CLASS_EXPRESSION (OWLAnonymousClassExpression .class , OntCE .class , false ) {
249
+ ANONYMOUS_CLASS_EXPRESSION (OWLAnonymousClassExpression .class , OntCE .class ) {
250
250
/**
251
251
* {@inheritDoc}
252
252
* This component may contain:
@@ -281,7 +281,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
281
281
return df .getClass (n .as (OntCE .class ));
282
282
}
283
283
},
284
- CLASS_EXPRESSION (OWLClassExpression .class , OntCE .class , false ) {
284
+ CLASS_EXPRESSION (OWLClassExpression .class , OntCE .class ) {
285
285
@ Override
286
286
List <OWLComponentType > includes () {
287
287
return Arrays .asList (CLASS , ANONYMOUS_CLASS_EXPRESSION );
@@ -297,7 +297,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
297
297
return df .getClass (n .as (OntCE .class ));
298
298
}
299
299
},
300
- INVERSE_OBJECT_PROPERTY (OWLObjectInverseOf .class , OntOPE .Inverse .class , false ) {
300
+ INVERSE_OBJECT_PROPERTY (OWLObjectInverseOf .class , OntOPE .Inverse .class ) {
301
301
@ Override
302
302
List <OWLComponentType > includes () {
303
303
return Collections .singletonList (NAMED_OBJECT_PROPERTY );
@@ -308,7 +308,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
308
308
return df .getProperty (n .as (OntOPE .Inverse .class ));
309
309
}
310
310
},
311
- OBJECT_PROPERTY_EXPRESSION (OWLObjectPropertyExpression .class , OntOPE .class , false ) {
311
+ OBJECT_PROPERTY_EXPRESSION (OWLObjectPropertyExpression .class , OntOPE .class ) {
312
312
@ Override
313
313
List <OWLComponentType > includes () {
314
314
return Arrays .asList (NAMED_OBJECT_PROPERTY , INVERSE_OBJECT_PROPERTY );
@@ -319,7 +319,7 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
319
319
return df .getProperty (n .as (OntOPE .class ));
320
320
}
321
321
},
322
- FACET_RESTRICTION (OWLFacetRestriction .class , OntFR .class , false ) {
322
+ FACET_RESTRICTION (OWLFacetRestriction .class , OntFR .class ) {
323
323
@ Override
324
324
List <OWLComponentType > includes () {
325
325
return Collections .singletonList (LITERAL );
@@ -331,13 +331,13 @@ ONTObject<OWLFacetRestriction> wrap(RDFNode n, InternalObjectFactory df) {
331
331
}
332
332
333
333
},
334
- SWRL_VARIABLE (SWRLVariable .class , OntSWRL .Variable .class , true ) {
334
+ SWRL_VARIABLE (SWRLVariable .class , OntSWRL .Variable .class , false , true ) {
335
335
@ Override
336
336
ONTObject <SWRLVariable > wrap (RDFNode n , InternalObjectFactory df ) {
337
337
return df .getSWRLVariable (n .as (OntSWRL .Variable .class ));
338
338
}
339
339
},
340
- SWRL_ATOM (SWRLAtom .class , OntSWRL .Atom .class , false ) {
340
+ SWRL_ATOM (SWRLAtom .class , OntSWRL .Atom .class ) {
341
341
@ Override
342
342
List <OWLComponentType > includes () {
343
343
return Arrays .asList (INDIVIDUAL , LITERAL , SWRL_VARIABLE ,
@@ -368,10 +368,22 @@ ONTObject<? extends OWLObject> wrap(RDFNode n, InternalObjectFactory df) {
368
368
final Class <? extends OWLObject > owl ;
369
369
final Class <? extends RDFNode > jena ;
370
370
private final boolean primitive ;
371
+ private final boolean entity ;
371
372
372
- OWLComponentType (Class <? extends OWLObject > owl , Class <? extends RDFNode > rdf , boolean primitive ) {
373
+ OWLComponentType (Class <? extends OWLObject > owl , Class <? extends RDFNode > rdf ) {
374
+ this (owl , rdf , false , false );
375
+ }
376
+
377
+ /**
378
+ * @param owl OWL-API {@code Class}-type
379
+ * @param rdf ONT-API {@code Class}-type
380
+ * @param entity {@code true} if the this is an entity type
381
+ * @param primitive {@code true} if the this is a primitive type
382
+ */
383
+ OWLComponentType (Class <? extends OWLObject > owl , Class <? extends RDFNode > rdf , boolean entity , boolean primitive ) {
373
384
this .owl = owl ;
374
385
this .jena = rdf ;
386
+ this .entity = entity ;
375
387
this .primitive = primitive ;
376
388
}
377
389
@@ -390,7 +402,7 @@ public static Set<OWLComponentType> toSet(OWLComponentType... values) {
390
402
391
403
/**
392
404
* Determines and returns the most specific type for the given {@link OWLObject}.
393
- * The primitive types go first, then the composite.
405
+ * The primitive types go first, then the composite or abstract .
394
406
*
395
407
* @param o {@link OWLObject}, not {@code null}
396
408
* @return {@link OWLComponentType}
@@ -406,8 +418,7 @@ public static OWLComponentType get(OWLObject o) {
406
418
}
407
419
408
420
/**
409
- * Lists components that can be shared,
410
- * but at the same time are not {@link OWLEntity OWL entities}.
421
+ * Lists components that can be shared.
411
422
*
412
423
* @return {@code Stream} of {@link OWLContentType}s
413
424
* @see InternalModel#getUsedComponentTriples(OntGraphModel, OWLObject)
@@ -493,17 +504,30 @@ public Stream<OWLObject> select(OWLObject container) {
493
504
/**
494
505
* Answers {@code true} if the given {@code container} contains the given {@code component} somewhere in its depths.
495
506
*
496
- * @param container {@link OWLObject} to search in, not {@code null}
497
- * @param component {@link OWLObject} to search for, not {@code null}
507
+ * @param container {@link OWLObject} the container to search in, not {@code null}
508
+ * @param component {@link OWLObject} to search for, must be of this type, not {@code null}
498
509
* @return boolean
499
510
*/
500
511
public boolean contains (OWLObject container , OWLObject component ) {
501
- if (component instanceof OWLEntity ) {
512
+ if (entity ) {
502
513
return container .containsEntityInSignature ((OWLEntity ) component );
503
514
}
504
515
return components (container ).anyMatch (component ::equals );
505
516
}
506
517
518
+ /**
519
+ * Answers {@code true} if the given {@code container} contains
520
+ * any of the given {@code components} somewhere in its depths.
521
+ * Input collection must contain objects of this type only.
522
+ *
523
+ * @param container {@link OWLObject}, the container to search in, not {@code null}
524
+ * @param components a {@code Collection} of {@link OWLObject}s of this type, not {@code null}
525
+ * @return boolean, {@code true} iff any of the {@code components} in present in the {@code container}
526
+ */
527
+ public boolean containsAny (OWLObject container , Collection <? extends OWLObject > components ) {
528
+ return components (container ).anyMatch (components ::contains );
529
+ }
530
+
507
531
/**
508
532
* Returns all components of this type from the specified {@link OWLObject}-container
509
533
* in the form of {@code Stream} of {@link ONTObject}s.
0 commit comments