| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef TAXVERTEX_H |
| 21 | #define TAXVERTEX_Hcxx . . $ `Kernel/taxVertex.h:21:9`! |
| 22 | |
| 23 | #include <set> |
| 24 | #include <vector> |
| 25 | #include <iosfwd> |
| 26 | #include <cstring> |
| 27 | |
| 28 | #include "taxNamEntry.h"cxx . . $ `<file>/Kernel/taxNamEntry.h`/ |
| 29 | #include "tLabeller.h"cxx . . $ `<file>/Kernel/tLabeller.h`/ |
| 30 | |
| 31 | class SaveLoadManagercxx . . $ SaveLoadManager#; |
| 32 | |
| 33 | class TaxonomyVertexcxx . . $ TaxonomyVertex# |
| 34 | { |
| 35 | protected: // typedefs |
| 36 | /// vertex vector for links to parents and children |
| 37 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<TaxonomyVertexcxx . . $ TaxonomyVertex#*> TaxVertexLinkcxx . . $ TaxonomyVertex#TaxVertexLink#; |
| 38 | /// vector of entries for synonyms |
| 39 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<const ClassifiableEntrycxx . . $ ClassifiableEntry#*> EqualNamescxx . . $ TaxonomyVertex#EqualNames#; |
| 40 | |
| 41 | public: // typedefs |
| 42 | // accessors type |
| 43 | |
| 44 | /// RW iterator for the neighbours |
| 45 | typedef TaxVertexLinkcxx . . $ TaxonomyVertex#TaxVertexLink#::iteratorcxx . . $ std/vector#iterator# iteratorcxx . . $ TaxonomyVertex#iterator#; |
| 46 | /// RO iterator for the neighbours |
| 47 | typedef TaxVertexLinkcxx . . $ TaxonomyVertex#TaxVertexLink#::const_iteratorcxx . . $ std/vector#const_iterator# const_iteratorcxx . . $ TaxonomyVertex#const_iterator#; |
| 48 | |
| 49 | private: // members |
| 50 | /// immediate parents and children |
| 51 | TaxVertexLinkcxx . . $ TaxonomyVertex#TaxVertexLink# Linkscxx . . $ TaxonomyVertex#Links.[2]; |
| 52 | |
| 53 | protected: // members |
| 54 | /// entry corresponding to current tax vertex |
| 55 | const ClassifiableEntrycxx . . $ ClassifiableEntry#* samplecxx . . $ TaxonomyVertex#sample. = nullptr; |
| 56 | /// synonyms of the sample entry |
| 57 | EqualNamescxx . . $ TaxonomyVertex#EqualNames# Synonymscxx . . $ TaxonomyVertex#Synonyms.; |
| 58 | |
| 59 | // labels for different purposes. all for 2 directions: top-down and bottom-up search |
| 60 | |
| 61 | /// flag if given vertex was checked; connected with checkLab |
| 62 | TLabellercxx . . $ TLabeller#::LabelTypecxx . . $ TLabeller#LabelType# theCheckedcxx . . $ TaxonomyVertex#theChecked.; |
| 63 | /// flag if given vertex has value; connected with valuedLab |
| 64 | TLabellercxx . . $ TLabeller#::LabelTypecxx . . $ TLabeller#LabelType# theValuedcxx . . $ TaxonomyVertex#theValued.; |
| 65 | /// number of common parents of a node |
| 66 | unsigned int commoncxx . . $ TaxonomyVertex#common. = 0; |
| 67 | /// satisfiability value of a valued vertex |
| 68 | bool checkValuecxx . . $ TaxonomyVertex#checkValue. = false; |
| 69 | /// flag to check whether the vertex is in use |
| 70 | bool inUsecxx . . $ TaxonomyVertex#inUse. = true; |
| 71 | |
| 72 | protected: // methods |
| 73 | /// indirect RW access to Links |
| 74 | TaxVertexLinkcxx . . $ TaxonomyVertex#TaxVertexLink#& neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645). ( bool upDirection ) { return Linkscxx . . $ TaxonomyVertex#Links.[!upDirection]; } |
| 75 | /// indirect RO access to Links |
| 76 | const TaxVertexLinkcxx . . $ TaxonomyVertex#TaxVertexLink#& neighcxx . . $ TaxonomyVertex#neigh(58eee4fe2eb59d79). ( bool upDirection ) const { return Linkscxx . . $ TaxonomyVertex#Links.[!upDirection]; } |
| 77 | |
| 78 | /// print entry name and its synonyms (if any) |
| 79 | void printSynonymscxx . . $ TaxonomyVertex#printSynonyms(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const; |
| 80 | /// print neighbours of a vertex in given direction |
| 81 | void printNeighbourscxx . . $ TaxonomyVertex#printNeighbours(25a4e5f405a65361). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, bool upDirection ) const; |
| 82 | |
| 83 | public: // flags interface |
| 84 | |
| 85 | // checked part |
| 86 | bool isCheckedcxx . . $ TaxonomyVertex#isChecked(cb76649e174af24). ( const TLabellercxx . . $ TLabeller#& checkLab ) const { return checkLab.isLabelledcxx . . $ TLabeller#isLabelled(7ba91045e28e2316).(theCheckedcxx . . $ TaxonomyVertex#theChecked.); } |
| 87 | void setCheckedcxx . . $ TaxonomyVertex#setChecked(9ce72ecab6fc8b2b). ( const TLabellercxx . . $ TLabeller#& checkLab ) { checkLab.setcxx . . $ TLabeller#set(702af1567bd3bb3c).(theCheckedcxx . . $ TaxonomyVertex#theChecked.); } |
| 88 | |
| 89 | // value part |
| 90 | bool isValuedcxx . . $ TaxonomyVertex#isValued(cb76649e174af24). ( const TLabellercxx . . $ TLabeller#& valueLab ) const { return valueLab.isLabelledcxx . . $ TLabeller#isLabelled(7ba91045e28e2316).(theValuedcxx . . $ TaxonomyVertex#theValued.); } |
| 91 | bool getValuecxx . . $ TaxonomyVertex#getValue(50ce9a9e25b4a850). ( void ) const { return checkValuecxx . . $ TaxonomyVertex#checkValue.; } |
| 92 | bool setValuedcxx . . $ TaxonomyVertex#setValued(2aa7d625c7d36b5d). ( bool val, const TLabellercxx . . $ TLabeller#& valueLab ) |
| 93 | { |
| 94 | valueLab.setcxx . . $ TLabeller#set(702af1567bd3bb3c).(theValuedcxx . . $ TaxonomyVertex#theValued.); |
| 95 | checkValuecxx . . $ TaxonomyVertex#checkValue. = val; |
| 96 | return val; |
| 97 | } |
| 98 | |
| 99 | // common part |
| 100 | bool isCommoncxx . . $ TaxonomyVertex#isCommon(50ce9a9e25b4a850). ( void ) const { return commoncxx . . $ TaxonomyVertex#common. != 0; } |
| 101 | void setCommoncxx . . $ TaxonomyVertex#setCommon(49f6e7a06ebc5aa8). ( void ) { ++commoncxx . . $ TaxonomyVertex#common.; } |
| 102 | void clearCommoncxx . . $ TaxonomyVertex#clearCommon(49f6e7a06ebc5aa8). ( void ) { commoncxx . . $ TaxonomyVertex#common. = 0; } |
| 103 | /// keep COMMON flag iff both flags are set; @return true if it is the case |
| 104 | bool correctCommoncxx . . $ TaxonomyVertex#correctCommon(dfa6e707f7696010). ( unsigned int n ) |
| 105 | { |
| 106 | if ( commoncxx . . $ TaxonomyVertex#common. == n ) |
| 107 | return true; |
| 108 | clearCommoncxx . . $ TaxonomyVertex#clearCommon(49f6e7a06ebc5aa8).(); |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | /// put initial values on the flags |
| 113 | void initFlagscxx . . $ TaxonomyVertex#initFlags(49f6e7a06ebc5aa8). ( void ) |
| 114 | { |
| 115 | TLabellercxx . . $ TLabeller#::clearcxx . . $ TLabeller#clear(db0e23f8c3d03d8b).(theCheckedcxx . . $ TaxonomyVertex#theChecked.); |
| 116 | TLabellercxx . . $ TLabeller#::clearcxx . . $ TLabeller#clear(db0e23f8c3d03d8b).(theValuedcxx . . $ TaxonomyVertex#theValued.); |
| 117 | clearCommoncxx . . $ TaxonomyVertex#clearCommon(49f6e7a06ebc5aa8).(); |
| 118 | } |
| 119 | |
| 120 | // get info about taxonomy structure |
| 121 | |
| 122 | const EqualNamescxx . . $ TaxonomyVertex#EqualNames#& synonymscxx . . $ TaxonomyVertex#synonyms(c783afb9bc916663). ( void ) const { return Synonymscxx . . $ TaxonomyVertex#Synonyms.; } |
| 123 | |
| 124 | /// mark vertex as the one corresponding to a given ENTRY |
| 125 | void setVertexAsHostcxx . . $ TaxonomyVertex#setVertexAsHost(25e3a48069a92e6e). ( const ClassifiableEntrycxx . . $ ClassifiableEntry#* entry ) { const_cast<ClassifiableEntrycxx . . $ ClassifiableEntry#*>(entry)->setTaxVertexcxx . . $ ClassifiableEntry#setTaxVertex(ea5ea6ad7488bb8a).(this); } |
| 126 | /// set sample to ENTRY |
| 127 | void setSamplecxx . . $ TaxonomyVertex#setSample(c310a0381288b48e). ( const ClassifiableEntrycxx . . $ ClassifiableEntry#* entry, bool linkBack = true ) |
| 128 | { |
| 129 | samplecxx . . $ TaxonomyVertex#sample. = entry; |
| 130 | if ( likelycxx . . $ `Kernel/globaldef.h:28:10`!(linkBack) ) |
| 131 | setVertexAsHostcxx . . $ TaxonomyVertex#setVertexAsHost(25e3a48069a92e6e).(entry); |
| 132 | } |
| 133 | |
| 134 | public: |
| 135 | /// empty c'tor |
| 136 | TaxonomyVertexcxx . . $ TaxonomyVertex#TaxonomyVertex(49f6e7a06ebc5aa8).() { initFlagscxx . . $ TaxonomyVertex#initFlags(49f6e7a06ebc5aa8).(); } |
| 137 | /// init c'tor; use it only for Top/Bot initialisations |
| 138 | explicit TaxonomyVertexcxx . . $ TaxonomyVertex#TaxonomyVertex(25e3a48069a92e6e). ( const ClassifiableEntrycxx . . $ ClassifiableEntry#* p ) : TaxonomyVertexcxx . . $ TaxonomyVertex#TaxonomyVertex(49f6e7a06ebc5aa8).() |
| 139 | { setSamplecxx . . $ TaxonomyVertex#setSample(c310a0381288b48e).(p); } |
| 140 | /// no copy |
| 141 | TaxonomyVertexcxx . . $ TaxonomyVertex#TaxonomyVertex(4e988596cd0e2c35). ( const TaxonomyVertexcxx . . $ TaxonomyVertex#& ) = delete; |
| 142 | /// no assignment |
| 143 | TaxonomyVertexcxx . . $ TaxonomyVertex#& operatorcxx . . $ TaxonomyVertex#`operator=`(25adcf0dc50dad2d). = ( const TaxonomyVertexcxx . . $ TaxonomyVertex#& ) = delete; |
| 144 | |
| 145 | /// add P as a synonym to current vertex |
| 146 | void addSynonymcxx . . $ TaxonomyVertex#addSynonym(25e3a48069a92e6e). ( const ClassifiableEntrycxx . . $ ClassifiableEntry#* p ) |
| 147 | { |
| 148 | Synonymscxx . . $ TaxonomyVertex#Synonyms..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p); |
| 149 | setVertexAsHostcxx . . $ TaxonomyVertex#setVertexAsHost(25e3a48069a92e6e).(p); |
| 150 | } |
| 151 | /// clears the vertex |
| 152 | void clearcxx . . $ TaxonomyVertex#clear(49f6e7a06ebc5aa8). ( void ) |
| 153 | { |
| 154 | Linkscxx . . $ TaxonomyVertex#Links.[0].clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 155 | Linkscxx . . $ TaxonomyVertex#Links.[1].clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 156 | samplecxx . . $ TaxonomyVertex#sample. = nullptr; |
| 157 | initFlagscxx . . $ TaxonomyVertex#initFlags(49f6e7a06ebc5aa8).(); |
| 158 | } |
| 159 | /// get RO access to the primer |
| 160 | const ClassifiableEntrycxx . . $ ClassifiableEntry#* getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a). ( void ) const { return samplecxx . . $ TaxonomyVertex#sample.; } |
| 161 | |
| 162 | /// add link in given direction to vertex |
| 163 | void addNeighbourcxx . . $ TaxonomyVertex#addNeighbour(93beaa2f49a74c7). ( bool upDirection, TaxonomyVertexcxx . . $ TaxonomyVertex#* p ) { neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(upDirection).push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p); } |
| 164 | /// check if vertex has no neighbours in given direction |
| 165 | bool noNeighbourscxx . . $ TaxonomyVertex#noNeighbours(962fae8be55e1d9). ( bool upDirection ) const { return neighcxx . . $ TaxonomyVertex#neigh(58eee4fe2eb59d79).(upDirection).emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); } |
| 166 | |
| 167 | // iterator access to parents/children |
| 168 | |
| 169 | iteratorcxx . . $ TaxonomyVertex#iterator# begincxx . . $ TaxonomyVertex#begin(98265602f6db0361). ( bool upDirection ) { return neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(upDirection).begincxx . . $ std/vector#begin(33b10a496a38335b).(); } |
| 170 | iteratorcxx . . $ TaxonomyVertex#iterator# endcxx . . $ TaxonomyVertex#end(98265602f6db0361). ( bool upDirection ) { return neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(upDirection).endcxx . . $ std/vector#end(33b10a496a38335b).(); } |
| 171 | |
| 172 | const_iteratorcxx . . $ TaxonomyVertex#const_iterator# begincxx . . $ TaxonomyVertex#begin(6bd8ccf6026be727). ( bool upDirection ) const { return neighcxx . . $ TaxonomyVertex#neigh(58eee4fe2eb59d79).(upDirection).begincxx . . $ std/vector#begin(359ca5030082c9f).(); } |
| 173 | const_iteratorcxx . . $ TaxonomyVertex#const_iterator# endcxx . . $ TaxonomyVertex#end(6bd8ccf6026be727). ( bool upDirection ) const { return neighcxx . . $ TaxonomyVertex#neigh(58eee4fe2eb59d79).(upDirection).endcxx . . $ std/vector#end(359ca5030082c9f).(); } |
| 174 | |
| 175 | /** Adds vertex to existing graph. For every Up, Down such that (Up->Down) |
| 176 | creates couple of links (Up->this), (this->Down). Don't work with synonyms!!! |
| 177 | */ |
| 178 | void incorporatecxx . . $ TaxonomyVertex#incorporate(49f6e7a06ebc5aa8). ( void ); |
| 179 | /// @return v if node represents a synonym (v=Up[i]==Down[j]); @return NULL otherwise |
| 180 | TaxonomyVertexcxx . . $ TaxonomyVertex#* getSynonymNodecxx . . $ TaxonomyVertex#getSynonymNode(e005a88f538258f6). ( void ) |
| 181 | { |
| 182 | // try to find Vertex such that Vertex\in Up and Vertex\in Down |
| 183 | for ( auto& upV: neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(true) ) |
| 184 | for ( const auto& downV: neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(false) ) |
| 185 | if ( upV == downV ) // found such vertex |
| 186 | return upV; |
| 187 | return nullptr; |
| 188 | } |
| 189 | /// Remove link to P from neighbours (given by flag). @return true if such link was removed |
| 190 | bool removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( bool upDirection, TaxonomyVertexcxx . . $ TaxonomyVertex#* p ); |
| 191 | /// clear all links in a given direction |
| 192 | void clearLinkscxx . . $ TaxonomyVertex#clearLinks(b45ddcbc8423892c). ( bool upDirection ) { neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(upDirection).clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); } |
| 193 | /// remove one half of a given node from a graph |
| 194 | void removeLinkscxx . . $ TaxonomyVertex#removeLinks(b45ddcbc8423892c). ( bool upDirection ); |
| 195 | /// remove given node from a graph |
| 196 | void removecxx . . $ TaxonomyVertex#remove(49f6e7a06ebc5aa8). ( void ) { removeLinkscxx . . $ TaxonomyVertex#removeLinks(b45ddcbc8423892c).(true); removeLinkscxx . . $ TaxonomyVertex#removeLinks(b45ddcbc8423892c).(false); setInUsecxx . . $ TaxonomyVertex#setInUse(b45ddcbc8423892c).(false); } |
| 197 | |
| 198 | // usage methods |
| 199 | |
| 200 | /// @return true iff the node is in use |
| 201 | bool isInUsecxx . . $ TaxonomyVertex#isInUse(50ce9a9e25b4a850). ( void ) const { return inUsecxx . . $ TaxonomyVertex#inUse.; } |
| 202 | /// set the inUse value of the node |
| 203 | void setInUsecxx . . $ TaxonomyVertex#setInUse(b45ddcbc8423892c). ( bool value ) { inUsecxx . . $ TaxonomyVertex#inUse. = value; } |
| 204 | |
| 205 | // output methods |
| 206 | |
| 207 | /// print taxonomy vertex in format <equals parents children> |
| 208 | void printcxx . . $ TaxonomyVertex#print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const; |
| 209 | |
| 210 | // save/load interface; implementation is in SaveLoad.cpp |
| 211 | |
| 212 | /// save label of the entry |
| 213 | void SaveLabelcxx . . $ TaxonomyVertex#SaveLabel(aaac402dd6f8bcf7). ( SaveLoadManagercxx . . $ SaveLoadManager#& m ) const; |
| 214 | /// load label of the entry |
| 215 | void LoadLabelcxx . . $ TaxonomyVertex#LoadLabel(da67b8e43f9c9b96). ( SaveLoadManagercxx . . $ SaveLoadManager#& m ); |
| 216 | /// save neighbours of the entry |
| 217 | void SaveNeighbourscxx . . $ TaxonomyVertex#SaveNeighbours(aaac402dd6f8bcf7). ( SaveLoadManagercxx . . $ SaveLoadManager#& m ) const; |
| 218 | /// load neighbours of the entry |
| 219 | void LoadNeighbourscxx . . $ TaxonomyVertex#LoadNeighbours(da67b8e43f9c9b96). ( SaveLoadManagercxx . . $ SaveLoadManager#& m ); |
| 220 | }; // TaxonomyVertex |
| 221 | |
| 222 | /// structure to sort tax vertices |
| 223 | struct TaxVertexLesscxx . . $ TaxVertexLess# |
| 224 | { |
| 225 | bool operatorcxx . . $ TaxVertexLess#`operator()`(9ab307e241b66f42).()(const TaxonomyVertexcxx . . $ TaxonomyVertex#* s1, const TaxonomyVertexcxx . . $ TaxonomyVertex#* s2) const |
| 226 | { return strcmp(s1->getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).(), s2->getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).()) < 0; } |
| 227 | }; |
| 228 | |
| 229 | /// sorted vertices set |
| 230 | typedef stdcxx . . $ std/::setcxx . . $ std/set#<const TaxonomyVertexcxx . . $ TaxonomyVertex#*, TaxVertexLesscxx . . $ TaxVertexLess#> TVSetcxx . . $ TVSet#; |
| 231 | |
| 232 | #endif // TAXVERTEX_H |