2020package ubic .basecode .ontology .jena ;
2121
2222import com .hp .hpl .jena .ontology .*;
23- import com .hp .hpl .jena .rdf .model .*;
23+ import com .hp .hpl .jena .rdf .model .ModelFactory ;
24+ import com .hp .hpl .jena .rdf .model .NodeIterator ;
25+ import com .hp .hpl .jena .rdf .model .Property ;
26+ import com .hp .hpl .jena .rdf .model .Resource ;
2427import com .hp .hpl .jena .rdfxml .xmlinput .ARPErrorNumbers ;
2528import com .hp .hpl .jena .rdfxml .xmlinput .ParseException ;
2629import com .hp .hpl .jena .reasoner .ReasonerFactory ;
@@ -67,12 +70,31 @@ public abstract class AbstractOntologyService implements OntologyService {
6770 /**
6871 * Properties through which propagation is allowed for {@link #getParents(Collection, boolean, boolean)}}
6972 */
70- private static final Set <String > DEFAULT_ADDITIONAL_PROPERTIES ;
73+ private static final Set <Property > DEFAULT_ADDITIONAL_PROPERTIES ;
7174
7275 static {
7376 DEFAULT_ADDITIONAL_PROPERTIES = new HashSet <>();
74- DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .partOf .getURI () );
75- DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .properPartOf .getURI () );
77+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .partOf );
78+ // all those are sub-properties of partOf, but some ontologies might not have them
79+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .activeIngredientIn );
80+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .boundingLayerOf );
81+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .branchingPartOf );
82+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .determinedBy );
83+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .ends );
84+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .isSubsequenceOf );
85+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .isEndSequenceOf );
86+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .isStartSequenceOf );
87+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .lumenOf );
88+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .luminalSpaceOf );
89+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .mainStemOf );
90+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .memberOf );
91+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .occurrentPartOf );
92+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .skeletonOf );
93+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .starts );
94+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .subclusterOf );
95+ // used by some older ontologies
96+ //noinspection deprecation
97+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .properPartOf );
7698 }
7799
78100 /**
@@ -87,7 +109,7 @@ public abstract class AbstractOntologyService implements OntologyService {
87109 private boolean processImports = true ;
88110 private boolean searchEnabled = true ;
89111 private Set <String > excludedWordsFromStemming = Collections .emptySet ();
90- private Set <String > additionalPropertyUris = DEFAULT_ADDITIONAL_PROPERTIES ;
112+ private Set <String > additionalPropertyUris = DEFAULT_ADDITIONAL_PROPERTIES . stream (). map ( Property :: getURI ). collect ( Collectors . toSet () ) ;
91113
92114 @ Override
93115 public String getName () {
@@ -183,8 +205,6 @@ private synchronized void initialize( @Nullable InputStream stream, boolean forc
183205 String ontologyUrl = getOntologyUrl ();
184206 String ontologyName = getOntologyName ();
185207 String cacheName = getCacheName ();
186- Set <Property > additionalProperties = this .additionalPropertyUris .stream ()
187- .map ( ResourceFactory ::createProperty ).collect ( Collectors .toSet () );
188208 LanguageLevel languageLevel = this .languageLevel ;
189209 InferenceMode inferenceMode = this .inferenceMode ;
190210 boolean processImports = this .processImports ;
@@ -242,9 +262,9 @@ private synchronized void initialize( @Nullable InputStream stream, boolean forc
242262 return ;
243263
244264 // compute additional restrictions
245- Set <Restriction > additionalRestrictions = model . listRestrictions ()
246- . filterKeep ( new RestrictionWithOnPropertyFilter ( additionalProperties ) )
247- . toSet ();
265+ Set <Property > additionalProperties = additionalPropertyUris . stream (). map ( model :: getProperty ). collect ( Collectors . toSet () );
266+ Set < Restriction > additionalRestrictions = JenaUtils . listRestrictionsOnProperties ( model , additionalProperties , true ). toSet ();
267+
248268
249269 // indexing is lengthy, don't bother if we're interrupted
250270 if ( Thread .currentThread ().isInterrupted () )
0 commit comments