Package: Assertion
Assertion
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Assertion(URI, boolean) |
|
|
|
|
|
||||||||||||||||||||
createAnnotationPropertyAssertion(URI, boolean) |
|
|
|
|
|
||||||||||||||||||||
createClassAssertion(boolean) |
|
|
|
|
|
||||||||||||||||||||
createDataPropertyAssertion(URI, boolean) |
|
|
|
|
|
||||||||||||||||||||
createObjectPropertyAssertion(URI, boolean) |
|
|
|
|
|
||||||||||||||||||||
createPropertyAssertion(URI, boolean) |
|
|
|
|
|
||||||||||||||||||||
createUnspecifiedPropertyAssertion(boolean) |
|
|
|
|
|
||||||||||||||||||||
equals(Object) |
|
|
|
|
|
||||||||||||||||||||
hashCode() |
|
|
|
|
|
||||||||||||||||||||
isClassAssertion() |
|
|
|
|
|
||||||||||||||||||||
isInferred() |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
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. </p> <p> Defines just whether the assertion uses inferred values and existing types of
21: * assertions. </p>
22: * <p>
23: * The usage of types may seem as not being very object-oriented, but since the hierarchy is fixed (there aren't any
24: * other kinds of assertions in ontologies) and since the subclasses essentially don't contain any behavior, we can use
25: * this way.
26: *
27: * @author ledvima1
28: */
29: public abstract class Assertion extends NamedResource {
30:
31: private static final long serialVersionUID = 2641835840569464452L;
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: }
47:
48: /**
49: * Whether this assertion is based on inferred values.
50: *
51: * @return True if inferred, false otherwise
52: */
53: public boolean isInferred() {
54: return inferred;
55: }
56:
57: /**
58: * Whether this assertion is a class assertion.
59: * <p>
60: * This is a convenience method, its functionality could be emulated by retrieving this assertion's identifier and
61: * checking whether it equals to the rdf:type URI.
62: *
63: * @return True if this assertion is a class assertion, false otherwise.
64: */
65: public boolean isClassAssertion() {
66: return getIdentifier().equals(ClassAssertion.RDF_TYPE);
67: }
68:
69: /**
70: * Gets type of this assertion.
71: *
72: * @return Assertion type
73: */
74: public abstract AssertionType getType();
75:
76: @Override
77: public int hashCode() {
78: final int prime = 31;
79: int result = super.hashCode();
80:• result = prime * result + (inferred ? 1231 : 1237);
81: return result;
82: }
83:
84: @Override
85: public boolean equals(Object obj) {
86:• if (this == obj)
87: return true;
88:• if (!super.equals(obj))
89: return false;
90:• if (getClass() != obj.getClass())
91: return false;
92: Assertion other = (Assertion) obj;
93:• if (inferred != other.inferred)
94: return false;
95: return true;
96: }
97:
98: @Override
99: public String toString() {
100:• return super.toString() + (inferred ? " - inferred" : " - non-inferred");
101: }
102:
103: /**
104: * Creates new class assertion. </p>
105: * <p>
106: * Class assertions use the rdf:type identifier.
107: *
108: * @param isInferred Whether the assertion uses inferred values
109: * @return Assertion
110: */
111: public static Assertion createClassAssertion(boolean isInferred) {
112: return new ClassAssertion(isInferred);
113: }
114:
115: /**
116: * Creates a property assertion without specifying the assertion identifier. </p>
117: * <p>
118: * Note that the returned instances are all equals as long as their inferred status is the same.
119: *
120: * @param isInferred Whether the assertion uses inferred values
121: * @return Assertion
122: */
123: public static Assertion createUnspecifiedPropertyAssertion(boolean isInferred) {
124: return new PropertyAssertion(isInferred);
125: }
126:
127: /**
128: * Creates new property assertion without specifying what kind of property it is. </p>
129: *
130: * @param assertionIdentifier Assertion identifier
131: * @param isInferred Whether the assertion uses inferred values
132: * @return Assertion
133: */
134: public static Assertion createPropertyAssertion(URI assertionIdentifier, boolean isInferred) {
135: return new PropertyAssertion(assertionIdentifier, isInferred);
136: }
137:
138: /**
139: * Creates new object property assertion.
140: *
141: * @param assertionIdentifier Assertion identifier
142: * @param isInferred Whether the assertion uses inferred values
143: * @return Assertion
144: */
145: public static Assertion createObjectPropertyAssertion(URI assertionIdentifier,
146: boolean isInferred) {
147: return new ObjectPropertyAssertion(assertionIdentifier, isInferred);
148: }
149:
150: /**
151: * Creates new data property assertion.
152: *
153: * @param assertionIdentifier Assertion identifier
154: * @param isInferred Whether the assertion uses inferred values
155: * @return Assertion
156: */
157: public static Assertion createDataPropertyAssertion(URI assertionIdentifier, boolean isInferred) {
158: return new DataPropertyAssertion(assertionIdentifier, isInferred);
159: }
160:
161: /**
162: * Creates new annotation property assertion.
163: *
164: * @param assertionIdentifier Assertion identifier
165: * @param isInferred Whether the assertion uses inferred values
166: * @return Assertion
167: */
168: public static Assertion createAnnotationPropertyAssertion(URI assertionIdentifier,
169: boolean isInferred) {
170: return new AnnotationPropertyAssertion(assertionIdentifier, isInferred);
171: }
172: }