2424import com .hp .hpl .jena .rdf .arp .ParseException ;
2525import com .hp .hpl .jena .rdf .model .Property ;
2626import com .hp .hpl .jena .rdf .model .Resource ;
27+ import com .hp .hpl .jena .rdf .model .ResourceFactory ;
2728import com .hp .hpl .jena .util .iterator .ExtendedIterator ;
2829import org .apache .commons .lang3 .RandomStringUtils ;
2930import org .apache .commons .lang3 .StringUtils ;
@@ -65,19 +66,20 @@ public abstract class AbstractOntologyService implements OntologyService {
6566 /**
6667 * Properties through which propagation is allowed for {@link #getParents(Collection, boolean, boolean)}}
6768 */
68- private static final Set <Property > additionalProperties ;
69+ private static final Set <String > DEFAULT_ADDITIONAL_PROPERTIES ;
6970
7071 static {
71- additionalProperties = new HashSet <>();
72- additionalProperties .add ( BFO .partOf );
73- additionalProperties .add ( RO .properPartOf );
72+ DEFAULT_ADDITIONAL_PROPERTIES = new HashSet <>();
73+ DEFAULT_ADDITIONAL_PROPERTIES .add ( BFO .partOf . getURI () );
74+ DEFAULT_ADDITIONAL_PROPERTIES .add ( RO .properPartOf . getURI () );
7475 }
7576
7677 /* settings (applicable for next initialization) */
7778 private LanguageLevel nextLanguageLevel = LanguageLevel .FULL ;
7879 private InferenceMode nextInferenceMode = InferenceMode .TRANSITIVE ;
7980 private boolean nextProcessImports = true ;
8081 private boolean nextSearchEnabled = true ;
82+ private Set <String > nextAdditionalPropertyUris = DEFAULT_ADDITIONAL_PROPERTIES ;
8183
8284 /**
8385 * Lock used to prevent reads while the ontology is being initialized.
@@ -99,6 +101,8 @@ public abstract class AbstractOntologyService implements OntologyService {
99101 private Boolean processImports = null ;
100102 @ Nullable
101103 private Boolean searchEnabled = null ;
104+ @ Nullable
105+ private Set <String > additionalPropertyUris = null ;
102106
103107 @ Override
104108 public LanguageLevel getLanguageLevel () {
@@ -164,6 +168,25 @@ public void setSearchEnabled( boolean searchEnabled ) {
164168 this .nextSearchEnabled = searchEnabled ;
165169 }
166170
171+ /**
172+ * The set of properties relation to use when inferring parents and children.
173+ * <p>
174+ * The default is to use {@link BFO#partOf} and {@link RO#properPartOf}.
175+ */
176+ public Set <String > getAdditionalPropertyUris () {
177+ Lock lock = rwLock .readLock ();
178+ try {
179+ lock .lock ();
180+ return additionalPropertyUris != null ? additionalPropertyUris : nextAdditionalPropertyUris ;
181+ } finally {
182+ lock .unlock ();
183+ }
184+ }
185+
186+ public void setAdditionalPropertyUris ( Set <String > additionalPropertyUris ) {
187+ this .nextAdditionalPropertyUris = additionalPropertyUris ;
188+ }
189+
167190 public void initialize ( boolean forceLoad , boolean forceIndexing ) {
168191 initialize ( null , forceLoad , forceIndexing );
169192 }
@@ -178,9 +201,12 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
178201 return ;
179202 }
180203
204+ // making a copy of all we need
181205 String ontologyUrl = getOntologyUrl ();
182206 String ontologyName = getOntologyName ();
183207 String cacheName = getCacheName ();
208+ Set <Property > additionalProperties = nextAdditionalPropertyUris .stream ()
209+ .map ( ResourceFactory ::createProperty ).collect ( Collectors .toSet () );
184210 LanguageLevel languageLevel = nextLanguageLevel ;
185211 InferenceMode inferenceMode = nextInferenceMode ;
186212 boolean processImports = nextProcessImports ;
@@ -278,6 +304,7 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
278304 this .inferenceMode = inferenceMode ;
279305 this .processImports = processImports ;
280306 this .searchEnabled = searchEnabled ;
307+ this .additionalPropertyUris = additionalProperties .stream ().map ( Property ::getURI ).collect ( Collectors .toSet () );
281308 if ( cacheName != null ) {
282309 // now that the terms have been replaced, we can clear old caches
283310 try {
0 commit comments