Skip to content

Commit 84c10f7

Browse files
committed
Add includePartOf option to getParents() and getChildren()
1 parent 12c732b commit 84c10f7

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/ubic/basecode/ontology/model/OntologyTermImpl.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public Collection<AnnotationProperty> getAnnotations() {
134134

135135
@Override
136136
public Collection<OntologyTerm> getChildren( boolean direct ) {
137+
return getChildren( direct, true );
138+
}
139+
140+
@Override
141+
public Collection<OntologyTerm> getChildren( boolean direct, boolean includePartOf ) {
137142
Collection<OntClass> result = new HashSet<>();
138143
ExtendedIterator<OntClass> iterator = ontResource.listSubClasses( direct )
139144
.filterDrop( new EqualityByUriFilter( NOTHING ) );
@@ -149,18 +154,20 @@ public Collection<OntologyTerm> getChildren( boolean direct ) {
149154
result.add( c );
150155
}
151156

152-
Property subClassOf = model.getProfile().SUB_CLASS_OF();
153-
ExtendedIterator<Restriction> restrictionsIterator = model.listRestrictions()
154-
.filterKeep( new RestrictionWithPropertyAndValueFilter( propagateParentsProperties, ontResource ) );
155-
while ( restrictionsIterator.hasNext() ) {
156-
Restriction r = restrictionsIterator.next();
157-
ResIterator ss = model.listResourcesWithProperty( subClassOf, r );
158-
while ( ss.hasNext() ) {
159-
Resource s = ss.next();
160-
if ( s.getURI() != null ) {
161-
OntClass o = model.getOntClass( s.getURI() );
162-
if ( o != null ) {
163-
result.add( o );
157+
if ( includePartOf ) {
158+
Property subClassOf = model.getProfile().SUB_CLASS_OF();
159+
ExtendedIterator<Restriction> restrictionsIterator = model.listRestrictions()
160+
.filterKeep( new RestrictionWithPropertyAndValueFilter( propagateParentsProperties, ontResource ) );
161+
while ( restrictionsIterator.hasNext() ) {
162+
Restriction r = restrictionsIterator.next();
163+
ResIterator ss = model.listResourcesWithProperty( subClassOf, r );
164+
while ( ss.hasNext() ) {
165+
Resource s = ss.next();
166+
if ( s.getURI() != null ) {
167+
OntClass o = model.getOntClass( s.getURI() );
168+
if ( o != null ) {
169+
result.add( o );
170+
}
164171
}
165172
}
166173
}
@@ -254,6 +261,11 @@ public Object getModel() {
254261

255262
@Override
256263
public Collection<OntologyTerm> getParents( boolean direct ) {
264+
return getParents( direct, true );
265+
}
266+
267+
@Override
268+
public Collection<OntologyTerm> getParents( boolean direct, boolean includePartOf ) {
257269
Collection<OntClass> result = new HashSet<>();
258270
ExtendedIterator<OntClass> iterator;
259271
Set<String> excludeProperties;
@@ -264,7 +276,7 @@ public Collection<OntologyTerm> getParents( boolean direct ) {
264276
OntClass c = iterator.next();
265277

266278
// handles part of some {parent container} or part of all {parent container}
267-
if ( c.isRestriction() ) {
279+
if ( includePartOf && c.isRestriction() ) {
268280
Restriction r = c.asRestriction();
269281
if ( propagateParentsProperties.contains( r.getOnProperty() ) ) {
270282
Resource value = getRestrictionValue( c.asRestriction() );

0 commit comments

Comments
 (0)