| 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 "COntologyStringMapping.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Ontology { |
| 29 |
|
| 30 |
|
| 31 |
COntologyStringMapping::COntologyStringMapping(COntologyContext* ontologyContext) { |
| 32 |
mOntoContext = ontologyContext; |
| 33 |
mClassNameConceptMapHash = nullptr; |
| 34 |
mPropertyNameRoleMapHash = nullptr; |
| 35 |
mIndividualNameIndividualMapHash = nullptr; |
| 36 |
mAbbreviatedNamePrefixMapHash = nullptr; |
| 37 |
mNamePrefixMapHash = nullptr; |
| 38 |
mPrefixList = nullptr; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
COntologyStringMapping::~COntologyStringMapping() { |
| 43 |
CMemoryAllocationManager* memMan = CContext::getMemoryAllocationManager(mOntoContext); |
| 44 |
COADestroyAndRelease(mClassNameConceptMapHash,memMan); |
| 45 |
COADestroyAndRelease(mPropertyNameRoleMapHash,memMan); |
| 46 |
COADestroyAndRelease(mIndividualNameIndividualMapHash,memMan); |
| 47 |
COADestroyAndRelease(mAbbreviatedNamePrefixMapHash,memMan); |
| 48 |
COADestroyAndRelease(mNamePrefixMapHash,memMan); |
| 49 |
COADestroyAndRelease(mPrefixList,memMan); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
COntologyStringMapping* COntologyStringMapping::referenceStringMapping(COntologyStringMapping* stringMapping) { |
| 54 |
if (stringMapping->mClassNameConceptMapHash) { |
| 55 |
(*getClassNameConceptMappingHash(true)) = *stringMapping->mClassNameConceptMapHash; |
| 56 |
} else { |
| 57 |
if (mClassNameConceptMapHash) { |
| 58 |
mClassNameConceptMapHash->clear(); |
| 59 |
} |
| 60 |
} |
| 61 |
if (stringMapping->mPropertyNameRoleMapHash) { |
| 62 |
(*getPropertyNameRoleMappingHash(true)) = *stringMapping->mPropertyNameRoleMapHash; |
| 63 |
} else { |
| 64 |
if (mPropertyNameRoleMapHash) { |
| 65 |
mPropertyNameRoleMapHash->clear(); |
| 66 |
} |
| 67 |
} |
| 68 |
if (stringMapping->mIndividualNameIndividualMapHash) { |
| 69 |
(*getIndividualNameIndividualMappingHash(true)) = *stringMapping->mIndividualNameIndividualMapHash; |
| 70 |
} else { |
| 71 |
if (mIndividualNameIndividualMapHash) { |
| 72 |
mIndividualNameIndividualMapHash->clear(); |
| 73 |
} |
| 74 |
} |
| 75 |
if (stringMapping->mAbbreviatedNamePrefixMapHash) { |
| 76 |
(*getAbbreviatedNamePrefixHash(true)) = *stringMapping->mAbbreviatedNamePrefixMapHash; |
| 77 |
} else { |
| 78 |
if (mAbbreviatedNamePrefixMapHash) { |
| 79 |
mAbbreviatedNamePrefixMapHash->clear(); |
| 80 |
} |
| 81 |
} |
| 82 |
if (stringMapping->mNamePrefixMapHash) { |
| 83 |
(*getNamePrefixHash(true)) = *stringMapping->mNamePrefixMapHash; |
| 84 |
} else { |
| 85 |
if (mNamePrefixMapHash) { |
| 86 |
mNamePrefixMapHash->clear(); |
| 87 |
} |
| 88 |
} |
| 89 |
if (stringMapping->mPrefixList) { |
| 90 |
(*getPrefixList(true)) = *stringMapping->mPrefixList; |
| 91 |
} else { |
| 92 |
if (mPrefixList) { |
| 93 |
mPrefixList->clear(); |
| 94 |
} |
| 95 |
} |
| 96 |
return this; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
CMAPPINGHASH<CStringRefStringHasher,CConcept*>* COntologyStringMapping::getClassNameConceptMappingHash(bool create) { |
| 102 |
if (!mClassNameConceptMapHash && create) { |
| 103 |
mClassNameConceptMapHash = CObjectParameterizingAllocator< CMAPPINGHASH<CStringRefStringHasher,CConcept*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mOntoContext),mOntoContext); |
| 104 |
} |
| 105 |
return mClassNameConceptMapHash; |
| 106 |
} |
| 107 |
|
| 108 |
CMAPPINGHASH<CStringRefStringHasher,CRole*>* COntologyStringMapping::getPropertyNameRoleMappingHash(bool create) { |
| 109 |
if (!mPropertyNameRoleMapHash && create) { |
| 110 |
mPropertyNameRoleMapHash = CObjectParameterizingAllocator< CMAPPINGHASH<CStringRefStringHasher,CRole*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mOntoContext),mOntoContext); |
| 111 |
} |
| 112 |
return mPropertyNameRoleMapHash; |
| 113 |
} |
| 114 |
|
| 115 |
CMAPPINGHASH<CStringRefStringHasher,CIndividual*>* COntologyStringMapping::getIndividualNameIndividualMappingHash(bool create) { |
| 116 |
if (!mIndividualNameIndividualMapHash && create) { |
| 117 |
mIndividualNameIndividualMapHash = CObjectParameterizingAllocator< CMAPPINGHASH<CStringRefStringHasher,CIndividual*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mOntoContext),mOntoContext); |
| 118 |
} |
| 119 |
return mIndividualNameIndividualMapHash; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
CMAPPINGHASH<QString,CNamePrefix*>* COntologyStringMapping::getAbbreviatedNamePrefixHash(bool create) { |
| 124 |
if (!mAbbreviatedNamePrefixMapHash && create) { |
| 125 |
mAbbreviatedNamePrefixMapHash = CObjectParameterizingAllocator< CMAPPINGHASH<QString,CNamePrefix*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mOntoContext),mOntoContext); |
| 126 |
} |
| 127 |
return mAbbreviatedNamePrefixMapHash; |
| 128 |
} |
| 129 |
|
| 130 |
CMAPPINGHASH<QString,CNamePrefix*>* COntologyStringMapping::getNamePrefixHash(bool create) { |
| 131 |
if (!mNamePrefixMapHash && create) { |
| 132 |
mNamePrefixMapHash = CObjectParameterizingAllocator< CMAPPINGHASH<QString,CNamePrefix*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mOntoContext),mOntoContext); |
| 133 |
} |
| 134 |
return mNamePrefixMapHash; |
| 135 |
} |
| 136 |
|
| 137 |
CMAPPINGLIST<CNamePrefix*>* COntologyStringMapping::getPrefixList(bool create) { |
| 138 |
if (!mPrefixList && create) { |
| 139 |
mPrefixList = CObjectParameterizingAllocator< CMAPPINGLIST<CNamePrefix*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mOntoContext),mOntoContext); |
| 140 |
} |
| 141 |
return mPrefixList; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
CConcept* COntologyStringMapping::getConceptFromName(const QString& fullClassName) { |
| 146 |
CConcept* concept = nullptr; |
| 147 |
if (mClassNameConceptMapHash) { |
| 148 |
concept = mClassNameConceptMapHash->value(fullClassName,nullptr); |
| 149 |
} |
| 150 |
return concept; |
| 151 |
} |
| 152 |
|
| 153 |
CRole* COntologyStringMapping::getRoleFromName(const QString& fullPropertyName) { |
| 154 |
CRole* role = nullptr; |
| 155 |
if (mPropertyNameRoleMapHash) { |
| 156 |
role = mPropertyNameRoleMapHash->value(fullPropertyName,nullptr); |
| 157 |
} |
| 158 |
return role; |
| 159 |
} |
| 160 |
|
| 161 |
CIndividual* COntologyStringMapping::getIndividualFromName(const QString& fullIndividualName) { |
| 162 |
CIndividual* individual = nullptr; |
| 163 |
if (mIndividualNameIndividualMapHash) { |
| 164 |
individual = mIndividualNameIndividualMapHash->value(fullIndividualName,nullptr); |
| 165 |
} |
| 166 |
return individual; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
}; // end namespace Ontology |
| 172 |
|
| 173 |
}; // end namespace Reasoner |
| 174 |
|
| 175 |
}; // end namespace Konclude |