Skip to content

Method: createDataPropertyAssertion(URI, boolean)

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