/* * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. * * This file is part of the reasoning system Konclude. * For details and support, see . * * Konclude is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU Lesser General Public * License (LGPLv3) as published by the Free Software Foundation. * * Konclude is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU (Lesser) General Public License for more details. * * You should have received a copy of the GNU (Lesser) General Public * License along with Konclude. If not, see . * */ #ifndef KONCLUDE_REASONER_QUERY_CSTRINGSUBSTRINGSRELATIONRESULT_CPP #define KONCLUDE_REASONER_QUERY_CSTRINGSUBSTRINGSRELATIONRESULT_CPP #include "CStringSubStringsRelationResult.h" namespace Konclude { namespace Reasoner { namespace Query { template CStringSubStringsRelationResult::CStringSubStringsRelationResult() { mSuperString = 0; } template CStringSubStringsRelationResult::CStringSubStringsRelationResult(E *superStringSynset) { mSuperString = superStringSynset; } template CStringSubStringsRelationResult::~CStringSubStringsRelationResult() { } template E* CStringSubStringsRelationResult::getSuperStringSynset() { return mSuperString; } template T *CStringSubStringsRelationResult::setSuperStringSynset(E* superStringSynset) { mSuperString = superStringSynset; return (T*)this; } template QSet* CStringSubStringsRelationResult::getSubStringsSynsetSet() { return &mSubStringSynsetSet; } template QList CStringSubStringsRelationResult::getSubStringsSynsetList() { return mSubStringSynsetSet.toList(); } template T *CStringSubStringsRelationResult::addSubStringsSynset(E *subStringSynset) { mSubStringSynsetSet.insert(subStringSynset); return (T*)this; } template T *CStringSubStringsRelationResult::addSubStringsSynsets(const QList &subStringsSynsets) { foreach (E* stringSynRes, subStringsSynsets) { mSubStringSynsetSet.insert(stringSynRes); } return (T*)this; } template qint64 CStringSubStringsRelationResult::getSubStringsSynsetCount() { return mSubStringSynsetSet.count(); } template bool CStringSubStringsRelationResult::hasSubStringsSynset(E *subStringSynset) { return mSubStringSynsetSet.contains(subStringSynset); } template QString CStringSubStringsRelationResult::getQueryResultString(const QString& typeStringName) { QString string; if (mSuperString && getSubStringsSynsetCount() > 0) { string += mSuperString->getQueryResultString(); } if (!string.isEmpty()) { QString subStringString; foreach (E *subStringSynset, mSubStringSynsetSet) { if (subStringString.isEmpty()) { subStringString += QString(" has Sub-%1-Relation to %2").arg(typeStringName).arg(subStringSynset->getQueryResultString()); } else { subStringString += QString(" and to %1").arg(subStringSynset->getQueryResultString()); } } string += subStringString; } return string; } template bool CStringSubStringsRelationResult::isResultEquivalentTo(CQueryResult *otherQueryResult) { if (!otherQueryResult) { return false; } T *otherSubClassRelation = dynamic_cast(otherQueryResult); if (!otherSubClassRelation) { return false; } if (!mSuperString->isResultEquivalentTo(otherSubClassRelation->getSuperStringSynset())) { return false; } QList otherSubStringList(otherSubClassRelation->getSubStringsSynsetList()); foreach (E *stringSynset, otherSubStringList) { bool contained = false; for (qint64 cnt = otherSubStringList.count(); cnt > 0; --cnt) { contained |= otherSubStringList.first()->isResultEquivalentTo(stringSynset); if (contained) { otherSubStringList.takeFirst(); break; } else { otherSubStringList.append(otherSubStringList.takeFirst()); } } if (!contained) { return false; } } return true; } }; // end namespace Query }; // end namespace Reasoner }; // end namespace Konclude #endif // KONCLUDE_REASONER_QUERY_CSTRINGSUBSTRINGSRELATIONRESULT_CPP