Skip to content

Commit fe232be

Browse files
committed
ont-api: rename OntologyID -> ID (see issue #4)
1 parent 8615383 commit fe232be

17 files changed

+139
-135
lines changed

src/main/java/com/github/owlcs/ontapi/HasAdapter.java

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

1515
package com.github.owlcs.ontapi;
1616

17+
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
1718
import org.semanticweb.owlapi.model.OWLOntologyID;
1819
import org.semanticweb.owlapi.model.OWLOntologyLoaderConfiguration;
1920
import org.semanticweb.owlapi.model.OWLOntologyManager;
20-
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
2121

2222
/**
2323
* A technical interface to provide an {@link Adapter} instance.
@@ -40,12 +40,12 @@ default Adapter getAdapter() {
4040
interface Adapter {
4141

4242
/**
43-
* Performs mapping {@link OWLOntologyID} to {@link OntologyID}.
43+
* Performs mapping {@link OWLOntologyID} to {@link ID}.
4444
*
4545
* @param id {@link OWLOntologyID}, not {@code null}
46-
* @return {@link OntologyID}
46+
* @return {@link ID}
4747
*/
48-
OntologyID asONT(OWLOntologyID id);
48+
ID asONT(OWLOntologyID id);
4949

5050
/**
5151
* Performs mapping {@link OWLOntologyLoaderConfiguration} to {@link OntLoaderConfiguration}.

src/main/java/com/github/owlcs/ontapi/OntologyID.java renamed to src/main/java/com/github/owlcs/ontapi/ID.java

+29-26
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
package com.github.owlcs.ontapi;
1616

17+
import com.github.owlcs.ontapi.jena.model.OntID;
1718
import org.apache.jena.graph.Node;
1819
import org.apache.jena.graph.NodeFactory;
1920
import org.semanticweb.owlapi.model.IRI;
2021
import org.semanticweb.owlapi.model.OWLOntologyID;
21-
import com.github.owlcs.ontapi.jena.model.OntID;
2222

2323
import java.lang.reflect.Field;
2424
import java.util.Objects;
@@ -34,7 +34,7 @@
3434
* @see OntID
3535
* @see <a href='https://www.w3.org/TR/owl-syntax/#Ontology_IRI_and_Version_IRI'>3.1 Ontology IRI and Version IRI</a>
3636
*/
37-
public class OntologyID extends OWLOntologyID implements AsNode {
37+
public class ID extends OWLOntologyID implements AsNode {
3838

3939
protected final Node node;
4040

@@ -43,7 +43,7 @@ public class OntologyID extends OWLOntologyID implements AsNode {
4343
*
4444
* @param iri String, not {@code null}
4545
*/
46-
public OntologyID(String iri) {
46+
public ID(String iri) {
4747
this(iri, null);
4848
}
4949

@@ -53,27 +53,27 @@ public OntologyID(String iri) {
5353
* @param iri String, not {@code null}
5454
* @param ver String, can be {@code null}
5555
*/
56-
public OntologyID(String iri, String ver) {
56+
public ID(String iri, String ver) {
5757
this(NodeFactory.createURI(Objects.requireNonNull(iri, "Null iri")), ver);
5858
}
5959

6060
/**
6161
* Constructs an anonymous ontology identifier
6262
* specifying that the ontology IRI (and hence the version IRI) is not present.
6363
*/
64-
public OntologyID() {
64+
public ID() {
6565
this(NodeFactory.createBlankNode(), null);
6666
}
6767

6868
/**
6969
* Constructs an ontology identifier from the given {@link OntID Ontology Graph Model ID}.
70-
* The difference between these two IDs ( {@link OntID} and {@link OntologyID this classs}) is
70+
* The difference between these two IDs ( {@link OntID} and {@link ID this classs}) is
7171
* that the former is used in the RDF representation (i.e. in {@link com.github.owlcs.ontapi.jena.model.OntGraphModel}),
7272
* while the other is in the axiomatic view (i.e. in {@link org.semanticweb.owlapi.model.OWLOntology}).
7373
*
7474
* @param id {@link OntID}, not {@code null}
7575
*/
76-
public OntologyID(OntID id) {
76+
public ID(OntID id) {
7777
this(id.asNode(), id.getVersionIRI());
7878
}
7979

@@ -82,27 +82,31 @@ public OntologyID(OntID id) {
8282
*
8383
* @param id {@link Node}, not {@code null}, ether blank or uri node
8484
* @param version {@link String}, can be {@code null}
85-
* @throws OntApiException if {@code id} is anonymous and {@code version} is not {@code null}
86-
* @throws IllegalStateException if the OWL-API guys have changed the basic implementation, and I do not know about it yet
87-
* @throws UnsupportedOperationException if {@code id} is not uri or blank node
88-
* @throws NullPointerException if {@code id} is {@code null}
85+
* @throws OntApiException if {@code id} is not blank or URI (i.e. it is literal) or
86+
* it is anonymous and {@code version} is not {@code null}
87+
* @throws IllegalStateException if the OWL-API guys have changed the basic implementation,
88+
* but we have not yet learned about it
89+
* @throws NullPointerException if {@code id} is {@code null}
8990
*/
90-
protected OntologyID(Node id, String version) throws OntApiException,
91+
protected ID(Node id, String version) throws OntApiException,
9192
IllegalStateException, UnsupportedOperationException, NullPointerException {
9293
Optional<String> internalID;
9394
Optional<IRI> ontologyIRI, versionIRI;
9495
if (Objects.requireNonNull(id, "Null id node").isBlank()) {
9596
if (version != null) {
96-
throw new OntApiException("Anonymous ontology id (" + id +
97+
throw new OntApiException.IllegalArgument("Anonymous ontology id (" + id +
9798
") can not be accompanied by a version (" + version + ")");
9899
}
99100
internalID = Optional.of(id.getBlankNodeLabel());
100101
ontologyIRI = Optional.empty();
101102
versionIRI = Optional.empty();
102-
} else {
103+
} else if (id.isURI()) {
103104
internalID = Optional.empty();
104105
ontologyIRI = Optional.of(id.getURI()).map(IRI::create);
105106
versionIRI = Optional.ofNullable(version).map(IRI::create);
107+
} else {
108+
throw new OntApiException.IllegalArgument("Illegal node is given: " +
109+
id + " - it must be either URI or Blank resource.");
106110
}
107111
this.node = id;
108112
int hashCode = 17;
@@ -136,17 +140,17 @@ public Node asNode() {
136140
}
137141

138142
/**
139-
* Converts any instance of {@link OWLOntologyID} to the {@link OntologyID ONT-API Ontology Identifier implementation}.
143+
* Converts any instance of {@link OWLOntologyID} to the {@link ID ONT-API Ontology Identifier implementation}.
140144
*
141145
* @param id {@link OWLOntologyID}, not {@code null}
142-
* @return {@link OntologyID}, not {@code null}
146+
* @return {@link ID}, not {@code null}
143147
* @throws IllegalArgumentException should never happen, actually
144148
*/
145-
public static OntologyID asONT(OWLOntologyID id) throws IllegalArgumentException {
146-
if (id instanceof OntologyID) {
147-
return (OntologyID) id;
149+
public static ID asONT(OWLOntologyID id) throws IllegalArgumentException {
150+
if (id instanceof ID) {
151+
return (ID) id;
148152
}
149-
if (id.isAnonymous()) return new OntologyID();
153+
if (id.isAnonymous()) return new ID();
150154
String iri = id.getOntologyIRI().map(IRI::getIRIString).orElseThrow(IllegalArgumentException::new);
151155
String ver = id.getVersionIRI().map(IRI::getIRIString).orElse(null);
152156
return create(iri, ver);
@@ -157,9 +161,9 @@ public static OntologyID asONT(OWLOntologyID id) throws IllegalArgumentException
157161
* Notice that the corresponding constructor does not allow {@code null}s, while this method does.
158162
*
159163
* @param iri {@link IRI}, can be {@code null}
160-
* @return {@link OntologyID}, not {@code null}
164+
* @return {@link ID}, not {@code null}
161165
*/
162-
public static OntologyID create(IRI iri) {
166+
public static ID create(IRI iri) {
163167
return create(iri == null ? null : iri.getIRIString(), null);
164168
}
165169

@@ -169,10 +173,9 @@ public static OntologyID create(IRI iri) {
169173
*
170174
* @param iri String, can be {@code null}
171175
* @param ver String, can be {@code null}
172-
* @return {@link OntologyID}, not {@code null}
176+
* @return {@link ID}, not {@code null}
173177
*/
174-
public static OntologyID create(String iri, String ver) {
175-
return iri == null ? new OntologyID() : new OntologyID(iri, ver);
178+
public static ID create(String iri, String ver) {
179+
return iri == null ? new ID() : new ID(iri, ver);
176180
}
177-
178181
}

src/main/java/com/github/owlcs/ontapi/OWLAdapter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
package com.github.owlcs.ontapi;
1616

17-
import org.semanticweb.owlapi.model.*;
1817
import com.github.owlcs.ontapi.config.OntConfig;
1918
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
2019
import com.github.owlcs.ontapi.config.OntWriterConfiguration;
2120
import com.github.owlcs.ontapi.internal.InternalConfig;
21+
import org.semanticweb.owlapi.model.*;
2222

2323
import java.util.Objects;
2424

@@ -120,11 +120,11 @@ public OntWriterConfiguration asONT(OWLOntologyWriterConfiguration conf) {
120120
* Converts id.
121121
*
122122
* @param id {@link OWLOntologyID}, not {@code null}
123-
* @return {@link OntologyID}, must not be {@code null}
123+
* @return {@link ID}, must not be {@code null}
124124
*/
125125
@Override
126-
public OntologyID asONT(OWLOntologyID id) {
127-
return OntologyID.asONT(id);
126+
public ID asONT(OWLOntologyID id) {
127+
return ID.asONT(id);
128128
}
129129

130130
/**

src/main/java/com/github/owlcs/ontapi/OWLFactoryWrapper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
package com.github.owlcs.ontapi;
1616

17+
import com.github.owlcs.ontapi.config.CacheSettings;
18+
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
19+
import com.github.owlcs.ontapi.jena.UnionGraph;
1720
import org.apache.jena.graph.Graph;
1821
import org.semanticweb.owlapi.io.*;
1922
import org.semanticweb.owlapi.model.*;
2023
import org.semanticweb.owlapi.model.parameters.ChangeApplied;
2124
import org.semanticweb.owlapi.util.PriorityCollection;
2225
import org.slf4j.Logger;
2326
import org.slf4j.LoggerFactory;
24-
import com.github.owlcs.ontapi.config.CacheSettings;
25-
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
26-
import com.github.owlcs.ontapi.jena.UnionGraph;
2727

2828
import javax.annotation.ParametersAreNonnullByDefault;
2929
import java.io.IOException;
@@ -341,7 +341,7 @@ public OWLOntology loadOWLOntology(OWLOntologyManager manager,
341341
if (manager.contains(iri)) {
342342
existingOntology = manager.getOntology(iri);
343343
}
344-
OntologyID id = new OntologyID();
344+
ID id = new ID();
345345
OWLOntology ont = createOWLOntology(id, manager, config);
346346
// Now parse the input into the empty ontology that we created select a parser
347347
// if the input source has format information and MIME information

src/main/java/com/github/owlcs/ontapi/OntBaseModelImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void setOWLOntologyManager(@Nullable OWLOntologyManager manager) {
109109
* @return the {@link OWLOntologyID}
110110
*/
111111
@Override
112-
public OntologyID getOntologyID() {
112+
public ID getOntologyID() {
113113
return this.base.getOntologyID();
114114
}
115115

src/main/java/com/github/owlcs/ontapi/OntGraphUtils.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
package com.github.owlcs.ontapi;
1616

17+
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
18+
import com.github.owlcs.ontapi.jena.impl.OntIDImpl;
19+
import com.github.owlcs.ontapi.jena.model.OntGraphModel;
20+
import com.github.owlcs.ontapi.jena.utils.Graphs;
21+
import com.github.owlcs.ontapi.jena.utils.Models;
22+
import com.github.owlcs.ontapi.transforms.GraphTransformers;
1723
import org.apache.commons.io.input.ReaderInputStream;
1824
import org.apache.jena.graph.*;
1925
import org.apache.jena.rdf.model.impl.ModelCom;
@@ -28,12 +34,6 @@
2834
import org.semanticweb.owlapi.model.PrefixManager;
2935
import org.slf4j.Logger;
3036
import org.slf4j.LoggerFactory;
31-
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
32-
import com.github.owlcs.ontapi.jena.impl.OntIDImpl;
33-
import com.github.owlcs.ontapi.jena.model.OntGraphModel;
34-
import com.github.owlcs.ontapi.jena.utils.Graphs;
35-
import com.github.owlcs.ontapi.jena.utils.Models;
36-
import com.github.owlcs.ontapi.transforms.GraphTransformers;
3737

3838
import java.io.IOException;
3939
import java.io.InputStream;
@@ -77,18 +77,18 @@ public class OntGraphUtils {
7777
* Each method's call should return the same value for the same graph.
7878
*
7979
* @param graph {@link Graph}, not {@code null}
80-
* @return {@link OntologyID}, not {@code null}
80+
* @return {@link ID}, not {@code null}
8181
* @throws OntApiException in case it is an anonymous graph but with version iri
8282
*/
83-
public static OntologyID getOntologyID(Graph graph) throws OntApiException {
83+
public static ID getOntologyID(Graph graph) throws OntApiException {
8484
Graph base = Graphs.getBase(graph);
8585
Node res = Graphs.ontologyNode(base)
8686
.orElseGet(() -> NodeFactory.createBlankNode(toString(graph)));
87-
return new OntologyID(new OntIDImpl(res, new ModelCom(base)));
87+
return new ID(new OntIDImpl(res, new ModelCom(base)));
8888
}
8989

9090
/**
91-
* Builds a map form the ontology graph with {@link OntologyID}s as keys and component {@link Graph Graph}s as values.
91+
* Builds a map form the ontology graph with {@link ID}s as keys and component {@link Graph Graph}s as values.
9292
* <p>
9393
* If any graph (the root or any its component) has no import declarations
9494
* (i.e. no statements {@code _:x owl:imports uri}) then this graph is put into the map as is.
@@ -100,17 +100,17 @@ public static OntologyID getOntologyID(Graph graph) throws OntApiException {
100100
* To check the equivalence of two graphs, the method {@link Graph#isIsomorphicWith(Graph)} is used.
101101
*
102102
* @param graph {@link Graph graph}, not {@code null}
103-
* @return Map with {@link OntologyID OWL Ontology ID} as a key and {@link Graph graph} as a value
103+
* @return Map with {@link ID OWL Ontology ID} as a key and {@link Graph graph} as a value
104104
* @throws OntApiException in case of violation of the restrictions described above
105105
*/
106-
public static Map<OntologyID, Graph> toGraphMap(Graph graph) throws OntApiException {
107-
Map<OntologyID, Graph> res = new LinkedHashMap<>();
108-
OntologyID id = getOntologyID(graph);
106+
public static Map<ID, Graph> toGraphMap(Graph graph) throws OntApiException {
107+
Map<ID, Graph> res = new LinkedHashMap<>();
108+
ID id = getOntologyID(graph);
109109
assembleMap(id, graph, res);
110110
return res;
111111
}
112112

113-
private static void assembleMap(OntologyID id, Graph graph, Map<OntologyID, Graph> res) {
113+
private static void assembleMap(ID id, Graph graph, Map<ID, Graph> res) {
114114
Set<String> imports = Graphs.getImports(graph);
115115
if (imports.isEmpty()) {
116116
// do not analyse graph structure -> put it as is
@@ -121,7 +121,7 @@ private static void assembleMap(OntologyID id, Graph graph, Map<OntologyID, Grap
121121
Iterator<Graph> graphs = Graphs.subGraphs(graph).iterator();
122122
while (graphs.hasNext()) {
123123
Graph g = graphs.next();
124-
OntologyID i = getOntologyID(g);
124+
ID i = getOntologyID(g);
125125
// get first version IRI, then ontology IRI:
126126
String uri = i.getVersionIRI().orElse(i.getOntologyIRI()
127127
.orElseThrow(() -> new OntApiException("Anonymous sub graph found: " + i + ". " +
@@ -132,7 +132,7 @@ private static void assembleMap(OntologyID id, Graph graph, Map<OntologyID, Grap
132132
}
133133
}
134134

135-
private static void put(OntologyID id, Graph graph, Map<OntologyID, Graph> map) {
135+
private static void put(ID id, Graph graph, Map<ID, Graph> map) {
136136
Graph prev = map.get(id);
137137
if (prev != null) {
138138
if (prev.isIsomorphicWith(graph)) {

src/main/java/com/github/owlcs/ontapi/OntologyBuilderImpl.java

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

1515
package com.github.owlcs.ontapi;
1616

17-
import org.apache.jena.graph.Graph;
1817
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
1918
import com.github.owlcs.ontapi.jena.OntModelFactory;
2019
import com.github.owlcs.ontapi.jena.UnionGraph;
20+
import org.apache.jena.graph.Graph;
2121

2222
import javax.annotation.ParametersAreNonnullByDefault;
2323
import java.util.concurrent.locks.ReadWriteLock;
@@ -36,7 +36,7 @@ public OWLAdapter getAdapter() {
3636
}
3737

3838
@Override
39-
public OntologyModel createOntology(OntologyID id, OntologyManager manager, OntLoaderConfiguration config) {
39+
public OntologyModel createOntology(ID id, OntologyManager manager, OntLoaderConfiguration config) {
4040
OntologyManagerImpl m = getAdapter().asIMPL(manager);
4141
OntologyModelImpl res = createOntologyImpl(createGraph(), m, config);
4242
res.setOntologyID(id);

src/main/java/com/github/owlcs/ontapi/OntologyCreator.java

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

1515
package com.github.owlcs.ontapi;
1616

17-
import org.apache.jena.graph.Factory;
18-
import org.apache.jena.graph.Graph;
1917
import com.github.owlcs.ontapi.config.OntLoaderConfiguration;
2018
import com.github.owlcs.ontapi.jena.UnionGraph;
19+
import org.apache.jena.graph.Factory;
20+
import org.apache.jena.graph.Graph;
2121

2222
import java.util.Objects;
2323

@@ -35,12 +35,12 @@ public interface OntologyCreator {
3535
* although the returned ontology must have a reference to the given manager,
3636
* i.e. the method {@link OntologyModel#getOWLOntologyManager()} must return the passed manager instance.
3737
*
38-
* @param id {@link OntologyID}, not {@code null}
38+
* @param id {@link ID}, not {@code null}
3939
* @param manager {@link OntologyManager}, not {@code null}
4040
* @param config {@link OntLoaderConfiguration} the config, not {@code null}
4141
* @return {@link OntologyModel} new instance reflecting manager settings
4242
*/
43-
OntologyModel createOntology(OntologyID id, OntologyManager manager, OntLoaderConfiguration config);
43+
OntologyModel createOntology(ID id, OntologyManager manager, OntLoaderConfiguration config);
4444

4545
/**
4646
* Creates a new detached ontology model which wraps the specified {@link Graph graph}.

0 commit comments

Comments
 (0)