Skip to content

Commit 531ea45

Browse files
committed
ont-api: add OWLOntology#objectPropertyAssertionAxioms(OWLIndividual) graph-optimization, add tests (#12)
1 parent d82b6f6 commit 531ea45

File tree

7 files changed

+174
-47
lines changed

7 files changed

+174
-47
lines changed

src/main/java/com/github/owlcs/ontapi/internal/InternalModel.java

+11
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public class InternalModel extends OntGraphModelImpl
160160
= new AnnotationAssertionBySubject();
161161
protected final ByObjectSearcher<OWLDataPropertyAssertionAxiom, OWLIndividual> dataAssertionsBySubject
162162
= new DataAssertionBySubject();
163+
protected final ByObjectSearcher<OWLObjectPropertyAssertionAxiom, OWLIndividual> objectAssertionsBySubject
164+
= new ObjectAssertionBySubject();
163165
protected final ByObjectSearcher<OWLSubClassOfAxiom, OWLClass> subClassOfBySubject = new SubClassOfBySubject();
164166
protected final ByObjectSearcher<OWLSubClassOfAxiom, OWLClass> subClassOfByObject = new SubClassOfByObject();
165167
protected final ByObjectSearcher<OWLEquivalentClassesAxiom, OWLClass> equivalentClassesByClass = new EquivalentClassesByClass();
@@ -662,6 +664,15 @@ public Stream<OWLDataPropertyAssertionAxiom> listOWLDataPropertyAssertionAxioms(
662664
return listOWLAxioms(dataAssertionsBySubject, OWLDataPropertyAssertionAxiom.class, subject, config);
663665
}
664666

667+
@Override
668+
public Stream<OWLObjectPropertyAssertionAxiom> listOWLObjectPropertyAssertionAxioms(OWLIndividual subject) {
669+
InternalConfig config = getConfig();
670+
if (!useAxiomsSearchOptimization(config)) {
671+
return ListAxioms.super.listOWLObjectPropertyAssertionAxioms(subject);
672+
}
673+
return listOWLAxioms(objectAssertionsBySubject, OWLObjectPropertyAssertionAxiom.class, subject, config);
674+
}
675+
665676
@Override
666677
public Stream<OWLSubClassOfAxiom> listOWLSubClassOfAxiomsBySubject(OWLClass subject) {
667678
InternalConfig config = getConfig();

src/main/java/com/github/owlcs/ontapi/internal/ListAxioms.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ default Stream<OWLDifferentIndividualsAxiom> listOWLDifferentIndividualsAxioms(O
125125
return listOWLNaryAxiomAxiomsByOperand(OWLDifferentIndividualsAxiom.class, operand);
126126
}
127127

128+
/**
129+
* Lists {@link OWLObjectPropertyAssertionAxiom ObjectPropertyAssertion Axiom}s by the given {@link OWLIndividual individual}-subject.
130+
*
131+
* @param subject {@link OWLIndividual}, not {@code null}
132+
* @return a {@code Stream} of {@link OWLObjectPropertyAssertionAxiom}s
133+
*/
128134
default Stream<OWLObjectPropertyAssertionAxiom> listOWLObjectPropertyAssertionAxioms(OWLIndividual subject) {
129135
return listOWLAxioms(OWLObjectPropertyAssertionAxiom.class).filter(x -> Objects.equals(subject, x.getSubject()));
130136
}
@@ -134,7 +140,7 @@ default Stream<OWLNegativeObjectPropertyAssertionAxiom> listOWLNegativeObjectPro
134140
}
135141

