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