| 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 |
#ifndef KONCLUDE_REASONER_QUERY_CSTRINGHIERARCHYRESULT_CPP |
| 21 |
#define KONCLUDE_REASONER_QUERY_CSTRINGHIERARCHYRESULT_CPP |
| 22 |
|
| 23 |
|
| 24 |
#include "CStringHierarchyResult.h" |
| 25 |
|
| 26 |
|
| 27 |
namespace Konclude { |
| 28 |
|
| 29 |
namespace Reasoner { |
| 30 |
|
| 31 |
namespace Query { |
| 32 |
|
| 33 |
|
| 34 |
template<class T, class R, class E> |
| 35 |
CStringHierarchyResult<T,R,E>::CStringHierarchyResult() { |
| 36 |
mBottomString = 0; |
| 37 |
mTopString = 0; |
| 38 |
} |
| 39 |
|
| 40 |
template<class T, class R, class E> |
| 41 |
CStringHierarchyResult<T,R,E>::CStringHierarchyResult(const QString &bottomHierarchyString, const QString &topHierarchyString) { |
| 42 |
mTopString = getStringSynset(topHierarchyString); |
| 43 |
mBottomString = getStringSynset(bottomHierarchyString); |
| 44 |
} |
| 45 |
|
| 46 |
template<class T, class R, class E> |
| 47 |
CStringHierarchyResult<T,R,E>::CStringHierarchyResult(const QStringList &bottomHierarchyStrings, const QStringList &topHierarchyStrings) { |
| 48 |
mTopString = getStringSynset(topHierarchyStrings); |
| 49 |
mBottomString = getStringSynset(bottomHierarchyStrings); |
| 50 |
} |
| 51 |
|
| 52 |
template<class T, class R, class E> |
| 53 |
CStringHierarchyResult<T,R,E>::CStringHierarchyResult(E *takeBottomStringSynset, E *takeTopStringSynset) { |
| 54 |
mTopString = takeTopStringSynset; |
| 55 |
mBottomString = takeBottomStringSynset; |
| 56 |
foreach (QString stringName, mTopString->getEquivalentStringNameList()) { |
| 57 |
mStringStringSynsetHash.insert(stringName,mTopString); |
| 58 |
} |
| 59 |
mStringSynsetContainer.append(mTopString); |
| 60 |
foreach (QString stringName, mBottomString->getEquivalentStringNameList()) { |
| 61 |
mStringStringSynsetHash.insert(stringName,mBottomString); |
| 62 |
} |
| 63 |
mStringSynsetContainer.append(mBottomString); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
template<class T, class R, class E> |
| 68 |
CStringHierarchyResult<T,R,E>::CStringHierarchyResult(E *takeBottomStringSynset) { |
| 69 |
mTopString = nullptr; |
| 70 |
mBottomString = takeBottomStringSynset; |
| 71 |
foreach (QString stringName, mBottomString->getEquivalentStringNameList()) { |
| 72 |
mStringStringSynsetHash.insert(stringName,mBottomString); |
| 73 |
} |
| 74 |
mStringSynsetContainer.append(mBottomString); |
| 75 |
} |
| 76 |
|
| 77 |
template<class T, class R, class E> |
| 78 |
CStringHierarchyResult<T,R,E>::~CStringHierarchyResult() { |
| 79 |
qDeleteAll(mStringSynsetContainer); |
| 80 |
qDeleteAll(mSubStringRelationContainer); |
| 81 |
} |
| 82 |
|
| 83 |
template<class T, class R, class E> |
| 84 |
E *CStringHierarchyResult<T,R,E>::getBottomStringSynset() { |
| 85 |
return mBottomString; |
| 86 |
} |
| 87 |
|
| 88 |
template<class T, class R, class E> |
| 89 |
E *CStringHierarchyResult<T,R,E>::getTopStringSynset() { |
| 90 |
return mTopString; |
| 91 |
} |
| 92 |
|
| 93 |
template<class T, class R, class E> |
| 94 |
E *CStringHierarchyResult<T,R,E>::getStringSynset(const QString &stringName, bool create) { |
| 95 |
E *stringSynset = mStringStringSynsetHash.value(stringName,0); |
| 96 |
if (!stringSynset && create) { |
| 97 |
stringSynset = new E(stringName); |
| 98 |
mStringStringSynsetHash.insert(stringName,stringSynset); |
| 99 |
mStringSynsetContainer.append(stringSynset); |
| 100 |
} |
| 101 |
return stringSynset; |
| 102 |
} |
| 103 |
|
| 104 |
template<class T, class R, class E> |
| 105 |
E *CStringHierarchyResult<T,R,E>::getStringSynset(const QStringList &stringNames, bool create) { |
| 106 |
E *stringSynset = 0; |
| 107 |
if (!stringNames.isEmpty()) { |
| 108 |
stringSynset = mStringStringSynsetHash.value(stringNames.first(),0); |
| 109 |
if (!stringSynset && create) { |
| 110 |
stringSynset = new E(stringNames); |
| 111 |
foreach (QString stringName, stringNames) { |
| 112 |
mStringStringSynsetHash.insert(stringName,stringSynset); |
| 113 |
} |
| 114 |
mStringSynsetContainer.append(stringSynset); |
| 115 |
} |
| 116 |
} |
| 117 |
return stringSynset; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
template<class T, class R, class E> |
| 122 |
E *CStringHierarchyResult<T,R,E>::setTopStringSynset(E *stringSynset) { |
| 123 |
mTopString = stringSynset; |
| 124 |
return stringSynset; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
template<class T, class R, class E> |
| 129 |
E *CStringHierarchyResult<T,R,E>::addStringSynset(E *takeStringSynset) { |
| 130 |
foreach (QString stringName, takeStringSynset->getEquivalentStringNameList()) { |
| 131 |
mStringStringSynsetHash.insert(stringName,takeStringSynset); |
| 132 |
} |
| 133 |
mStringSynsetContainer.append(takeStringSynset); |
| 134 |
return takeStringSynset; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
template<class T, class R, class E> |
| 139 |
R *CStringHierarchyResult<T,R,E>::addSubStringRelation(E *superStringSynset, E *anySubStringSynset) { |
| 140 |
R *subStringRelation = mStringSynsetSubStringHash.value(superStringSynset,0); |
| 141 |
if (!subStringRelation) { |
| 142 |
subStringRelation = new R(superStringSynset); |
| 143 |
mSubStringRelationContainer.append(subStringRelation); |
| 144 |
mStringSynsetSubStringHash.insert(superStringSynset,subStringRelation); |
| 145 |
} |
| 146 |
if (!subStringRelation->hasSubStringsSynset(anySubStringSynset)) { |
| 147 |
subStringRelation->addSubStringsSynset(anySubStringSynset); |
| 148 |
} |
| 149 |
return subStringRelation; |
| 150 |
} |
| 151 |
|
| 152 |
template<class T, class R, class E> |
| 153 |
R *CStringHierarchyResult<T,R,E>::getSubStringRelation(E *superStringSynset, bool create) { |
| 154 |
R *subStringRelation = mStringSynsetSubStringHash.value(superStringSynset,0); |
| 155 |
if (!subStringRelation && create) { |
| 156 |
subStringRelation = new R(superStringSynset); |
| 157 |
mSubStringRelationContainer.append(subStringRelation); |
| 158 |
mStringSynsetSubStringHash.insert(superStringSynset,subStringRelation); |
| 159 |
} |
| 160 |
return subStringRelation; |
| 161 |
} |
| 162 |
|
| 163 |
template<class T, class R, class E> |
| 164 |
QString CStringHierarchyResult<T,R,E>::getQueryResultString() { |
| 165 |
QString string; |
| 166 |
return string; |
| 167 |
} |
| 168 |
|
| 169 |
template<class T, class R, class E> |
| 170 |
CTaxonomy *CStringHierarchyResult<T,R,E>::fillTaxonomy(CConcreteOntology *ontology, CTaxonomy *taxonomy) { |
| 171 |
bool completeMapping = true; |
| 172 |
CMAPPINGHASH<CStringRefStringHasher, CConcept *> *stringConceptHash = ontology->getStringMapping()->getClassNameConceptMappingHash(false); |
| 173 |
if (stringConceptHash) { |
| 174 |
QStringList bottomStringList(mBottomString->getEquivalentStringNameList()); |
| 175 |
foreach (QString bottomStringString, bottomStringList) { |
| 176 |
CConcept *unsatCon = stringConceptHash->value(bottomStringString,0); |
| 177 |
if (unsatCon) { |
| 178 |
if (!taxonomy->isSatisfiable(unsatCon) && !taxonomy->isNotSatisfiable(unsatCon)) { |
| 179 |
taxonomy->setConceptSatisfiable(unsatCon,false); |
| 180 |
} |
| 181 |
} else { |
| 182 |
completeMapping = false; |
| 183 |
} |
| 184 |
} |
| 185 |
QList<E *> updateStringSynList; |
| 186 |
QSet<E *> updateStringSynSet; |
| 187 |
updateStringSynList.append(mTopString); |
| 188 |
while (!updateStringSynList.isEmpty()) { |
| 189 |
E *stringSynset = updateStringSynList.takeFirst(); |
| 190 |
QStringList stringNameList(stringSynset->getEquivalentStringNameList()); |
| 191 |
CConcept *firstSatCon = 0; |
| 192 |
foreach (QString stringName, stringNameList) { |
| 193 |
CConcept *satConcept = stringConceptHash->value(stringName,0); |
| 194 |
if (satConcept) { |
| 195 |
if (!taxonomy->isSatisfiable(satConcept) && !taxonomy->isNotSatisfiable(satConcept)) { |
| 196 |
taxonomy->setConceptSatisfiable(satConcept,true); |
| 197 |
} |
| 198 |
if (firstSatCon) { |
| 199 |
if (!taxonomy->isSubsumption(firstSatCon,satConcept) && !taxonomy->isNotSubsumption(firstSatCon,satConcept)) { |
| 200 |
taxonomy->setConceptSubsumption(firstSatCon,satConcept); |
| 201 |
} |
| 202 |
if (!taxonomy->isSubsumption(satConcept,firstSatCon) && !taxonomy->isNotSubsumption(satConcept,firstSatCon)) { |
| 203 |
taxonomy->setConceptSubsumption(satConcept,firstSatCon); |
| 204 |
} |
| 205 |
} |
| 206 |
if (!firstSatCon) { |
| 207 |
firstSatCon = satConcept; |
| 208 |
} |
| 209 |
} else { |
| 210 |
completeMapping = false; |
| 211 |
} |
| 212 |
} |
| 213 |
R *subStringRelation = mStringSynsetSubStringHash.value(stringSynset); |
| 214 |
if (subStringRelation) { |
| 215 |
QSet<E *>* subStringSet(subStringRelation->getSubStringsSynsetSet()); |
| 216 |
foreach (E *subStringSynset, *subStringSet) { |
| 217 |
CConcept *con = 0; |
| 218 |
foreach (QString substringName, subStringSynset->getEquivalentStringNameList()) { |
| 219 |
con = stringConceptHash->value(substringName,0); |
| 220 |
if (con) { |
| 221 |
if (!taxonomy->isSatisfiable(con) && !taxonomy->isNotSatisfiable(con)) { |
| 222 |
taxonomy->setConceptSatisfiable(con,true); |
| 223 |
} |
| 224 |
break; |
| 225 |
} |
| 226 |
} |
| 227 |
if (con) { |
| 228 |
if (!taxonomy->isSubsumption(con,firstSatCon) && !taxonomy->isNotSubsumption(con,firstSatCon)) { |
| 229 |
taxonomy->setConceptSubsumption(con,firstSatCon); |
| 230 |
} |
| 231 |
if (!updateStringSynSet.contains(subStringSynset)) { |
| 232 |
updateStringSynSet.insert(subStringSynset); |
| 233 |
updateStringSynList.append(subStringSynset); |
| 234 |
} |
| 235 |
} else { |
| 236 |
completeMapping = false; |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
return taxonomy; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
template<class T, class R, class E> |
| 247 |
void CStringHierarchyResult<T,R,E>::compareSubsumersCount(QHash<QString,QString>* subsumHash1, QHash<QString,QString>* subsumHash2) { |
| 248 |
cint64 totalStringDiffCount = 0; |
| 249 |
cint64 totalStringAddCount = 0; |
| 250 |
cint64 totalStringMissCount = 0; |
| 251 |
cint64 totalAddCount = 0; |
| 252 |
cint64 totalMissCount = 0; |
| 253 |
foreach (const QString& stringName, subsumHash1->uniqueKeys()) { |
| 254 |
QList<QString> stringSuperSynSets1(subsumHash1->values(stringName)); |
| 255 |
QList<QString> stringSuperSynSets2(subsumHash2->values(stringName)); |
| 256 |
|
| 257 |
cint64 missingCount = 0; |
| 258 |
cint64 additionalCount = 0; |
| 259 |
foreach (const QString& supsumerStringName, stringSuperSynSets1) { |
| 260 |
if (!stringSuperSynSets2.contains(supsumerStringName)) { |
| 261 |
++missingCount; |
| 262 |
} |
| 263 |
} |
| 264 |
cint64 diffCount = stringSuperSynSets2.count() - stringSuperSynSets1.count(); |
| 265 |
if (diffCount != 0 || missingCount > 0) { |
| 266 |
foreach (const QString& supsumerStringName, stringSuperSynSets2) { |
| 267 |
if (!stringSuperSynSets1.contains(supsumerStringName)) { |
| 268 |
++additionalCount; |
| 269 |
} |
| 270 |
} |
| 271 |
} |
| 272 |
if (additionalCount > 0) { |
| 273 |
++totalStringAddCount; |
| 274 |
totalAddCount += additionalCount; |
| 275 |
} |
| 276 |
if (missingCount > 0) { |
| 277 |
++totalStringMissCount; |
| 278 |
totalMissCount += missingCount; |
| 279 |
} |
| 280 |
if (additionalCount > 0 || missingCount > 0) { |
| 281 |
++totalStringDiffCount; |
| 282 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("'%1' has %2 additional and %3 missing subsumers.").arg(stringName).arg(additionalCount).arg(missingCount),this); |
| 283 |
} |
| 284 |
} |
| 285 |
if (totalStringDiffCount != 0) { |
| 286 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("%1 with additional subsumers, %2 with missing subsumers, overall %3 different.").arg(totalStringAddCount).arg(totalStringMissCount).arg(totalStringDiffCount),this); |
| 287 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Overall %1 additional subsumers, %2 missing subsumers.").arg(totalAddCount).arg(totalMissCount),this); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
template<class T, class R, class E> |
| 293 |
void CStringHierarchyResult<T,R,E>::collectSubsumerStringSynsets(CStringHierarchyResult *stringHierarchy, QHash<QString,QString>* subsumHash, QSet< QPair<QString,QString> >* subsumSet) { |
| 294 |
|
| 295 |
QSet< QPair<QString,QString> >* delSubsumSet = nullptr; |
| 296 |
if (!subsumSet) { |
| 297 |
delSubsumSet = new QSet< QPair<QString,QString> >(); |
| 298 |
subsumSet = delSubsumSet; |
| 299 |
} |
| 300 |
|
| 301 |
QList<E*> allStringList; |
| 302 |
QSet<E*> allStringSet; |
| 303 |
QSet<E*> currStringSet; |
| 304 |
E* topStringSynset = stringHierarchy->getTopStringSynset(); |
| 305 |
allStringList.append(topStringSynset); |
| 306 |
allStringSet.insert(topStringSynset); |
| 307 |
currStringSet.insert(topStringSynset); |
| 308 |
|
| 309 |
while (!allStringList.isEmpty()) { |
| 310 |
E* stringSynset = allStringList.takeFirst(); |
| 311 |
R* subStringSynsetRel = stringHierarchy->getSubStringRelation(stringSynset,false); |
| 312 |
|
| 313 |
QList<QString> superStringList; |
| 314 |
foreach (const QString& stringName1, stringSynset->getEquivalentStringNameList()) { |
| 315 |
foreach (const QString& stringName2, stringSynset->getEquivalentStringNameList()) { |
| 316 |
QPair<QString,QString> selfSubSumPair(stringName1,stringName2); |
| 317 |
if (!subsumSet->contains(selfSubSumPair)) { |
| 318 |
subsumSet->insert(selfSubSumPair); |
| 319 |
subsumHash->insertMulti(stringName1,stringName2); |
| 320 |
} |
| 321 |
|
| 322 |
QList<QString> tmpSuperStringList(subsumHash->values(stringName2)); |
| 323 |
foreach (const QString& stringName3, tmpSuperStringList) { |
| 324 |
QPair<QString,QString> subSumPair(stringName1,stringName3); |
| 325 |
if (!subsumSet->contains(subSumPair)) { |
| 326 |
subsumSet->insert(subSumPair); |
| 327 |
subsumHash->insertMulti(stringName1,stringName3); |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
if (superStringList.isEmpty()) { |
| 332 |
superStringList.append(subsumHash->values(stringName1)); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
if (subStringSynsetRel) { |
| 337 |
foreach (E* subStringSynset, *subStringSynsetRel->getSubStringsSynsetSet()) { |
| 338 |
|
| 339 |
QList<QString> subStringList(subStringSynset->getEquivalentStringNameList()); |
| 340 |
|
| 341 |
allStringList.append(subStringSynset); |
| 342 |
|
| 343 |
|
| 344 |
foreach (const QString& stringName1, subStringList) { |
| 345 |
foreach (const QString& stringName2, subStringList) { |
| 346 |
QPair<QString,QString> selfSubSumPair(stringName1,stringName2); |
| 347 |
if (!subsumSet->contains(selfSubSumPair)) { |
| 348 |
subsumSet->insert(selfSubSumPair); |
| 349 |
subsumHash->insertMulti(stringName1,stringName2); |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
foreach (const QString& stringName1, subStringList) { |
| 355 |
foreach (const QString& stringName2, superStringList) { |
| 356 |
QPair<QString,QString> subSumPair(stringName1,stringName2); |
| 357 |
if (!subsumSet->contains(subSumPair)) { |
| 358 |
subsumSet->insert(subSumPair); |
| 359 |
subsumHash->insertMulti(stringName1,stringName2); |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
delete delSubsumSet; |
| 367 |
} |
| 368 |
|
| 369 |
template<class T, class R, class E> |
| 370 |
bool CStringHierarchyResult<T,R,E>::isResultEquivalentTo(CQueryResult *otherQueryResult) { |
| 371 |
if (!otherQueryResult) { |
| 372 |
return false; |
| 373 |
} |
| 374 |
T *otherStringHierarchy = dynamic_cast<T *>(otherQueryResult); |
| 375 |
if (!otherStringHierarchy) { |
| 376 |
return false; |
| 377 |
} |
| 378 |
bool wrongResult = false; |
| 379 |
if (!mBottomString->isResultEquivalentTo(otherStringHierarchy->getBottomStringSynset())) { |
| 380 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Bottom synset does not match."),this); |
| 381 |
wrongResult = true; |
| 382 |
} |
| 383 |
if (mTopString && !otherStringHierarchy->getTopStringSynset() || !mTopString && otherStringHierarchy->getTopStringSynset()) { |
| 384 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Top synset does not match."),this); |
| 385 |
return false; |
| 386 |
} |
| 387 |
if (!mTopString) { |
| 388 |
return !wrongResult; |
| 389 |
} |
| 390 |
if (!mTopString->isResultEquivalentTo(otherStringHierarchy->getTopStringSynset())) { |
| 391 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Top synset does not match."),this); |
| 392 |
return false; |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
#ifndef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 399 |
//QHash<QString,QString> subsumHash1; |
| 400 |
//QHash<QString,QString> subsumHash2; |
| 401 |
//QSet< QPair<QString,QString> > subsumSet1; |
| 402 |
//QSet< QPair<QString,QString> > subsumSet2; |
| 403 |
//collectSubsumerStringSynsets(this,&subsumHash1,&subsumSet1); |
| 404 |
//collectSubsumerStringSynsets(otherStringHierarchy,&subsumHash2,&subsumSet2); |
| 405 |
//compareSubsumersCount(&subsumHash1,&subsumHash2); |
| 406 |
#endif |
| 407 |
|
| 408 |
E* topStringSynset = otherStringHierarchy->getTopStringSynset(); |
| 409 |
QList<E *> testStringList; |
| 410 |
QList<E *> otherStringList; |
| 411 |
QSet<E *> testStringSet; |
| 412 |
testStringList.append(mTopString); |
| 413 |
otherStringList.append(topStringSynset); |
| 414 |
testStringSet.insert(mTopString); |
| 415 |
while (!testStringList.isEmpty()) { |
| 416 |
E *stringSynset = testStringList.takeFirst(); |
| 417 |
E *otherStringSynset = otherStringList.takeFirst(); |
| 418 |
R *subStringRelation = getSubStringRelation(stringSynset,false); |
| 419 |
R *otherSubStringRelation = otherStringHierarchy->getSubStringRelation(otherStringSynset,false); |
| 420 |
|
| 421 |
if (!subStringRelation && otherSubStringRelation || subStringRelation && !otherSubStringRelation) { |
| 422 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Sub relations of '%1' do not match.").arg(stringSynset->getEquivalentStringNameList().join(", ")),this); |
| 423 |
return false; |
| 424 |
} |
| 425 |
|
| 426 |
if (subStringRelation) { |
| 427 |
|
| 428 |
if (subStringRelation->getSubStringsSynsetCount() != otherSubStringRelation->getSubStringsSynsetCount()) { |
| 429 |
wrongResult = true; |
| 430 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Sub relations of '%1' do not match.").arg(stringSynset->getEquivalentStringNameList().join(", ")),this); |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
if (subStringRelation->getSubStringsSynsetCount() < 20) { |
| 435 |
QList<E *> otherSubStringList(otherSubStringRelation->getSubStringsSynsetList()); |
| 436 |
foreach (E *stringSynset, subStringRelation->getSubStringsSynsetList()) { |
| 437 |
bool contained = false; |
| 438 |
E *accSubStringSynset = stringSynset; |
| 439 |
|
| 440 |
for (qint64 cnt = otherSubStringList.count(); cnt > 0; --cnt) { |
| 441 |
E *accOtherSubStringSynset = otherSubStringList.first(); |
| 442 |
if (!accOtherSubStringSynset) { |
| 443 |
wrongResult = true; |
| 444 |
break; |
| 445 |
} else { |
| 446 |
contained |= accOtherSubStringSynset->isResultEquivalentTo(stringSynset); |
| 447 |
if (contained) { |
| 448 |
otherSubStringList.takeFirst(); |
| 449 |
|
| 450 |
if (!testStringSet.contains(accSubStringSynset)) { |
| 451 |
testStringSet.insert(accSubStringSynset); |
| 452 |
testStringList.append(accSubStringSynset); |
| 453 |
otherStringList.append(accOtherSubStringSynset); |
| 454 |
} |
| 455 |
|
| 456 |
break; |
| 457 |
} else { |
| 458 |
otherSubStringList.append(otherSubStringList.takeFirst()); |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
if (!contained) { |
| 463 |
wrongResult = true; |
| 464 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Could not find corresponding sub synset '%1' of super synset '%2'.").arg(stringSynset->getEquivalentStringNameList().join(", ")).arg(otherStringSynset->getEquivalentStringNameList().join(", ")),this); |
| 465 |
|
| 466 |
} |
| 467 |
} |
| 468 |
} else { |
| 469 |
QList<E *> otherSubStringList(otherSubStringRelation->getSubStringsSynsetList()); |
| 470 |
QHash<QString,E*> otherSubStringHash; |
| 471 |
foreach (E* otherStringSynset, otherSubStringList) { |
| 472 |
foreach (const QString& stringName ,otherStringSynset->getEquivalentStringNameList()) { |
| 473 |
otherSubStringHash.insert(stringName,otherStringSynset); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
foreach (E *stringSynset, subStringRelation->getSubStringsSynsetList()) { |
| 478 |
bool contained = false; |
| 479 |
E *accSubStringSynset = stringSynset; |
| 480 |
|
| 481 |
E *accOtherSubStringSynset = otherSubStringHash.value(accSubStringSynset->getEquivalentStringNameList().first()); |
| 482 |
if (!accOtherSubStringSynset || !accOtherSubStringSynset->isResultEquivalentTo(stringSynset)) { |
| 483 |
wrongResult = true; |
| 484 |
LOG(ERROR,"::Konclude::Reasoner::Query::StringHierarchyResult",logTr("Could not find corresponding sub synset '%1' of super synset '%2'.").arg(stringSynset->getEquivalentStringNameList().join(", ")).arg(otherStringSynset->getEquivalentStringNameList().join(", ")),this); |
| 485 |
|
| 486 |
} else if (accOtherSubStringSynset) { |
| 487 |
foreach (const QString& stringName ,accOtherSubStringSynset->getEquivalentStringNameList()) { |
| 488 |
otherSubStringHash.insert(stringName,nullptr); |
| 489 |
} |
| 490 |
contained = true; |
| 491 |
} |
| 492 |
|
| 493 |
if (contained) { |
| 494 |
if (!testStringSet.contains(accSubStringSynset)) { |
| 495 |
testStringSet.insert(accSubStringSynset); |
| 496 |
testStringList.append(accSubStringSynset); |
| 497 |
otherStringList.append(accOtherSubStringSynset); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
} |
| 502 |
} |
| 503 |
} |
| 504 |
} |
| 505 |
return !wrongResult; |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
}; // end namespace Query |
| 510 |
|
| 511 |
}; // end namespace Reasoner |
| 512 |
|
| 513 |
}; // end namespace Konclude |
| 514 |
|
| 515 |
#endif // KONCLUDE_REASONER_QUERY_CSTRINGHIERARCHYRESULT_CPP |