Skip to content

Package: Assertion$AssertionType

Assertion$AssertionType

nameinstructionbranchcomplexitylinemethod
static {...}
M: 0 C: 54
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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.model;
16:
17: import java.net.URI;
18:
19: /**
20: * Base assertion axiom class.
21: * <p>
22: * Defines just whether the assertion uses inferred values and existing types of assertions.
23: * <p>
24: * The usage of types may seem as not being very object-oriented, but since the hierarchy is fixed (there aren't any
25: * other kinds of assertions in ontologies) and since the subclasses essentially don't contain any behavior, we can use
26: * this way.
27: */
28: public abstract class Assertion extends NamedResource {
29:
30: protected final String language;
31: private final boolean hasLanguage;
32:
33: private final boolean inferred;
34:
35: public enum AssertionType {
36: /**
37: * PROPERTY assertion is used in cases where we don't know the property type, for instance when loading value of
38: * the Properties attribute
39: */
40: CLASS, PROPERTY, OBJECT_PROPERTY, DATA_PROPERTY, ANNOTATION_PROPERTY
41: }
42:
43: protected Assertion(URI identifier, boolean isInferred) {
44: super(identifier);
45: this.inferred = isInferred;
46: this.language = null;
47: this.hasLanguage = false;
48: }
49:
50: protected Assertion(URI identifier, String language, boolean isInferred) {
51: super(identifier);
52: this.inferred = isInferred;
53: this.language = language;
54: this.hasLanguage = true;
55: }
56:
57: /**
58: * Whether this assertion is based on inferred values.
59: *
60: * @return True if inferred, false otherwise
61: */
62: public boolean isInferred() {
63: return inferred;
64: }
65:
66: /**
67: * Whether this assertion is a class assertion.
68: * <p>
69: * This is a convenience method, its functionality could be emulated by retrieving this assertion's identifier and
70: * checking whether it equals to the rdf:type URI.
71: *
72: * @return True if this assertion is a class assertion, false otherwise.
73: */
74: public boolean isClassAssertion() {
75: return getIdentifier().equals(ClassAssertion.RDF_TYPE);
76: }
77:
78: /**
79: * Gets type of this assertion.
80: *
81: * @return Assertion type
82: */
83: public abstract AssertionType getType();
84:
85: /**
86: * Gets the language tag carried by this assertion.
87: * <p>
88: * The language tag applies only to string-based literals.
89: *
90: * @return Language tag, e.g. {@code en}, can be {@code null}
91: */
92: public String getLanguage() {
93: return language;
94: }
95:
96: /**
97: * Checks whether a language tag was set for this assertion.
98: *
99: * @return {@code true} if a language tag was set, {@code false} otherwise
100: */
101: public boolean hasLanguage() {
102: return hasLanguage;
103: }
104:
105: @Override
106: public int hashCode() {
107: final int prime = 31;
108: int result = super.hashCode();
109: result = prime * result + (inferred ? 1231 : 1237);
110: return result;
111: }
112:
113: @Override
114: public boolean equals(Object obj) {
115: if (this == obj)
116: return true;
117: if (!super.equals(obj))
118: return false;
119: if (getClass() != obj.getClass())
120: return false;
121: Assertion other = (Assertion) obj;
122: return inferred == other.inferred;
123: }
124:
125: @Override
126: public String toString() {
127: return super.toString() + (inferred ? " - inferred" : " - non-inferred");
128: }
129:
130: /**
131: * Creates new class assertion.
132: * <p>
133: * Class assertions use the rdf:type identifier.
134: *
135: * @param isInferred Whether the assertion uses inferred values
136: * @return Assertion
137: */
138: public static Assertion createClassAssertion(boolean isInferred) {
139: return new ClassAssertion(isInferred);
140: }
141:
142: /**
143: * Creates a property assertion without specifying the assertion identifier.
144: * <p>
145: * Note that the returned instances have the same identifier throughout one JVM - a randomly generated URI.
146: *
147: * @param isInferred Whether the assertion uses inferred values
148: * @return Assertion
149: */
150: public static Assertion createUnspecifiedPropertyAssertion(boolean isInferred) {
151: return new PropertyAssertion(isInferred);
152: }
153:
154: /**
155: * Creates a property assertion without specifying the assertion identifier.
156: * <p>
157: * Note that the returned instances have the same identifier throughout one JVM - a randomly generated URI.
158: *
159: * @param language Language tag, optional
160: * @param isInferred Whether the assertion uses inferred values
161: * @return Assertion
162: */
163: public static Assertion createUnspecifiedPropertyAssertion(String language, boolean isInferred) {
164: return new PropertyAssertion(language, isInferred);
165: }
166:
167: /**
168: * Creates new property assertion without specifying what kind of property it is.
169: *
170: * @param assertionIdentifier Assertion identifier
171: * @param isInferred Whether the assertion uses inferred values
172: * @return Assertion
173: */
174: public static Assertion createPropertyAssertion(URI assertionIdentifier, boolean isInferred) {
175: return new PropertyAssertion(assertionIdentifier, isInferred);
176: }
177:
178: /**
179: * Creates new property assertion without specifying what kind of property it is.
180: *
181: * @param assertionIdentifier Assertion identifier
182: * @param language Language tag. Passing {@code null} explicitly specifies that any language tag is
183: * supported
184: * @param isInferred Whether the assertion uses inferred values
185: * @return Assertion
186: */
187: public static Assertion createPropertyAssertion(URI assertionIdentifier, String language, boolean isInferred) {
188: return new PropertyAssertion(assertionIdentifier, language, isInferred);
189: }
190:
191: /**
192: * Creates new object property assertion.
193: *
194: * @param assertionIdentifier Assertion identifier
195: * @param isInferred Whether the assertion uses inferred values
196: * @return Assertion
197: */
198: public static Assertion createObjectPropertyAssertion(URI assertionIdentifier, boolean isInferred) {
199: return new ObjectPropertyAssertion(assertionIdentifier, isInferred);
200: }
201:
202: /**
203: * Creates new data property assertion.
204: *
205: * @param assertionIdentifier Assertion identifier
206: * @param isInferred Whether the assertion uses inferred values
207: * @return Assertion
208: */
209: public static Assertion createDataPropertyAssertion(URI assertionIdentifier, boolean isInferred) {
210: return new DataPropertyAssertion(assertionIdentifier, isInferred);
211: }
212:
213: /**
214: * Creates new data property assertion.
215: *
216: * @param assertionIdentifier Assertion identifier
217: * @param language Language tag. Passing {@code null} explicitly specifies that any language tag is
218: * supported
219: * @param isInferred Whether the assertion uses inferred values
220: * @return Assertion
221: */
222: public static Assertion createDataPropertyAssertion(URI assertionIdentifier, String language, boolean isInferred) {
223: return new DataPropertyAssertion(assertionIdentifier, language, isInferred);
224: }
225:
226: /**
227: * Creates new annotation property assertion.
228: *
229: * @param assertionIdentifier Assertion identifier
230: * @param isInferred Whether the assertion uses inferred values
231: * @return Assertion
232: */
233: public static Assertion createAnnotationPropertyAssertion(URI assertionIdentifier, boolean isInferred) {
234: return new AnnotationPropertyAssertion(assertionIdentifier, isInferred);
235: }
236:
237: /**
238: * Creates new annotation property assertion.
239: *
240: * @param assertionIdentifier Assertion identifier
241: * @param language Language tag. Passing {@code null} explicitly specifies that any language tag is
242: * supported
243: * @param isInferred Whether the assertion uses inferred values
244: * @return Assertion
245: */
246: public static Assertion createAnnotationPropertyAssertion(URI assertionIdentifier, String language,
247: boolean isInferred) {
248: return new AnnotationPropertyAssertion(assertionIdentifier, language, isInferred);
249: }
250: }