Skip to content

Commit

Permalink
Add includePartOf option to getParents() and getChildren()
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Mar 27, 2023
1 parent 12c732b commit 84c10f7
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/ubic/basecode/ontology/model/OntologyTermImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public Collection<AnnotationProperty> getAnnotations() {

@Override
public Collection<OntologyTerm> getChildren( boolean direct ) {
return getChildren( direct, true );
}

@Override
public Collection<OntologyTerm> getChildren( boolean direct, boolean includePartOf ) {
Collection<OntClass> result = new HashSet<>();
ExtendedIterator<OntClass> iterator = ontResource.listSubClasses( direct )
.filterDrop( new EqualityByUriFilter( NOTHING ) );
Expand All @@ -149,18 +154,20 @@ public Collection<OntologyTerm> getChildren( boolean direct ) {
result.add( c );
}

Property subClassOf = model.getProfile().SUB_CLASS_OF();
ExtendedIterator<Restriction> restrictionsIterator = model.listRestrictions()
.filterKeep( new RestrictionWithPropertyAndValueFilter( propagateParentsProperties, ontResource ) );
while ( restrictionsIterator.hasNext() ) {
Restriction r = restrictionsIterator.next();
ResIterator ss = model.listResourcesWithProperty( subClassOf, r );
while ( ss.hasNext() ) {
Resource s = ss.next();
if ( s.getURI() != null ) {
OntClass o = model.getOntClass( s.getURI() );
if ( o != null ) {
result.add( o );
if ( includePartOf ) {
Property subClassOf = model.getProfile().SUB_CLASS_OF();
ExtendedIterator<Restriction> restrictionsIterator = model.listRestrictions()
.filterKeep( new RestrictionWithPropertyAndValueFilter( propagateParentsProperties, ontResource ) );
while ( restrictionsIterator.hasNext() ) {
Restriction r = restrictionsIterator.next();
ResIterator ss = model.listResourcesWithProperty( subClassOf, r );
while ( ss.hasNext() ) {
Resource s = ss.next();
if ( s.getURI() != null ) {
OntClass o = model.getOntClass( s.getURI() );
if ( o != null ) {
result.add( o );
}
}
}
}
Expand Down Expand Up @@ -254,6 +261,11 @@ public Object getModel() {

@Override
public Collection<OntologyTerm> getParents( boolean direct ) {
return getParents( direct, true );
}

@Override
public Collection<OntologyTerm> getParents( boolean direct, boolean includePartOf ) {
Collection<OntClass> result = new HashSet<>();
ExtendedIterator<OntClass> iterator;
Set<String> excludeProperties;
Expand All @@ -264,7 +276,7 @@ public Collection<OntologyTerm> getParents( boolean direct ) {
OntClass c = iterator.next();

// handles part of some {parent container} or part of all {parent container}
if ( c.isRestriction() ) {
if ( includePartOf && c.isRestriction() ) {
Restriction r = c.asRestriction();
if ( propagateParentsProperties.contains( r.getOnProperty() ) ) {
Resource value = getRestrictionValue( c.asRestriction() );
Expand Down

0 comments on commit 84c10f7

Please sign in to comment.