Debian Codegraph @

Source/Reasoner/Query/CStringSynsetsResult.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 #ifndef KONCLUDE_REASONER_QUERY_CSTRINGSYNSETSRESULT_CPP
22 #define KONCLUDE_REASONER_QUERY_CSTRINGSYNSETSRESULT_CPP
23
24
25 #include "CStringSynsetsResult.h"
26
27
28 namespace Konclude {
29
30 namespace Reasoner {
31
32 namespace Query {
33
34
35 template<class T, class E>
36 CStringSynsetsResult<T,E>::CStringSynsetsResult() {
37 }
38
39
40
41 template<class T, class E>
42 CStringSynsetsResult<T,E>::~CStringSynsetsResult() {
43 qDeleteAll(mStringSynsetContainer);
44 }
45
46
47 template<class T, class E>
48 E *CStringSynsetsResult<T,E>::getStringSynset(const QString &stringName, bool create) {
49 E *stringSynset = mStringStringSynsetHash.value(stringName,0);
50 if (!stringSynset && create) {
51 stringSynset = new E(stringName);
52 mStringStringSynsetHash.insert(stringName,stringSynset);
53 mStringSynsetContainer.append(stringSynset);
54 }
55 return stringSynset;
56 }
57
58 template<class T, class E>
59 E *CStringSynsetsResult<T,E>::getStringSynset(const QStringList &stringNames, bool create) {
60 E *stringSynset = 0;
61 if (!stringNames.isEmpty()) {
62 stringSynset = mStringStringSynsetHash.value(stringNames.first(),0);
63 if (!stringSynset && create) {
64 stringSynset = new E(stringNames);
65 foreach (QString stringName, stringNames) {
66 mStringStringSynsetHash.insert(stringName,stringSynset);
67 }
68 mStringSynsetContainer.append(stringSynset);
69 }
70 }
71 return stringSynset;
72 }
73
74 template<class T, class E>
75 E *CStringSynsetsResult<T,E>::addStringSynset(E *takeStringSynset) {
76 foreach (QString stringName, takeStringSynset->getEquivalentStringNameList()) {
77 mStringStringSynsetHash.insert(stringName,takeStringSynset);
78 }
79 mStringSynsetContainer.append(takeStringSynset);
80 return takeStringSynset;
81 }
82
83 template<class T, class E>
84 QList<E*>* CStringSynsetsResult<T,E>::getStringSynsetList() {
85 return &mStringSynsetContainer;
86 }
87
88
89 template<class T, class E>
90 QString CStringSynsetsResult<T,E>::getQueryResultString() {
91 QString string;
92 return string;
93 }
94
95
96 template<class T, class E>
97 bool CStringSynsetsResult<T,E>::isResultEquivalentTo(CQueryResult *otherQueryResult) {
98 if (!otherQueryResult) {
99 return false;
100 }
101 T *otherStringSynsets = dynamic_cast<T *>(otherQueryResult);
102 if (!otherStringSynsets) {
103 return false;
104 }
105
106 if (mStringStringSynsetHash.count() != otherStringSynsets->mStringStringSynsetHash.count()) {
107 return false;
108 }
109
110 for (typename QList<E*>::const_iterator it = mStringSynsetContainer.constBegin(), itEnd = mStringSynsetContainer.constEnd(); it != itEnd; ++it) {
111 E* stringSynRes(*it);
112 E* otherStringSynRes = nullptr;
113 QStringList stringNameList(stringSynRes->getEquivalentStringNameList());
114 if (!stringNameList.isEmpty()) {
115 const QString& className = stringNameList.first();
116 otherStringSynRes = otherStringSynsets->mStringStringSynsetHash.value(className);
117 }
118 if (!otherStringSynRes && !stringNameList.isEmpty()) {
119 return false;
120 }
121 if (!stringSynRes->isResultEquivalentTo(otherStringSynRes)) {
122 return false;
123 }
124 }
125 return true;
126 }
127
128
129 }; // end namespace Query
130
131 }; // end namespace Reasoner
132
133 }; // end namespace Konclude
134
135 #endif // KONCLUDE_REASONER_QUERY_CSTRINGSYNSETSRESULT_CPP