Skip to content

Package: IdentifierGenerator

IdentifierGenerator

nameinstructionbranchcomplexitylinemethod
IdentifierGenerator(OWLOntology)
M: 4 C: 9
69%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
generateIdentifier(URI)
M: 0 C: 29
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
isIdentifierUnique(URI)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.owlapi.util;
16:
17: import cz.cvut.kbss.ontodriver.exception.IdentifierGenerationException;
18: import cz.cvut.kbss.ontodriver.util.IdentifierUtils;
19: import org.semanticweb.owlapi.model.IRI;
20: import org.semanticweb.owlapi.model.OWLOntology;
21:
22: import java.net.URI;
23:
24: public class IdentifierGenerator {
25:
26: private static final int GENERATION_THRESHOLD = 100;
27:
28: private final OWLOntology ontology;
29:
30: public IdentifierGenerator(OWLOntology ontology) {
31:• assert ontology != null;
32: this.ontology = ontology;
33: }
34:
35: /**
36: * Generates an identifier which is unique w.r.t. individuals in the known ontology.
37: *
38: * @param classUri URI of individual's class, used as base for the identifier
39: * @return Unique identifier
40: * @throws IdentifierGenerationException If unable to generate unique identifier
41: */
42: public URI generateIdentifier(URI classUri) {
43: boolean unique = false;
44: URI id = null;
45: int counter = 0;
46:• while (!unique && counter++ < GENERATION_THRESHOLD) {
47: id = IdentifierUtils.generateIdentifier(classUri);
48: unique = isIdentifierUnique(id);
49: }
50:• if (!unique) {
51: throw new IdentifierGenerationException("Unable to generate a unique identifier.");
52: }
53: return id;
54: }
55:
56: private boolean isIdentifierUnique(URI uri) {
57:• return !ontology.containsIndividualInSignature(IRI.create(uri));
58: }
59: }