| 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 "CHierarchyNode.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Taxonomy { |
| 29 |
|
| 30 |
|
| 31 |
CHierarchyNode::CHierarchyNode(CConcept *representiveConcept) { |
| 32 |
eqConList.append(representiveConcept); |
| 33 |
eqConCount = 1; |
| 34 |
active = true; |
| 35 |
mention = false; |
| 36 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 37 |
generateNodeStrings(); |
| 38 |
#endif |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
CHierarchyNode::~CHierarchyNode() { |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
CHierarchyNode *CHierarchyNode::addParentNode(CHierarchyNode *parentNode) { |
| 47 |
parentNodeSet.insert(parentNode); |
| 48 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 49 |
generateNodeStrings(); |
| 50 |
#endif |
| 51 |
return this; |
| 52 |
} |
| 53 |
|
| 54 |
CHierarchyNode *CHierarchyNode::addChildNode(CHierarchyNode *childNode) { |
| 55 |
childNodeSet.insert(childNode); |
| 56 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 57 |
generateNodeStrings(); |
| 58 |
#endif |
| 59 |
return this; |
| 60 |
} |
| 61 |
|
| 62 |
CHierarchyNode *CHierarchyNode::makeParent(CHierarchyNode *parentNode) { |
| 63 |
addParentNode(parentNode); |
| 64 |
parentNode->addChildNode(this); |
| 65 |
makePredecessor(parentNode); |
| 66 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 67 |
generateNodeStrings(); |
| 68 |
#endif |
| 69 |
return this; |
| 70 |
} |
| 71 |
|
| 72 |
CHierarchyNode *CHierarchyNode::makeChild(CHierarchyNode *childNode) { |
| 73 |
childNodeSet.insert(childNode); |
| 74 |
childNode->addParentNode(this); |
| 75 |
makeSuccessor(childNode); |
| 76 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 77 |
generateNodeStrings(); |
| 78 |
#endif |
| 79 |
return this; |
| 80 |
} |
| 81 |
|
| 82 |
bool CHierarchyNode::hasChildNode(CHierarchyNode *node) { |
| 83 |
return childNodeSet.contains(node); |
| 84 |
} |
| 85 |
|
| 86 |
bool CHierarchyNode::hasParentNode(CHierarchyNode *node) { |
| 87 |
return parentNodeSet.contains(node); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
CHierarchyNode *CHierarchyNode::addEquivalentConcept(CConcept *concept) { |
| 92 |
eqConList.append(concept); |
| 93 |
eqConCount++; |
| 94 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 95 |
generateNodeStrings(); |
| 96 |
#endif |
| 97 |
return this; |
| 98 |
} |
| 99 |
|
| 100 |
CHierarchyNode *CHierarchyNode::addPredecessorNode(CHierarchyNode *preNode) { |
| 101 |
predNodeSet.insert(preNode); |
| 102 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 103 |
generateNodeStrings(); |
| 104 |
#endif |
| 105 |
return this; |
| 106 |
} |
| 107 |
|
| 108 |
CHierarchyNode *CHierarchyNode::addSuccessorNode(CHierarchyNode *succNode) { |
| 109 |
succNodeSet.insert(succNode); |
| 110 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 111 |
generateNodeStrings(); |
| 112 |
#endif |
| 113 |
return this; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
CHierarchyNode *CHierarchyNode::makePredecessor(CHierarchyNode *preNode) { |
| 118 |
predNodeSet.insert(preNode); |
| 119 |
preNode->addSuccessorNode(this); |
| 120 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 121 |
generateNodeStrings(); |
| 122 |
#endif |
| 123 |
return this; |
| 124 |
} |
| 125 |
|
| 126 |
CHierarchyNode *CHierarchyNode::makeSuccessor(CHierarchyNode *succNode) { |
| 127 |
succNodeSet.insert(succNode); |
| 128 |
succNode->addPredecessorNode(this); |
| 129 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 130 |
generateNodeStrings(); |
| 131 |
#endif |
| 132 |
return this; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
bool CHierarchyNode::hasSuccessorNode(CHierarchyNode *node) { |
| 137 |
return succNodeSet.contains(node); |
| 138 |
} |
| 139 |
|
| 140 |
bool CHierarchyNode::hasPredecessorNode(CHierarchyNode *node) { |
| 141 |
return predNodeSet.contains(node); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
CHierarchyNode *CHierarchyNode::removeParent(CHierarchyNode *parentNode) { |
| 147 |
parentNodeSet.remove(parentNode); |
| 148 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 149 |
generateNodeStrings(); |
| 150 |
#endif |
| 151 |
return this; |
| 152 |
} |
| 153 |
|
| 154 |
CHierarchyNode *CHierarchyNode::removeChild(CHierarchyNode *childNode) { |
| 155 |
childNodeSet.remove(childNode); |
| 156 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 157 |
generateNodeStrings(); |
| 158 |
#endif |
| 159 |
return this; |
| 160 |
} |
| 161 |
|
| 162 |
cint64 CHierarchyNode::getPredecessorNodeCount() const { |
| 163 |
return predNodeSet.count(); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
QSet<CHierarchyNode *> *CHierarchyNode::getParentNodeSet() { |
| 168 |
return &parentNodeSet; |
| 169 |
} |
| 170 |
|
| 171 |
QSet<CHierarchyNode *> *CHierarchyNode::getChildNodeSet() { |
| 172 |
return &childNodeSet; |
| 173 |
} |
| 174 |
|
| 175 |
QSet<CHierarchyNode *> *CHierarchyNode::getPredecessorNodeSet() { |
| 176 |
return &predNodeSet; |
| 177 |
} |
| 178 |
|
| 179 |
QSet<CHierarchyNode *> *CHierarchyNode::getSuccessorNodeSet() { |
| 180 |
return &succNodeSet; |
| 181 |
} |
| 182 |
|
| 183 |
QList<CConcept *> *CHierarchyNode::getEquivalentConceptList() { |
| 184 |
return &eqConList; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
CHierarchyNode *CHierarchyNode::removePredecessor(CHierarchyNode *predNode) { |
| 189 |
predNodeSet.remove(predNode); |
| 190 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 191 |
generateNodeStrings(); |
| 192 |
#endif |
| 193 |
return this; |
| 194 |
} |
| 195 |
|
| 196 |
CHierarchyNode *CHierarchyNode::removeSuccessor(CHierarchyNode *succNode) { |
| 197 |
succNodeSet.remove(succNode); |
| 198 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 199 |
generateNodeStrings(); |
| 200 |
#endif |
| 201 |
return this; |
| 202 |
} |
| 203 |
|
| 204 |
QList<CHierarchyNode *> CHierarchyNode::getParentNodeList() { |
| 205 |
return parentNodeSet.values(); |
| 206 |
} |
| 207 |
|
| 208 |
QList<CHierarchyNode *> CHierarchyNode::getChildNodeList() { |
| 209 |
return childNodeSet.values(); |
| 210 |
} |
| 211 |
|
| 212 |
QList<CHierarchyNode *> CHierarchyNode::getPredecessorNodeList() { |
| 213 |
return predNodeSet.values(); |
| 214 |
} |
| 215 |
|
| 216 |
QList<CHierarchyNode *> CHierarchyNode::getSuccessorNodeList() { |
| 217 |
return succNodeSet.values(); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
CHierarchyNode *CHierarchyNode::addIncompatiblePredecessorNode(CHierarchyNode *incompNode) { |
| 223 |
incompPredNodeSet.insert(incompNode); |
| 224 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 225 |
generateNodeStrings(); |
| 226 |
#endif |
| 227 |
return this; |
| 228 |
} |
| 229 |
|
| 230 |
CHierarchyNode *CHierarchyNode::makeIncompatiblePredecessor(CHierarchyNode *incompNode) { |
| 231 |
addIncompatiblePredecessorNode(incompNode); |
| 232 |
incompNode->addIncompatibleSuccessorNode(this); |
| 233 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 234 |
generateNodeStrings(); |
| 235 |
#endif |
| 236 |
return this; |
| 237 |
} |
| 238 |
|
| 239 |
bool CHierarchyNode::hasIncompatiblePredecessorNode(CHierarchyNode *node) { |
| 240 |
return incompPredNodeSet.contains(node); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
CHierarchyNode *CHierarchyNode::removeIncompatiblePredecessorNode(CHierarchyNode *incompNode) { |
| 245 |
incompPredNodeSet.remove(incompNode); |
| 246 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 247 |
generateNodeStrings(); |
| 248 |
#endif |
| 249 |
return this; |
| 250 |
} |
| 251 |
|
| 252 |
CHierarchyNode *CHierarchyNode::addIncompatibleSuccessorNode(CHierarchyNode *incompNode) { |
| 253 |
incompSuccNodeSet.insert(incompNode); |
| 254 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 255 |
generateNodeStrings(); |
| 256 |
#endif |
| 257 |
return this; |
| 258 |
} |
| 259 |
|
| 260 |
CHierarchyNode *CHierarchyNode::makeIncompatibleSuccessor(CHierarchyNode *incompNode) { |
| 261 |
addIncompatibleSuccessorNode(incompNode); |
| 262 |
incompNode->addIncompatiblePredecessorNode(this); |
| 263 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 264 |
generateNodeStrings(); |
| 265 |
#endif |
| 266 |
return this; |
| 267 |
} |
| 268 |
|
| 269 |
bool CHierarchyNode::hasIncompatibleSuccessorNode(CHierarchyNode *node) { |
| 270 |
return incompSuccNodeSet.contains(node); |
| 271 |
} |
| 272 |
|
| 273 |
CHierarchyNode *CHierarchyNode::removeIncompatibleSuccessorNode(CHierarchyNode *incompNode) { |
| 274 |
incompSuccNodeSet.remove(incompNode); |
| 275 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 276 |
generateNodeStrings(); |
| 277 |
#endif |
| 278 |
return this; |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
CHierarchyNode *CHierarchyNode::addDisjointNode(CHierarchyNode *disjNode) { |
| 284 |
disjointNodeSet.insert(disjNode); |
| 285 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 286 |
generateNodeStrings(); |
| 287 |
#endif |
| 288 |
return this; |
| 289 |
} |
| 290 |
|
| 291 |
CHierarchyNode *CHierarchyNode::makeDisjoint(CHierarchyNode *disjNode) { |
| 292 |
addDisjointNode(disjNode); |
| 293 |
disjNode->addDisjointNode(this); |
| 294 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 295 |
generateNodeStrings(); |
| 296 |
#endif |
| 297 |
return this; |
| 298 |
} |
| 299 |
|
| 300 |
bool CHierarchyNode::hasDisjointNode(CHierarchyNode *node) { |
| 301 |
return disjointNodeSet.contains(node); |
| 302 |
} |
| 303 |
|
| 304 |
CHierarchyNode *CHierarchyNode::removeDisjointNode(CHierarchyNode *disjNode) { |
| 305 |
disjointNodeSet.remove(disjNode); |
| 306 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 307 |
generateNodeStrings(); |
| 308 |
#endif |
| 309 |
return this; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
QSet<CHierarchyNode *> *CHierarchyNode::getIncompatibleSuccessorNodeSet() { |
| 316 |
return &incompSuccNodeSet; |
| 317 |
} |
| 318 |
|
| 319 |
QSet<CHierarchyNode *> *CHierarchyNode::getIncompatiblePredecessorNodeSet() { |
| 320 |
return &incompPredNodeSet; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
QList<CHierarchyNode *> CHierarchyNode::getIncompatibleSuccessorNodeList() { |
| 325 |
return incompSuccNodeSet.values(); |
| 326 |
} |
| 327 |
|
| 328 |
QList<CHierarchyNode *> CHierarchyNode::getIncompatiblePredecessorNodeList() { |
| 329 |
return incompPredNodeSet.values(); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
QSet<CHierarchyNode *> *CHierarchyNode::getDisjointNodeSet() { |
| 335 |
return &disjointNodeSet; |
| 336 |
} |
| 337 |
|
| 338 |
QList<CHierarchyNode *> CHierarchyNode::getDisjointNodeList() { |
| 339 |
return disjointNodeSet.values(); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
CConcept *CHierarchyNode::getOneEquivalentConcept() { |
| 344 |
CConcept *concept = 0; |
| 345 |
if (!eqConList.isEmpty()) { |
| 346 |
concept = eqConList.first(); |
| 347 |
} |
| 348 |
return concept; |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
bool CHierarchyNode::isActive() { |
| 353 |
return active; |
| 354 |
} |
| 355 |
|
| 356 |
CHierarchyNode *CHierarchyNode::setActive(bool activeNode) { |
| 357 |
active = activeNode; |
| 358 |
return this; |
| 359 |
} |
| 360 |
|
| 361 |
CHierarchyNode *CHierarchyNode::setInactive(bool inactiveNode) { |
| 362 |
active = !inactiveNode; |
| 363 |
return this; |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
bool CHierarchyNode::isNeedExplicitMentioned() { |
| 368 |
return mention; |
| 369 |
} |
| 370 |
|
| 371 |
CHierarchyNode *CHierarchyNode::setNeedExplicitMentioned(bool needsExplicitMentioned) { |
| 372 |
mention = needsExplicitMentioned; |
| 373 |
return this; |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
QString CHierarchyNode::getEquivalentConceptsNodeString() { |
| 380 |
QString string; |
| 381 |
foreach (CConcept *con, eqConList) { |
| 382 |
QString iriClassNameString = CIRIName::getRecentIRIName(con->getClassNameLinker()); |
| 383 |
if (!string.isEmpty()) { |
| 384 |
string += QString(" <=> %1").arg(iriClassNameString); |
| 385 |
} else { |
| 386 |
string = iriClassNameString; |
| 387 |
} |
| 388 |
} |
| 389 |
return string; |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
QString CHierarchyNode::getHierarchyConceptsNodeString(qint64 depth) { |
| 394 |
QString string(depth,'\t'); |
| 395 |
string += QString("< ") + getEquivalentConceptsNodeString() + QString(" >\n"); |
| 396 |
foreach (CHierarchyNode *childNode, getChildNodeList()) { |
| 397 |
string += childNode->getHierarchyConceptsNodeString(depth+1); |
| 398 |
} |
| 399 |
string += QString(depth,'\t')+QString("</ ") + getEquivalentConceptsNodeString() + QString(" >\n"); |
| 400 |
return string; |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
QStringList CHierarchyNode::getEquivalentConceptStringList(bool preferAbbreviatedNames) { |
| 405 |
QStringList stringList; |
| 406 |
foreach (CConcept *con, eqConList) { |
| 407 |
QStringList iriClassNameStringList; |
| 408 |
if (preferAbbreviatedNames) { |
| 409 |
iriClassNameStringList.append(CAbbreviatedIRIName::getRecentAbbreviatedPrefixWithAbbreviatedIRIName(con->getClassNameLinker())); |
| 410 |
} |
| 411 |
|
| 412 |
if (!preferAbbreviatedNames || iriClassNameStringList.isEmpty()) { |
| 413 |
iriClassNameStringList.append(CIRIName::getRecentIRIName(con->getClassNameLinker())); |
| 414 |
} |
| 415 |
stringList<<iriClassNameStringList; |
| 416 |
} |
| 417 |
return stringList; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
qint64 CHierarchyNode::getEquivalentConceptCount() { |
| 422 |
return eqConCount; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
#ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS |
| 427 |
CHierarchyNode *CHierarchyNode::generateNodeStrings() { |
| 428 |
nodeStrings.clear(); |
| 429 |
nodeStrings = getEquivalentConceptStringList(true); |
| 430 |
parentNodeStrings.clear(); |
| 431 |
foreach (CHierarchyNode *node, getParentNodeList()) { |
| 432 |
parentNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 433 |
} |
| 434 |
childNodeStrings.clear(); |
| 435 |
foreach (CHierarchyNode *node, getChildNodeList()) { |
| 436 |
childNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 437 |
} |
| 438 |
precNodeStrings.clear(); |
| 439 |
foreach (CHierarchyNode *node, getPredecessorNodeList()) { |
| 440 |
precNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 441 |
} |
| 442 |
succNodeStrings.clear(); |
| 443 |
foreach (CHierarchyNode *node, getSuccessorNodeList()) { |
| 444 |
succNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 445 |
} |
| 446 |
incPrecNodeStrings.clear(); |
| 447 |
foreach (CHierarchyNode *node, getIncompatiblePredecessorNodeList()) { |
| 448 |
incPrecNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 449 |
} |
| 450 |
incSuccNodeStrings.clear(); |
| 451 |
foreach (CHierarchyNode *node, getIncompatibleSuccessorNodeList()) { |
| 452 |
incSuccNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 453 |
} |
| 454 |
disjointNodeStrings.clear(); |
| 455 |
foreach (CHierarchyNode *node, getDisjointNodeList()) { |
| 456 |
disjointNodeStrings<<node->getEquivalentConceptsNodeString(); |
| 457 |
} |
| 458 |
return this; |
| 459 |
} |
| 460 |
#endif |
| 461 |
|
| 462 |
|
| 463 |
}; // end namespace Taxonomy |
| 464 |
|
| 465 |
}; // end namespace Reasoner |
| 466 |
|
| 467 |
}; // end namespace Konclude |