1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
Copyright (C) 2015-2016 Dmitry Tsarkov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TINDIVIDUAL_H
#define TINDIVIDUAL_H
#include <map>
#include "tConcept.h"
class DlCompletionTree;
class TRelated;
class SaveLoadManager;
class TIndividual;
/// class to map roles to set of individuals
class TRelatedMap
{
public: // interface types
/// vector of individuals
typedef std::vector<const TIndividual*> CIVec;
protected: // types
/// base class
typedef std::map<const TRole*,CIVec> BaseType;
protected: // members
/// base that contains all info
BaseType Base;
public: // interface
/// empty c'tor
TRelatedMap ( void ) {}
/// empty d'tor
~TRelatedMap ( void ) {}
// access
/// check whether role is in map
bool hasRole ( const TRole* R ) const { return Base.find(R) != Base.end(); }
/// get array related to role
const CIVec& getRelated ( const TRole* R ) const
{
fpp_assert ( hasRole(R) );
return Base.find(R)->second;
}
/// add related wrt role
void setRelated ( const TRole* R, const CIVec& v )
{
fpp_assert ( !hasRole(R) );
Base[R] = v;
}
}; // TRelatedMap
/// class to represent individuals
class TIndividual: public TConcept
{
public: // types
/// pointers to RELATED constructors
typedef std::vector<TRelated*> RelatedSet;
/// vector of individuals
typedef TRelatedMap::CIVec CIVec;
public: // members
/// pointer to nominal node (works for singletons only)
DlCompletionTree* node;
/// index for axioms <this,C>:R
RelatedSet RelatedIndex;
/// map for the related individuals: Map[R]={i:R(this,i)}
TRelatedMap* pRelatedMap;
private: // no copy
/// no copy c'tor
TIndividual ( const TIndividual& );
/// no asssignment
TIndividual& operator = ( const TIndividual& );
public: // interface
/// the only c'tor
explicit TIndividual ( const std::string& name )
: TConcept(name)
, node(NULL)
, pRelatedMap(new TRelatedMap())
{
setSingleton(true);
}
/// empty d'tor
virtual ~TIndividual ( void ) { delete pRelatedMap; }
/// init told subsumers of the individual by it's description
virtual void initToldSubsumers ( void )
{
toldSubsumers.clear();
clearHasSP();
if ( isRelated() ) // check if domain and range of RELATED axioms affects TS
updateToldFromRelated();
// normalise description if the only parent is TOP
if ( isPrimitive() && Description && Description->Element() == TOP )
removeDescription();
// not a completely defined if there are extra rules or related individuals
bool CD = !hasExtraRules() && isPrimitive() && !isRelated();
if ( Description != NULL || hasToldSubsumers() )
CD &= TConcept::initToldSubsumers(Description);
setCompletelyDefined(CD);
}
// related things
/// update told subsumers from the RELATED axioms in a given range
template<class Iterator>
void updateTold ( Iterator begin, Iterator end, RoleSSet& RolesProcessed )
{
for ( Iterator p = begin; p < end; ++p )
SearchTSbyRoleAndSupers ( (*p)->getRole(), RolesProcessed);
}
/// update told subsumers from all relevant RELATED axioms
void updateToldFromRelated ( void );
/// check if individual connected to something with RELATED statement
bool isRelated ( void ) const { return !RelatedIndex.empty(); }
/// set individual related
void addRelated ( TRelated* p ) { RelatedIndex.push_back(p); }
/// add all the related elements from the given P
void addRelated ( TIndividual* p )
{ RelatedIndex.insert ( RelatedIndex.end(), p->RelatedIndex.begin(), p->RelatedIndex.end() ); }
// related map access
/// @return true if has cache for related individuals via role R
bool hasRelatedCache ( const TRole* R ) const { return pRelatedMap->hasRole(R); }
/// get set of individuals related to THIS via R
const CIVec& getRelatedCache ( const TRole* R ) const { return pRelatedMap->getRelated(R); }
/// set the cache of individuals related to THIS via R
void setRelatedCache ( const TRole* R, const CIVec& v ) { pRelatedMap->setRelated ( R, v ); }
/// clear RM
void clearRelatedMap ( void ) { delete pRelatedMap; pRelatedMap = new TRelatedMap(); }
// save/load interface; implementation is in SaveLoad.cpp
/// save entry
virtual void Save ( SaveLoadManager& m ) const;
/// load entry
virtual void Load ( SaveLoadManager& m );
}; // TIndividual
#endif
|