136142
/**
137-
* Lists {@link OWLDataPropertyAssertionAxiom DataPropertyAssertion Axiom}s by the given {@link OWLIndividual individual}-subjectt.
143+
* Lists {@link OWLDataPropertyAssertionAxiom DataPropertyAssertion Axiom}s by the given {@link OWLIndividual individual}-subject.
138144
*
139145
* @param subject {@link OWLIndividual}, not {@code null}
140146
* @return a {@code Stream} of {@link OWLDataPropertyAssertionAxiom}s

src/main/java/com/github/owlcs/ontapi/internal/searchers/axioms/AnnotationAssertionBySubject.java

+4-15
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,20 @@
1414

1515
package com.github.owlcs.ontapi.internal.searchers.axioms;
1616

17-
import com.github.owlcs.ontapi.config.AxiomsSettings;
18-
import com.github.owlcs.ontapi.internal.ONTObject;
19-
import com.github.owlcs.ontapi.internal.ONTObjectFactory;
17+
import com.github.owlcs.ontapi.internal.AxiomTranslator;
2018
import com.github.owlcs.ontapi.internal.OWLTopObjectType;
21-
import com.github.owlcs.ontapi.internal.WriteHelper;
2219
import com.github.owlcs.ontapi.internal.axioms.AnnotationAssertionTranslator;
23-
import com.github.owlcs.ontapi.jena.model.OntModel;
24-
import com.github.owlcs.ontapi.jena.model.OntStatement;
25-
import org.apache.jena.util.iterator.ExtendedIterator;
2620
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
2721
import org.semanticweb.owlapi.model.OWLAnnotationSubject;
2822

2923
/**
3024
* Created by @ssz on 18.04.2020.
3125
*/
32-
public class AnnotationAssertionBySubject extends BaseByObject<OWLAnnotationAssertionAxiom, OWLAnnotationSubject> {
26+
public class AnnotationAssertionBySubject extends AssertionBySubject<OWLAnnotationAssertionAxiom, OWLAnnotationSubject> {
3327
private static final AnnotationAssertionTranslator TRANSLATOR = getTranslator(OWLTopObjectType.ANNOTATION_ASSERTION);
3428

3529
@Override
36-
public ExtendedIterator<ONTObject<OWLAnnotationAssertionAxiom>> listONTAxioms(OWLAnnotationSubject subject,
37-
OntModel model,
38-
ONTObjectFactory factory,
39-
AxiomsSettings config) {
40-
ExtendedIterator<OntStatement> res = listBySubject(model, WriteHelper.toResource(subject))
41-
.filterKeep(x -> TRANSLATOR.testStatement(x, config));
42-
return translate(TRANSLATOR, res, factory, config);
30+
AxiomTranslator<OWLAnnotationAssertionAxiom> getTranslator() {
31+
return TRANSLATOR;
4332
}
4433
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* This file is part of the ONT API.
3+
* The contents of this file are subject to the LGPL License, Version 3.0.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
7+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8+
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
9+
*
10+
* Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0 in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
11+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
12+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
13+
*/
14+
15+
package com.github.owlcs.ontapi.internal.searchers.axioms;
16+
17+
import com.github.owlcs.ontapi.config.AxiomsSettings;
18+
import com.github.owlcs.ontapi.internal.AxiomTranslator;
19+
import com.github.owlcs.ontapi.internal.ONTObject;
20+
import com.github.owlcs.ontapi.internal.ONTObjectFactory;
21+
import com.github.owlcs.ontapi.internal.WriteHelper;
22+
import com.github.owlcs.ontapi.jena.model.OntModel;
23+
import com.github.owlcs.ontapi.jena.model.OntStatement;
24+
import org.apache.jena.rdf.model.Resource;
25+
import org.apache.jena.util.iterator.ExtendedIterator;
26+
import org.semanticweb.owlapi.model.HasSubject;
27+
import org.semanticweb.owlapi.model.OWLAxiom;
28+
import org.semanticweb.owlapi.model.OWLObject;
29+
30+
/**
31+
* Created by @ssz on 16.05.2020.
32+
*
33+
* @param <A> - {@link OWLAxiom} and {@link HasSubject}
34+
* @param <S> - {@link OWLObject}
35+
*/
36+
abstract class AssertionBySubject<A extends OWLAxiom & HasSubject<S>, S extends OWLObject> extends BaseByObject<A, S> {
37+
38+
@Override
39+
public final ExtendedIterator<ONTObject<A>> listONTAxioms(S subject,
40+
OntModel model,
41+
ONTObjectFactory factory,
42+
AxiomsSettings config) {
43+
return listONTAxioms(subject, getTranslator(), model, factory, config);
44+
}
45+
46+
private ExtendedIterator<ONTObject<A>> listONTAxioms(S subject,
47+
AxiomTranslator<A> translator,
48+
OntModel model,
49+
ONTObjectFactory factory,
50+
AxiomsSettings config) {
51+
ExtendedIterator<OntStatement> res = listBySubject(model, toResource(subject))
52+
.filterKeep(x -> translator.testStatement(x, config));
53+
return translate(translator, res, factory, config);
54+
}
55+
56+
Resource toResource(S subject) {
57+
return WriteHelper.toResource(subject);
58+
}
59+
60+
abstract AxiomTranslator<A> getTranslator();
61+
}

src/main/java/com/github/owlcs/ontapi/internal/searchers/axioms/DataAssertionBySubject.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,27 @@
1414

1515
package com.github.owlcs.ontapi.internal.searchers.axioms;
1616

17-
import com.github.owlcs.ontapi.config.AxiomsSettings;
18-
import com.github.owlcs.ontapi.internal.ONTObject;
19-
import com.github.owlcs.ontapi.internal.ONTObjectFactory;
17+
import com.github.owlcs.ontapi.internal.AxiomTranslator;
2018
import com.github.owlcs.ontapi.internal.OWLTopObjectType;
2119
import com.github.owlcs.ontapi.internal.WriteHelper;
2220
import com.github.owlcs.ontapi.internal.axioms.DataPropertyAssertionTranslator;
23-
import com.github.owlcs.ontapi.jena.model.OntModel;
24-
import com.github.owlcs.ontapi.jena.model.OntStatement;
25-
import org.apache.jena.util.iterator.ExtendedIterator;
21+
import org.apache.jena.rdf.model.Resource;
2622
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
2723
import org.semanticweb.owlapi.model.OWLIndividual;
2824

2925
/**
3026
* Created by @ssz on 16.05.2020.
3127
*/
32-
public class DataAssertionBySubject extends BaseByObject<OWLDataPropertyAssertionAxiom, OWLIndividual> {
28+
public class DataAssertionBySubject extends AssertionBySubject<OWLDataPropertyAssertionAxiom, OWLIndividual> {
3329
private static final DataPropertyAssertionTranslator TRANSLATOR = getTranslator(OWLTopObjectType.DATA_PROPERTY_ASSERTION);
3430

3531
@Override
36-
public ExtendedIterator<ONTObject<OWLDataPropertyAssertionAxiom>> listONTAxioms(OWLIndividual subject,
37-
OntModel model,
38-
ONTObjectFactory factory,
39-
AxiomsSettings config) {
40-
ExtendedIterator<OntStatement> res = listBySubject(model, WriteHelper.toResource(subject))
41-
.filterKeep(x -> TRANSLATOR.testStatement(x, config));
42-
return translate(TRANSLATOR, res, factory, config);
32+
Resource toResource(OWLIndividual subject) {
33+
return WriteHelper.toResource(subject);
34+
}
35+
36+
@Override
37+
AxiomTranslator<OWLDataPropertyAssertionAxiom> getTranslator() {
38+
return TRANSLATOR;
4339
}
4440
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the ONT API.
3+
* The contents of this file are subject to the LGPL License, Version 3.0.
4+
* Copyright (c) 2020, The University of Manchester, owl.cs group.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
7+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8+
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
9+
*
10+
* Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0 in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
11+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
12+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
13+
*/
14+
15+
package com.github.owlcs.ontapi.internal.searchers.axioms;
16+
17+
import com.github.owlcs.ontapi.internal.AxiomTranslator;
18+
import com.github.owlcs.ontapi.internal.OWLTopObjectType;
19+
import com.github.owlcs.ontapi.internal.WriteHelper;
20+
import com.github.owlcs.ontapi.internal.axioms.ObjectPropertyAssertionTranslator;
21+
import org.apache.jena.rdf.model.Resource;
22+
import org.semanticweb.owlapi.model.OWLIndividual;
23+
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
24+
25+
/**
26+
* Created by @ssz on 16.05.2020.
27+
*/
28+
public class ObjectAssertionBySubject extends AssertionBySubject<OWLObjectPropertyAssertionAxiom, OWLIndividual> {
29+
private static final ObjectPropertyAssertionTranslator TRANSLATOR = getTranslator(OWLTopObjectType.OBJECT_PROPERTY_ASSERTION);
30+
31+
@Override
32+
Resource toResource(OWLIndividual subject) {
33+
return WriteHelper.toResource(subject);
34+
}
35+
36+
@Override
37+
AxiomTranslator<OWLObjectPropertyAssertionAxiom> getTranslator() {
38+
return TRANSLATOR;
39+
}
40+
}

0 commit comments

Comments
 (0)