| 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 "COccurrenceStatisticsCacheWriter.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Cache { |
| 31 |
|
| 32 |
|
| 33 |
COccurrenceStatisticsCacheWriter::COccurrenceStatisticsCacheWriter(COccurrenceStatisticsCache* cache, COccurrenceStatisticsCacheData* data) : mCache(cache), mData(data) { |
| 34 |
mOntologyTag = -1; |
| 35 |
mOntologyData = nullptr; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
COccurrenceStatisticsCacheWriter* COccurrenceStatisticsCacheWriter::writeCachedData(COccurrenceStatisticsCacheWriteData* writeData, CMemoryPool* memoryPools) { |
| 40 |
mCache->writeCachedData(writeData,memoryPools); |
| 41 |
return this; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
COccurrenceStatisticsCacheWriter* COccurrenceStatisticsCacheWriter::loadOntologyDataVectors(CConcreteOntology* ontology) { |
| 46 |
cint64 ontologyId = ontology->getOntologyID(); |
| 47 |
if (ontologyId != mOntologyTag) { |
| 48 |
mData->getReadWriteLock()->lockForWrite(); |
| 49 |
if (mOntologyData) { |
| 50 |
mOntologyData->releaseWrittenConceptDataVector(mConceptDataVector); |
| 51 |
mOntologyData->releaseWrittenRoleDataVector(mRoleDataVector); |
| 52 |
mOntologyData->decUsageCount(); |
| 53 |
} |
| 54 |
mOntologyData = mData->getOntologyData(ontologyId, true); |
| 55 |
mOntologyData->incUsageCount(); |
| 56 |
mConceptDataVector = mOntologyData->getWriteableConceptDataVector(ontology->getTBox()->getConceptCount()); |
| 57 |
mRoleDataVector = mOntologyData->getWriteableRoleDataVector(ontology->getRBox()->getRoleCount()); |
| 58 |
mOntologyTag = ontologyId; |
| 59 |
mData->incUpdateId(); |
| 60 |
mData->getReadWriteLock()->unlock(); |
| 61 |
} |
| 62 |
return this; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
COccurrenceStatisticsCacheWriter* COccurrenceStatisticsCacheWriter::incConceptInstanceOccurrencceStatistics(CConcreteOntology* ontology, cint64 conceptId, cint64 deterministicCount, cint64 nondeterministicCount, cint64 individualCount, cint64 existentialCount) { |
| 67 |
loadOntologyDataVectors(ontology); |
| 68 |
COccurrenceStatisticsConceptData* conceptData = mConceptDataVector->getOccurrenceStatisticsData(conceptId); |
| 69 |
if (conceptData) { |
| 70 |
if (deterministicCount != 0) { |
| 71 |
conceptData->incDeterministicInstanceOccurrencesCount(deterministicCount); |
| 72 |
} |
| 73 |
if (nondeterministicCount != 0) { |
| 74 |
conceptData->incNonDeterministicInstanceOccurrencesCount(nondeterministicCount); |
| 75 |
} |
| 76 |
if (existentialCount != 0) { |
| 77 |
conceptData->incExistentialInstanceOccurrencesCount(existentialCount); |
| 78 |
} |
| 79 |
if (individualCount != 0) { |
| 80 |
conceptData->incIndividualInstanceOccurrencesCount(individualCount); |
| 81 |
} |
| 82 |
} |
| 83 |
return this; |
| 84 |
} |
| 85 |
|
| 86 |
COccurrenceStatisticsCacheWriter* COccurrenceStatisticsCacheWriter::incRoleInstanceOccurrencceStatistics(CConcreteOntology* ontology, cint64 roleId, cint64 deterministicCount, cint64 nondeterministicCount, cint64 individualCount, cint64 existentialCount, cint64 outgoingCount, cint64 incomingCount) { |
| 87 |
loadOntologyDataVectors(ontology); |
| 88 |
COccurrenceStatisticsRoleData* roleData = mRoleDataVector->getOccurrenceStatisticsData(roleId); |
| 89 |
if (roleData) { |
| 90 |
if (deterministicCount != 0) { |
| 91 |
roleData->incDeterministicInstanceOccurrencesCount(deterministicCount); |
| 92 |
} |
| 93 |
if (nondeterministicCount != 0) { |
| 94 |
roleData->incNonDeterministicInstanceOccurrencesCount(nondeterministicCount); |
| 95 |
} |
| 96 |
if (existentialCount != 0) { |
| 97 |
roleData->incExistentialInstanceOccurrencesCount(existentialCount); |
| 98 |
} |
| 99 |
if (individualCount != 0) { |
| 100 |
roleData->incIndividualInstanceOccurrencesCount(individualCount); |
| 101 |
} |
| 102 |
if (outgoingCount != 0) { |
| 103 |
roleData->incOutgoingNodeInstanceOccurrencesCount(outgoingCount); |
| 104 |
} |
| 105 |
if (incomingCount != 0) { |
| 106 |
roleData->incIncomingNodeInstanceOccurrencesCount(incomingCount); |
| 107 |
} |
| 108 |
} |
| 109 |
return this; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
}; // end namespace Cache |
| 114 |
|
| 115 |
}; // end namespace Kernel |
| 116 |
|
| 117 |
}; // end namespace Reasoner |
| 118 |
|
| 119 |
}; // end namespace Konclude |