| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2011-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 TDAG2INTERFACE_H |
| 21 | #define TDAG2INTERFACE_Hcxx . . $ `Kernel/tDag2Interface.h:21:9`! |
| 22 | |
| 23 | #include "tDLExpression.h"cxx . . $ `<file>/Kernel/tDLExpression.h`/ |
| 24 | #include "tExpressionManager.h"cxx . . $ `<file>/Kernel/tExpressionManager.h`/ |
| 25 | #include "dlDag.h"cxx . . $ `<file>/Kernel/dlDag.h`/ |
| 26 | |
| 27 | /// class to translate DAG entities into the TDL* expressions |
| 28 | class TDag2Interfacecxx . . $ TDag2Interface# |
| 29 | { |
| 30 | protected: // members |
| 31 | /// DAG to be translated |
| 32 | const DLDagcxx . . $ DLDag#& Dagcxx . . $ TDag2Interface#Dag.; |
| 33 | /// expression manager |
| 34 | TExpressionManagercxx . . $ TExpressionManager#* Managercxx . . $ TDag2Interface#Manager.; |
| 35 | /// vector of cached concept expressions |
| 36 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<const TDLConceptExpressioncxx . . $ TDLConceptExpression#*> TransCcxx . . $ TDag2Interface#TransC.; |
| 37 | /// vector of cached data expressions |
| 38 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<const TDLDataExpressioncxx . . $ TDLDataExpression#*> TransDcxx . . $ TDag2Interface#TransD.; |
| 39 | |
| 40 | protected: // methods |
| 41 | /// build concept expression by a vertex V |
| 42 | const TDLConceptExpressioncxx . . $ TDLConceptExpression#* buildCExprcxx . . $ TDag2Interface#buildCExpr(716d868c34b48504). ( const DLVertexcxx . . $ DLVertex#& v ); |
| 43 | /// build data expression by a vertex V |
| 44 | const TDLDataExpressioncxx . . $ TDLDataExpression#* buildDExprcxx . . $ TDag2Interface#buildDExpr(b7f9bc3945e81617). ( const DLVertexcxx . . $ DLVertex#& v ); |
| 45 | /// create concept name by named entry |
| 46 | static const TDLConceptNamecxx . . $ TDLConceptName#* CNamecxx . . $ TDag2Interface#CName(b05f11f6e14b7b05). ( const TNamedEntrycxx . . $ TNamedEntry#* p ) { return dynamic_cast<const TDLConceptNamecxx . . $ TDLConceptName#*>(p->getEntitycxx . . $ TNamedEntry#getEntity(1a59bfca6295ee56).()); } |
| 47 | /// create individual name by named entry |
| 48 | static const TDLIndividualNamecxx . . $ TDLIndividualName#* INamecxx . . $ TDag2Interface#IName(34e92956fd3dcf62). ( const TNamedEntrycxx . . $ TNamedEntry#* p ) { return dynamic_cast<const TDLIndividualNamecxx . . $ TDLIndividualName#*>(p->getEntitycxx . . $ TNamedEntry#getEntity(1a59bfca6295ee56).()); } |
| 49 | /// create object role name by named entry |
| 50 | static const TDLObjectRoleNamecxx . . $ TDLObjectRoleName#* ORNamecxx . . $ TDag2Interface#ORName(f6b4e2a39c1153a). ( const TNamedEntrycxx . . $ TNamedEntry#* p ) { return dynamic_cast<const TDLObjectRoleNamecxx . . $ TDLObjectRoleName#*>(p->getEntitycxx . . $ TNamedEntry#getEntity(1a59bfca6295ee56).()); } |
| 51 | /// create data role name by named entry |
| 52 | static const TDLDataRoleNamecxx . . $ TDLDataRoleName#* DRNamecxx . . $ TDag2Interface#DRName(27b3a1391483e422). ( const TNamedEntrycxx . . $ TNamedEntry#* p ) { return dynamic_cast<const TDLDataRoleNamecxx . . $ TDLDataRoleName#*>(p->getEntitycxx . . $ TNamedEntry#getEntity(1a59bfca6295ee56).()); } |
| 53 | |
| 54 | public: // interface |
| 55 | /// init c'tor |
| 56 | TDag2Interfacecxx . . $ TDag2Interface#TDag2Interface(316ea3a9375416da). ( const DLDagcxx . . $ DLDag#& dag, TExpressionManagercxx . . $ TExpressionManager#* manager ) |
| 57 | : Dagcxx . . $ TDag2Interface#Dag.(dag) |
| 58 | , Managercxx . . $ TDag2Interface#Manager.(manager) |
| 59 | , TransCcxx . . $ TDag2Interface#TransC.(dag.sizecxx . . $ DLDag#size(fe4d2d262d4164a8).(),nullptr) |
| 60 | , TransDcxx . . $ std/vector#vector(229e4d6bd205de31).(dag.sizecxx . . $ DLDag#size(fe4d2d262d4164a8).(),nullptr) |
| 61 | {} |
| 62 | |
| 63 | /// make sure that size of expression cache is the same as the size of a DAG |
| 64 | void ensureDagSizecxx . . $ TDag2Interface#ensureDagSize(49f6e7a06ebc5aa8). ( void ) |
| 65 | { |
| 66 | size_tcxx . . $ size_t# ds = Dagcxx . . $ TDag2Interface#Dag..sizecxx . . $ DLDag#size(fe4d2d262d4164a8).(), ts = TransCcxx . . $ TDag2Interface#TransC..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 67 | if ( likelycxx . . $ `Kernel/globaldef.h:28:10`!(ds == ts) ) |
| 68 | return; |
| 69 | TransCcxx . . $ TDag2Interface#TransC..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(ds); |
| 70 | TransDcxx . . $ TDag2Interface#TransD..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(ds); |
| 71 | if ( unlikelycxx . . $ `Kernel/globaldef.h:29:10`!(ds>ts) ) |
| 72 | for ( ; ts != ds; ++ts ) |
| 73 | { |
| 74 | TransCcxx . . $ TDag2Interface#TransC.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).ts] = nullptr; |
| 75 | TransDcxx . . $ TDag2Interface#TransD.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).ts] = nullptr; |
| 76 | } |
| 77 | } |
| 78 | /// get concept expression corresponding index of vertex |
| 79 | const TDLConceptExpressioncxx . . $ TDLConceptExpression#* getCExprcxx . . $ TDag2Interface#getCExpr(aa86f64c869b3d9f). ( BipolarPointercxx . . $ BipolarPointer# p ) |
| 80 | { |
| 81 | if ( isNegativecxx . . $ isNegative(83c267b20bac841a).(p) ) |
| 82 | return Managercxx . . $ TDag2Interface#Manager.->Notcxx . . $ TExpressionManager#Not(a5147c10d6f77be7).(getCExprcxx . . $ TDag2Interface#getCExpr(aa86f64c869b3d9f).(inversecxx . . $ inverse(7864480464b09eea).(p))); |
| 83 | unsigned int i = (unsigned int)p; |
| 84 | if ( TransCcxx . . $ TDag2Interface#TransC.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i] == nullptr ) |
| 85 | TransCcxx . . $ TDag2Interface#TransC.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i] = buildCExprcxx . . $ TDag2Interface#buildCExpr(716d868c34b48504).(Dagcxx . . $ TDag2Interface#Dag.[cxx . . $ DLDag#`operator[]`(5fe3b8e96045ba2c).p]); |
| 86 | return TransCcxx . . $ TDag2Interface#TransC.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i]; |
| 87 | } |
| 88 | /// get data expression corresponding index of vertex |
| 89 | const TDLDataExpressioncxx . . $ TDLDataExpression#* getDExprcxx . . $ TDag2Interface#getDExpr(2bfb6d1592282b92). ( BipolarPointercxx . . $ BipolarPointer# p ) |
| 90 | { |
| 91 | if ( isNegativecxx . . $ isNegative(83c267b20bac841a).(p) ) |
| 92 | return Managercxx . . $ TDag2Interface#Manager.->DataNotcxx . . $ TExpressionManager#DataNot(83abbe967e1a7d33).(getDExprcxx . . $ TDag2Interface#getDExpr(2bfb6d1592282b92).(inversecxx . . $ inverse(7864480464b09eea).(p))); |
| 93 | unsigned int i = (unsigned int)p; |
| 94 | if ( TransDcxx . . $ TDag2Interface#TransD.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i] == nullptr ) |
| 95 | TransDcxx . . $ TDag2Interface#TransD.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i] = buildDExprcxx . . $ TDag2Interface#buildDExpr(b7f9bc3945e81617).(Dagcxx . . $ TDag2Interface#Dag.[cxx . . $ DLDag#`operator[]`(5fe3b8e96045ba2c).p]); |
| 96 | return TransDcxx . . $ TDag2Interface#TransD.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i]; |
| 97 | } |
| 98 | /// get expression corresponding index of vertex given the DATA flag |
| 99 | const TDLExpressioncxx . . $ TDLExpression#* getExprcxx . . $ TDag2Interface#getExpr(a077c67dd72591fa). ( BipolarPointercxx . . $ BipolarPointer# p, bool data ) |
| 100 | { |
| 101 | if ( data ) |
| 102 | return getDExprcxx . . $ TDag2Interface#getDExpr(2bfb6d1592282b92).(p); |
| 103 | else |
| 104 | return getCExprcxx . . $ TDag2Interface#getCExpr(aa86f64c869b3d9f).(p); |
| 105 | } |
| 106 | }; // TDag2Interface |
| 107 | |
| 108 | #endif |