| 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 |
#ifndef KONCLUDE_REASONER_QUERY_CSTRINGSUBSTRINGSRELATIONRESULT_CPP |
| 22 |
#define KONCLUDE_REASONER_QUERY_CSTRINGSUBSTRINGSRELATIONRESULT_CPP |
| 23 |
|
| 24 |
|
| 25 |
#include "CStringSubStringsRelationResult.h" |
| 26 |
|
| 27 |
|
| 28 |
namespace Konclude { |
| 29 |
|
| 30 |
namespace Reasoner { |
| 31 |
|
| 32 |
namespace Query { |
| 33 |
|
| 34 |
|
| 35 |
template<class T, class E> |
| 36 |
CStringSubStringsRelationResult<T,E>::CStringSubStringsRelationResult() { |
| 37 |
mSuperString = 0; |
| 38 |
} |
| 39 |
|
| 40 |
template<class T, class E> |
| 41 |
CStringSubStringsRelationResult<T,E>::CStringSubStringsRelationResult(E *superStringSynset) { |
| 42 |
mSuperString = superStringSynset; |
| 43 |
} |
| 44 |
|
| 45 |
template<class T, class E> |
| 46 |
CStringSubStringsRelationResult<T,E>::~CStringSubStringsRelationResult() { |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
template<class T, class E> |
| 51 |
E* CStringSubStringsRelationResult<T,E>::getSuperStringSynset() { |
| 52 |
return mSuperString; |
| 53 |
} |
| 54 |
|
| 55 |
template<class T, class E> |
| 56 |
T *CStringSubStringsRelationResult<T,E>::setSuperStringSynset(E* superStringSynset) { |
| 57 |
mSuperString = superStringSynset; |
| 58 |
return (T*)this; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
template<class T, class E> |
| 63 |
QSet<E*>* CStringSubStringsRelationResult<T,E>::getSubStringsSynsetSet() { |
| 64 |
return &mSubStringSynsetSet; |
| 65 |
} |
| 66 |
|
| 67 |
template<class T, class E> |
| 68 |
QList<E*> CStringSubStringsRelationResult<T,E>::getSubStringsSynsetList() { |
| 69 |
return mSubStringSynsetSet.toList(); |
| 70 |
} |
| 71 |
|
| 72 |
template<class T, class E> |
| 73 |
T *CStringSubStringsRelationResult<T,E>::addSubStringsSynset(E *subStringSynset) { |
| 74 |
mSubStringSynsetSet.insert(subStringSynset); |
| 75 |
return (T*)this; |
| 76 |
} |
| 77 |
|
| 78 |
template<class T, class E> |
| 79 |
T *CStringSubStringsRelationResult<T,E>::addSubStringsSynsets(const QList<E*> &subStringsSynsets) { |
| 80 |
foreach (E* stringSynRes, subStringsSynsets) { |
| 81 |
mSubStringSynsetSet.insert(stringSynRes); |
| 82 |
} |
| 83 |
return (T*)this; |
| 84 |
} |
| 85 |
|
| 86 |
template<class T, class E> |
| 87 |
qint64 CStringSubStringsRelationResult<T,E>::getSubStringsSynsetCount() { |
| 88 |
return mSubStringSynsetSet.count(); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
template<class T, class E> |
| 93 |
bool CStringSubStringsRelationResult<T,E>::hasSubStringsSynset(E *subStringSynset) { |
| 94 |
return mSubStringSynsetSet.contains(subStringSynset); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
template<class T, class E> |
| 99 |
QString CStringSubStringsRelationResult<T,E>::getQueryResultString(const QString& typeStringName) { |
| 100 |
QString string; |
| 101 |
if (mSuperString && getSubStringsSynsetCount() > 0) { |
| 102 |
string += mSuperString->getQueryResultString(); |
| 103 |
} |
| 104 |
if (!string.isEmpty()) { |
| 105 |
QString subStringString; |
| 106 |
foreach (E *subStringSynset, mSubStringSynsetSet) { |
| 107 |
if (subStringString.isEmpty()) { |
| 108 |
subStringString += QString(" has Sub-%1-Relation to %2").arg(typeStringName).arg(subStringSynset->getQueryResultString()); |
| 109 |
} else { |
| 110 |
subStringString += QString(" and to %1").arg(subStringSynset->getQueryResultString()); |
| 111 |
} |
| 112 |
} |
| 113 |
string += subStringString; |
| 114 |
} |
| 115 |
return string; |
| 116 |
} |
| 117 |
|
| 118 |
template<class T, class E> |
| 119 |
bool CStringSubStringsRelationResult<T,E>::isResultEquivalentTo(CQueryResult *otherQueryResult) { |
| 120 |
if (!otherQueryResult) { |
| 121 |
return false; |
| 122 |
} |
| 123 |
T *otherSubClassRelation = dynamic_cast<T *>(otherQueryResult); |
| 124 |
if (!otherSubClassRelation) { |
| 125 |
return false; |
| 126 |
} |
| 127 |
if (!mSuperString->isResultEquivalentTo(otherSubClassRelation->getSuperStringSynset())) { |
| 128 |
return false; |
| 129 |
} |
| 130 |
QList<E *> otherSubStringList(otherSubClassRelation->getSubStringsSynsetList()); |
| 131 |
foreach (E *stringSynset, otherSubStringList) { |
| 132 |
bool contained = false; |
| 133 |
for (qint64 cnt = otherSubStringList.count(); cnt > 0; --cnt) { |
| 134 |
contained |= otherSubStringList.first()->isResultEquivalentTo(stringSynset); |
| 135 |
if (contained) { |
| 136 |
otherSubStringList.takeFirst(); |
| 137 |
break; |
| 138 |
} else { |
| 139 |
otherSubStringList.append(otherSubStringList.takeFirst()); |
| 140 |
} |
| 141 |
} |
| 142 |
if (!contained) { |
| 143 |
return false; |
| 144 |
} |
| 145 |
} |
| 146 |
return true; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
}; // end namespace Query |
| 152 |
|
| 153 |
}; // end namespace Reasoner |
| 154 |
|
| 155 |
}; // end namespace Konclude |
| 156 |
|
| 157 |
#endif // KONCLUDE_REASONER_QUERY_CSTRINGSUBSTRINGSRELATIONRESULT_CPP |