Skip to content

Commit cafc5be

Browse files
committed
ont-api: add DataPropertySearcher (issue #15) + tests
1 parent 6f7859e commit cafc5be

File tree

4 files changed

+98
-22
lines changed

4 files changed

+98
-22
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import com.github.owlcs.ontapi.OntApiException;
2020
import com.github.owlcs.ontapi.internal.axioms.AbstractNaryTranslator;
2121
import com.github.owlcs.ontapi.internal.searchers.axioms.*;
22-
import com.github.owlcs.ontapi.internal.searchers.objects.AnnotationPropertySearcher;
23-
import com.github.owlcs.ontapi.internal.searchers.objects.ClassSearcher;
24-
import com.github.owlcs.ontapi.internal.searchers.objects.NamedIndividualSearcher;
25-
import com.github.owlcs.ontapi.internal.searchers.objects.ObjectPropertySearcher;
22+
import com.github.owlcs.ontapi.internal.searchers.objects.*;
2623
import com.github.owlcs.ontapi.jena.OntJenaException;
2724
import com.github.owlcs.ontapi.jena.RWLockedGraph;
2825
import com.github.owlcs.ontapi.jena.impl.OntGraphModelImpl;
@@ -152,6 +149,7 @@ abstract class InternalReadModel extends OntGraphModelImpl implements ListAxioms
152149
protected final ObjectsSearcher<OWLNamedIndividual> individualSearcher = new NamedIndividualSearcher();
153150
protected final ObjectsSearcher<OWLObjectProperty> objectPropertySearcher = new ObjectPropertySearcher();
154151
protected final ObjectsSearcher<OWLAnnotationProperty> annotationPropertySearcher = new AnnotationPropertySearcher();
152+
protected final ObjectsSearcher<OWLDataProperty> dataPropertySearcher = new DataPropertySearcher();
155153

156154
InternalReadModel(Graph base,
157155
OntPersonality personality,
@@ -899,6 +897,8 @@ private ObjectsSearcher<OWLObject> getEntitySearcher(OWLComponentType type) {
899897
return BaseSearcher.cast(objectPropertySearcher);
900898
case ANNOTATION_PROPERTY:
901899
return BaseSearcher.cast(annotationPropertySearcher);
900+
case DATATYPE_PROPERTY:
901+
return BaseSearcher.cast(dataPropertySearcher);
902902
}
903903
// TODO: support other types (see https://github.com/owlcs/ont-api/issues/15)
904904
return null;

src/main/java/com/github/owlcs/ontapi/internal/searchers/objects/ClassSearcher.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ protected ONTObject<OWLClass> createEntity(String uri, ModelObjectFactory factor
6060
@Override
6161
protected boolean containsEntity(String uri, OntModel m, AxiomsSettings conf) {
6262
Resource clazz = toResource(m, uri);
63-
if (isBuiltin(m, clazz)) {
64-
if (OWL.Thing.equals(clazz)) {
65-
if (containsAxiom(Iter.flatMap(listImplicitStatements(m), s -> listRootStatements(m, s)), conf)) {
66-
return true;
67-
}
63+
if (!isBuiltin(m, clazz)) {
64+
return containsDeclaration(clazz, m, conf);
65+
}
66+
if (OWL.Thing.equals(clazz)) {
67+
if (containsAxiom(Iter.flatMap(listImplicitStatements(m), s -> listRootStatements(m, s)), conf)) {
68+
return true;
6869
}
69-
return containsInOntology(clazz, m, conf);
7070
}
71-
return containsDeclaration(clazz, m, conf);
71+
return containsInOntology(clazz, m, conf);
7272
}
7373

7474
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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, 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.objects;
16+
17+
import com.github.owlcs.ontapi.OntApiException;
18+
import com.github.owlcs.ontapi.internal.*;
19+
import com.github.owlcs.ontapi.jena.model.OntModel;
20+
import com.github.owlcs.ontapi.jena.utils.Iter;
21+
import com.github.owlcs.ontapi.jena.vocabulary.OWL;
22+
import org.apache.jena.graph.Node;
23+
import org.apache.jena.rdf.model.Resource;
24+
import org.apache.jena.util.iterator.ExtendedIterator;
25+
import org.semanticweb.owlapi.model.OWLAxiom;
26+
import org.semanticweb.owlapi.model.OWLDataProperty;
27+
28+
import java.util.Set;
29+
30+
/**
31+
* Created by @ssz on 26.07.2020.
32+
*/
33+
public class DataPropertySearcher extends PropertySearcher<OWLDataProperty> {
34+
private static final Set<AxiomTranslator<OWLAxiom>> TRANSLATORS = selectTranslators(OWLComponentType.DATATYPE_PROPERTY);
35+
36+
@Override
37+
protected ExtendedIterator<? extends AxiomTranslator<OWLAxiom>> listTranslators() {
38+
return Iter.create(TRANSLATORS);
39+
}
40+
41+
@Override
42+
protected ONTObject<OWLDataProperty> createEntity(String uri, OntModel model, ONTObjectFactory factory) {
43+
return factory.getProperty(OntApiException.mustNotBeNull(model.getDataProperty(uri)));
44+
}
45+
46+
@Override
47+
protected ONTObject<OWLDataProperty> createEntity(String uri, ModelObjectFactory factory) {
48+
return factory.getDataProperty(uri);
49+
}
50+
51+
@Override
52+
protected Resource getEntityType() {
53+
return OWL.DatatypeProperty;
54+
}
55+
56+
@Override
57+
protected Set<Node> getBuiltins(OntModel m) {
58+
return getBuiltinsVocabulary(m).getDatatypeProperties();
59+
}
60+
}

src/test/java/com/github/owlcs/ontapi/tests/model/SignatureTest.java

+27-11
Original file line numberDiff line numberDiff line change
@@ -75,83 +75,99 @@ public void testAnnotationProperties() {
7575
data.doTest(T.ANNOTATION_PROPERTY);
7676
}
7777

78+
@Test
79+
public void testDataProperties() {
80+
data.doTest(T.DATA_PROPERTY);
81+
}
82+
7883
enum TestData {
7984
PIZZA(ModelData.PIZZA,
8085
T.CLASS.of(-18549559397L),
8186
T.CLASS_EXPRESSION.of(-42505386964L),
8287
T.NAMED_INDIVIDUAL.of(627705256L),
8388
T.OBJECT_PROPERTY.of(833765171L),
84-
T.ANNOTATION_PROPERTY.of(2561927052L)
89+
T.ANNOTATION_PROPERTY.of(2561927052L),
90+
T.DATA_PROPERTY.of()
8591
),
8692
FAMILY(ModelData.FAMILY,
8793
T.CLASS.of(-1268263574L),
8894
T.CLASS_EXPRESSION.of(-16978651096L),
8995
T.NAMED_INDIVIDUAL.of(85936112709L),
9096
T.OBJECT_PROPERTY.of(16114808725L),
91-
T.ANNOTATION_PROPERTY.of(1501132596L)
97+
T.ANNOTATION_PROPERTY.of(1501132596L),
98+
T.DATA_PROPERTY.of(-253462624L)
9299
),
93100
PEOPLE(ModelData.PEOPLE,
94101
T.CLASS.of(-44946003502L),
95102
T.CLASS_EXPRESSION.of(-51187071185L),
96103
T.NAMED_INDIVIDUAL.of(-27921947437L),
97104
T.OBJECT_PROPERTY.of(-3152099946L),
98-
T.ANNOTATION_PROPERTY.of(374445982L)
105+
T.ANNOTATION_PROPERTY.of(374445982L),
106+
T.DATA_PROPERTY.of()
99107
),
100108
CAMERA(ModelData.CAMERA,
101109
T.CLASS.of(8550118707L),
102110
T.CLASS_EXPRESSION.of(7152927621L),
103111
T.NAMED_INDIVIDUAL.of(-1151331346L),
104112
T.OBJECT_PROPERTY.of(7453849661L),
105-
T.ANNOTATION_PROPERTY.of(1501132596L)
113+
T.ANNOTATION_PROPERTY.of(1501132596L),
114+
T.DATA_PROPERTY.of(1045936326L)
106115
),
107116
KOALA(ModelData.KOALA,
108117
T.CLASS.of(4003478322L),
109118
T.CLASS_EXPRESSION.of(6612435426L),
110119
T.NAMED_INDIVIDUAL.of(11447501603L),
111120
T.OBJECT_PROPERTY.of(1499233275L),
112-
T.ANNOTATION_PROPERTY.of(-1366328290L)
121+
T.ANNOTATION_PROPERTY.of(-1366328290L),
122+
T.DATA_PROPERTY.of(-1885133841L)
113123
),
114124
TRAVEL(ModelData.TRAVEL,
115125
T.CLASS.of(-12813239L),
116126
T.CLASS_EXPRESSION.of(5669053922L),
117127
T.NAMED_INDIVIDUAL.of(647180319L),
118128
T.OBJECT_PROPERTY.of(451649769L),
119-
T.ANNOTATION_PROPERTY.of(2561927052L)
129+
T.ANNOTATION_PROPERTY.of(2561927052L),
130+
T.DATA_PROPERTY.of(-3029448884L)
120131
),
121132
WINE(ModelData.WINE,
122133
T.CLASS.of(-7328739440L),
123134
T.CLASS_EXPRESSION.of(-12745569437L),
124135
T.NAMED_INDIVIDUAL.of(3479779986L),
125136
T.OBJECT_PROPERTY.of(2015421784L),
126-
T.ANNOTATION_PROPERTY.of(1366640788L)
137+
T.ANNOTATION_PROPERTY.of(1366640788L),
138+
T.DATA_PROPERTY.of(-2003930395L)
127139
),
128140
FOOD(ModelData.FOOD,
129141
T.CLASS.of(-23236948086L),
130142
T.CLASS_EXPRESSION.of(-15980117497L),
131143
T.NAMED_INDIVIDUAL.of(-37834773654L),
132144
T.OBJECT_PROPERTY.of(-1744813981L),
133-
T.ANNOTATION_PROPERTY.of(1501132596L)
145+
T.ANNOTATION_PROPERTY.of(1501132596L),
146+
T.DATA_PROPERTY.of()
134147
),
135148
NCBITAXON_CUT(ModelData.NCBITAXON_CUT,
136149
T.CLASS.of(-72461035056L),
137150
T.CLASS_EXPRESSION.of(2872387903L),
138151
T.NAMED_INDIVIDUAL.of(-75278820767L),
139152
T.OBJECT_PROPERTY.of(-3871221171L),
140-
T.ANNOTATION_PROPERTY.of(7516115975L)
153+
T.ANNOTATION_PROPERTY.of(7516115975L),
154+
T.DATA_PROPERTY.of(-795195587L)
141155
),
142156
HP_CUT(ModelData.HP_CUT,
143157
T.CLASS.of(4720902778L),
144158
T.CLASS_EXPRESSION.of(8426758568L),
145159
T.NAMED_INDIVIDUAL.of(),
146160
T.OBJECT_PROPERTY.of(-1116367413L),
147-
T.ANNOTATION_PROPERTY.of(6911265806L)
161+
T.ANNOTATION_PROPERTY.of(6911265806L),
162+
T.DATA_PROPERTY.of()
148163
),
149164
FAMILY_PEOPLE_UNION(ModelData.FAMILY_PEOPLE_UNION,
150165
T.CLASS.of(-1213682231L),
151166
T.CLASS_EXPRESSION.of(2421052769L),
152167
T.NAMED_INDIVIDUAL.of(899752725L),
153168
T.OBJECT_PROPERTY.of(-163607138L),
154-
T.ANNOTATION_PROPERTY.of(1501132596L)
169+
T.ANNOTATION_PROPERTY.of(1501132596L),
170+
T.DATA_PROPERTY.of(-1511256518L)
155171
),
156172
;
157173
private final ModelData resource;

0 commit comments

Comments
 (0)