| 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 "CIndexedIndividualAssertionConvertionVisitor.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Algorithm { |
| 31 |
|
| 32 |
|
| 33 |
CIndexedIndividualAssertionConvertionVisitor::CIndexedIndividualAssertionConvertionVisitor(cint64 retrievingIndiId, CCalculationAlgorithmContext* calcAlgContext) : mPreprocessContext(calcAlgContext->getProcessingDataBox()->getOntology(), calcAlgContext->getSatisfiableCalculationTask()->getCalculationConfiguration(), calcAlgContext->getUsedProcessTaskMemoryAllocationManager()) { |
| 34 |
mCalcAlgContext = calcAlgContext; |
| 35 |
mMemoryAllocationManager = calcAlgContext->getUsedProcessTaskMemoryAllocationManager(); |
| 36 |
mRetrievingIndiId = retrievingIndiId; |
| 37 |
mRetrievingIndi = getExistingOrCreateNewTemporaryIndividual(mRetrievingIndiId); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
CIndexedIndividualAssertionConvertionVisitor::CIndexedIndividualAssertionConvertionVisitor(CIndividual* retrievingIndi, CCalculationAlgorithmContext* calcAlgContext) : mPreprocessContext(calcAlgContext->getProcessingDataBox()->getOntology(), calcAlgContext->getSatisfiableCalculationTask()->getCalculationConfiguration(), calcAlgContext->getUsedProcessTaskMemoryAllocationManager()) { |
| 42 |
mCalcAlgContext = calcAlgContext; |
| 43 |
mMemoryAllocationManager = calcAlgContext->getUsedProcessTaskMemoryAllocationManager(); |
| 44 |
mRetrievingIndiId = retrievingIndi->getIndividualID(); |
| 45 |
mRetrievingIndi = getNewTemporaryIndividual(retrievingIndi); |
| 46 |
mConceptAssertionLinker = retrievingIndi->getAssertionConceptLinker(); |
| 47 |
mRoleAssertionLinker = retrievingIndi->getAssertionRoleLinker(); |
| 48 |
mReverseRoleAssertionLinker = retrievingIndi->getReverseAssertionRoleLinker(); |
| 49 |
mDataAssertionLinker = retrievingIndi->getAssertionDataLinker(); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
bool CIndexedIndividualAssertionConvertionVisitor::visitIndividualName(const QString& indiName, COntologyTriplesAssertionsAccessor* accessor) { |
| 54 |
if (!mRetrievingIndi->getIndividualNameLinker()) { |
| 55 |
CIRIName* name = CObjectAllocator< CIRIName >::allocateAndConstruct(mMemoryAllocationManager); |
| 56 |
name->setIRIName(indiName); |
| 57 |
CLinker<CName*>* nameLinker = CObjectAllocator< CLinker<CName*> >::allocateAndConstruct(mMemoryAllocationManager); |
| 58 |
nameLinker->init(name); |
| 59 |
mRetrievingIndi->setNameLinker(nameLinker); |
| 60 |
} |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
bool CIndexedIndividualAssertionConvertionVisitor::visitRoleAssertion(CRole* role, cint64 otherIndividualId, COntologyTriplesAssertionsAccessor* accessor) { |
| 66 |
CRoleAssertionLinker* roleAssertionLinker = CObjectAllocator<CRoleAssertionLinker>::allocateAndConstruct(mMemoryAllocationManager); |
| 67 |
CIndividual* existingOrNewTemporaryIndi = getExistingOrCreateNewTemporaryIndividual(otherIndividualId); |
| 68 |
roleAssertionLinker->initRoleAssertionLinker(role, existingOrNewTemporaryIndi); |
| 69 |
mRoleAssertionLinker = roleAssertionLinker->append(mRoleAssertionLinker); |
| 70 |
return true; |
| 71 |
} |
| 72 |
|
| 73 |
bool CIndexedIndividualAssertionConvertionVisitor::visitReverseRoleAssertion(CRole* role, cint64 otherIndividualId, COntologyTriplesAssertionsAccessor* accessor) { |
| 74 |
CReverseRoleAssertionLinker* reversRoleAssertionLinker = CObjectAllocator<CReverseRoleAssertionLinker>::allocateAndConstruct(mMemoryAllocationManager); |
| 75 |
CIndividual* existingOrNewTemporaryIndi = getExistingOrCreateNewTemporaryIndividual(otherIndividualId); |
| 76 |
|
| 77 |
CRoleAssertionLinker* roleAssertionLinker = CObjectAllocator<CRoleAssertionLinker>::allocateAndConstruct(mMemoryAllocationManager); |
| 78 |
roleAssertionLinker->initRoleAssertionLinker(role, mRetrievingIndi); |
| 79 |
|
| 80 |
reversRoleAssertionLinker->initReverseRoleAssertionLinker(roleAssertionLinker, existingOrNewTemporaryIndi); |
| 81 |
mReverseRoleAssertionLinker = reversRoleAssertionLinker->append(mReverseRoleAssertionLinker); |
| 82 |
return true; |
| 83 |
} |
| 84 |
|
| 85 |
bool CIndexedIndividualAssertionConvertionVisitor::visitDataAssertion(CRole* role, CDataLiteral* dataLiteral, COntologyTriplesAssertionsAccessor* accessor) { |
| 86 |
CDataLiteral* copiedDataLiteral = CObjectParameterizingAllocator<CDataLiteral,CContext*>::allocateAndConstructAndParameterize(mMemoryAllocationManager, mCalcAlgContext); |
| 87 |
copiedDataLiteral->initDataLiteral(dataLiteral->getLexicalDataLiteralValueString(), dataLiteral->getDatatype()); |
| 88 |
createDataLiteralValue(copiedDataLiteral); |
| 89 |
// TODO: clean up of internal data of data literal and data literal value |
| 90 |
|
| 91 |
CDataAssertionLinker* dataAssertionLinker = CObjectAllocator<CDataAssertionLinker>::allocateAndConstruct(mMemoryAllocationManager); |
| 92 |
dataAssertionLinker->initDataAssertionLinker(role, copiedDataLiteral); |
| 93 |
mDataAssertionLinker = dataAssertionLinker->append(mDataAssertionLinker); |
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
bool CIndexedIndividualAssertionConvertionVisitor::visitConceptAssertion(CConcept* concept, COntologyTriplesAssertionsAccessor* accessor) { |
| 98 |
CConceptAssertionLinker* conceptAssertionLinker = CObjectAllocator<CConceptAssertionLinker>::allocateAndConstruct(mMemoryAllocationManager); |
| 99 |
conceptAssertionLinker->initNegLinker(concept, false); |
| 100 |
mConceptAssertionLinker = conceptAssertionLinker->append(mConceptAssertionLinker); |
| 101 |
return true; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
CIndividual* CIndexedIndividualAssertionConvertionVisitor::getExistingOrCreateNewTemporaryIndividual(cint64 indiId) { |
| 106 |
CIndividual* indi = nullptr; |
| 107 |
CIndividualVector* indiVector = mCalcAlgContext->getProcessingDataBox()->getIndividualVector(true); |
| 108 |
indi = indiVector->getLocalData(indiId); |
| 109 |
if (!indi) { |
| 110 |
indi = CObjectAllocator<CIndividual>::allocateAndConstruct(mMemoryAllocationManager); |
| 111 |
indi->initIndividual(indiId); |
| 112 |
indi->setTemporaryIndividual(true); |
| 113 |
indiVector->setLocalData(indiId, indi); |
| 114 |
} |
| 115 |
return indi; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
CIndividual* CIndexedIndividualAssertionConvertionVisitor::getNewTemporaryIndividual(CIndividual* existingIndi) { |
| 120 |
CIndividualVector* indiVector = mCalcAlgContext->getProcessingDataBox()->getIndividualVector(true); |
| 121 |
CIndividual* newIndi = CObjectAllocator<CIndividual>::allocateAndConstruct(mMemoryAllocationManager); |
| 122 |
newIndi->initIndividual(existingIndi->getIndividualID()); |
| 123 |
newIndi->setTemporaryIndividual(true); |
| 124 |
newIndi->setIndividualData(existingIndi->getIndividualData()); |
| 125 |
indiVector->setLocalData(existingIndi->getIndividualID(), newIndi); |
| 126 |
return newIndi; |
| 127 |
} |
| 128 |
|
| 129 |
CDataLiteralValue* CIndexedIndividualAssertionConvertionVisitor::createDataLiteralValue(CDataLiteral* dataLiteral) { |
| 130 |
CDataLiteralValue* dataLiteralValue = mDataLiteralNormalizer.createPreprocessedDataLiteralValue(dataLiteral, &mPreprocessContext, mCalcAlgContext); |
| 131 |
return dataLiteralValue; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
CConceptAssertionLinker* CIndexedIndividualAssertionConvertionVisitor::getConceptAssertionLinker() { |
| 136 |
return mConceptAssertionLinker; |
| 137 |
} |
| 138 |
|
| 139 |
CRoleAssertionLinker* CIndexedIndividualAssertionConvertionVisitor::getRoleAssertionLinker() { |
| 140 |
return mRoleAssertionLinker; |
| 141 |
} |
| 142 |
|
| 143 |
CReverseRoleAssertionLinker* CIndexedIndividualAssertionConvertionVisitor::getReverseRoleAssertionLinker() { |
| 144 |
return mReverseRoleAssertionLinker; |
| 145 |
} |
| 146 |
|
| 147 |
CDataAssertionLinker* CIndexedIndividualAssertionConvertionVisitor::getDataAssertionLinker() { |
| 148 |
return mDataAssertionLinker; |
| 149 |
} |
| 150 |
|
| 151 |
CIndividual* CIndexedIndividualAssertionConvertionVisitor::getRetrievalIndividual() { |
| 152 |
mRetrievingIndi->setAssertionDataLinker(mDataAssertionLinker); |
| 153 |
mRetrievingIndi->setAssertionConceptLinker(mConceptAssertionLinker); |
| 154 |
mRetrievingIndi->setAssertionRoleLinker(mRoleAssertionLinker); |
| 155 |
mRetrievingIndi->setReverseAssertionRoleLinker(mReverseRoleAssertionLinker); |
| 156 |
return mRetrievingIndi; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
}; // end namespace Algorithm |
| 163 |
|
| 164 |
}; // end namespace Kernel |
| 165 |
|
| 166 |
}; // end namespace Reasoner |
| 167 |
|
| 168 |
}; // end namespace Konclude |