Debian Codegraph @

Source/Reasoner/Ontology/CDataLiteralIRIValue.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CDataLiteralIRIValue.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Ontology {
29
30
31 CDataLiteralIRIValue::CDataLiteralIRIValue() {
32 clearValue();
33 }
34
35
36 CDataLiteralValue::DATA_LITERAL_VALUE_TYPE CDataLiteralIRIValue::getDataValueType() {
37 return CDataLiteralValue::DLVT_IRI;
38 }
39
40
41 CDataLiteralCompareValue* CDataLiteralIRIValue::initValue(CDataLiteralCompareValue* value) {
42 clearValue();
43 CDataLiteralIRIValue* iriValue = dynamic_cast<CDataLiteralIRIValue*>(value);
44 if (iriValue) {
45 mInfiniteLength = iriValue->mInfiniteLength;
46 mLength = iriValue->mLength;
47 mIRIString = iriValue->mIRIString;
48 }
49 return this;
50 }
51
52
53 QString CDataLiteralIRIValue::getValueString() {
54 return mIRIString;
55 }
56
57
58 CDataLiteralIRIValue* CDataLiteralIRIValue::initValueFromInfiniteLength() {
59 clearValue();
60 mInfiniteLength = true;
61 return this;
62 }
63
64 CDataLiteralIRIValue* CDataLiteralIRIValue::initValueFromLength(cuint64 length) {
65 clearValue();
66 mLength = length;
67 return this;
68 }
69
70
71 CDataLiteralIRIValue* CDataLiteralIRIValue::initValueFromIRIString(const QString& iriString) {
72 clearValue();
73 mIRIString = iriString;
74 return this;
75 }
76
77
78 CDataLiteralIRIValue* CDataLiteralIRIValue::initValue(CDataLiteralIRIValue* value) {
79 if (value) {
80 mInfiniteLength = value->mInfiniteLength;
81 mLength = value->mLength;
82 mIRIString = value->mIRIString;
83 }
84 return this;
85 }
86
87
88 CDataLiteralIRIValue* CDataLiteralIRIValue::clearValue() {
89 mInfiniteLength = false;
90 mLength = 0;
91 mIRIString.clear();
92 return this;
93 }
94
95
96 bool CDataLiteralIRIValue::isInfiniteLength() {
97 return mInfiniteLength;
98 }
99
100 cuint64 CDataLiteralIRIValue::getLength() {
101 if (mLength > 0) {
102 return mLength;
103 } else {
104 return mIRIString.length();
105 }
106 }
107
108 QString CDataLiteralIRIValue::getIRIValue() {
109 return mIRIString;
110 }
111
112
113 bool CDataLiteralIRIValue::isEqualTo(CDataLiteralValue* value) {
114 CDataLiteralIRIValue* iriValue = dynamic_cast<CDataLiteralIRIValue*>(value);
115 if (iriValue) {
116 return isEqualTo(iriValue);
117 }
118 return false;
119 }
120
121
122
123 bool CDataLiteralIRIValue::isLessEqualThan(CDataLiteralCompareValue* value) {
124 CDataLiteralIRIValue* iriValue = dynamic_cast<CDataLiteralIRIValue*>(value);
125 if (iriValue) {
126 return isEqualTo(iriValue) || isLessThan(iriValue);
127 }
128 return false;
129 }
130
131 bool CDataLiteralIRIValue::isLessEqualThan(CDataLiteralIRIValue* iriValue) {
132 return isEqualTo(iriValue) || isLessThan(iriValue);
133 }
134
135
136 bool CDataLiteralIRIValue::isEqualTo(CDataLiteralCompareValue* value) {
137 CDataLiteralIRIValue* iriValue = dynamic_cast<CDataLiteralIRIValue*>(value);
138 if (iriValue) {
139 return isEqualTo(iriValue);
140 }
141 return false;
142 }
143
144 bool CDataLiteralIRIValue::isEqualTo(CDataLiteralIRIValue* iriValue) {
145 if (mInfiniteLength && iriValue->mInfiniteLength) {
146 return true;
147 }
148 if (mInfiniteLength || iriValue->mInfiniteLength) {
149 return false;
150 }
151 if (mLength > 0 && mLength == iriValue->mLength) {
152 return true;
153 }
154 if (mIRIString == iriValue->mIRIString) {
155 return true;
156 }
157 return false;
158 }
159
160 bool CDataLiteralIRIValue::isGreaterEqualThan(CDataLiteralIRIValue* iriValue) {
161 return isEqualTo(iriValue) || isGreaterThan(iriValue);
162 }
163
164 bool CDataLiteralIRIValue::isGreaterEqualThan(CDataLiteralCompareValue* value) {
165 CDataLiteralIRIValue* iriValue = dynamic_cast<CDataLiteralIRIValue*>(value);
166 if (iriValue) {
167 return isEqualTo(iriValue) || isGreaterThan(iriValue);
168 }
169 return false;
170 }
171
172 bool CDataLiteralIRIValue::isGreaterThan(CDataLiteralCompareValue* value) {
173 return value->isLessThan(this);
174 }
175
176 bool CDataLiteralIRIValue::isGreaterThan(CDataLiteralIRIValue* iriValue) {
177 return iriValue->isLessThan(this);
178 }
179
180
181 bool CDataLiteralIRIValue::isLessThan(CDataLiteralCompareValue* value) {
182 CDataLiteralIRIValue* iriValue = dynamic_cast<CDataLiteralIRIValue*>(value);
183 if (iriValue) {
184 return isLessThan(iriValue);
185 }
186 return false;
187 }
188
189
190
191
192
193 bool CDataLiteralIRIValue::isLessThan(CDataLiteralIRIValue* iriValue) {
194 if (mInfiniteLength) {
195 return false;
196 }
197 if (!mInfiniteLength && iriValue->mInfiniteLength) {
198 return true;
199 }
200 if (getLength() < iriValue->getLength()) {
201 return true;
202 } else if (getLength() > iriValue->getLength()) {
203 return false;
204 } else {
205 int stringComp = mIRIString.compare(iriValue->mIRIString);
206 if (stringComp < 0) {
207 return true;
208 } else if (stringComp > 0) {
209 return false;
210 }
211 }
212 return false;
213 }
214
215
216
217 }; // end namespace Ontology
218
219 }; // end namespace Reasoner
220
221 }; // end namespace Konclude