| 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 program is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU General Public License |
| 7 | as published by the Free Software Foundation; either version 2 |
| 8 | of the License, or (at your option) any later version. |
| 9 | |
| 10 | This program 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 |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #ifndef PARSER_H |
| 21 | #define PARSER_Hcxx . . $ `FaCT++/parser.h:21:9`! |
| 22 | |
| 23 | #include "scanner.h"cxx . . $ `<file>/FaCT++/scanner.h`/ |
| 24 | #define GenericTokencxx . . $ `FaCT++/parser.h:24:9`! LispToken |
| 25 | #include "comparser.h"cxx . . $ `<file>/FaCT++/comparser.h`/ |
| 26 | #include "Kernel.h"cxx . . $ `<file>/Kernel/Kernel.h`/ |
| 27 | |
| 28 | /// class for parsing LISP-like ontologies |
| 29 | class DLLispParsercxx . . $ DLLispParser#: public CommonParsercxx . . $ CommonParser#<TsScannercxx . . $ TsScanner#> |
| 30 | { |
| 31 | protected: // typedefs |
| 32 | /// general expression |
| 33 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TExprcxx . . $ ReasoningKernel#TExpr# TExprcxx . . $ DLLispParser#TExpr#; |
| 34 | /// concept expression |
| 35 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TConceptExprcxx . . $ ReasoningKernel#TConceptExpr# TConceptExprcxx . . $ DLLispParser#TConceptExpr#; |
| 36 | /// individual expression |
| 37 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TIndividualExprcxx . . $ ReasoningKernel#TIndividualExpr# TIndividualExprcxx . . $ DLLispParser#TIndividualExpr#; |
| 38 | /// role expression |
| 39 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TRoleExprcxx . . $ ReasoningKernel#TRoleExpr# TRoleExprcxx . . $ DLLispParser#TRoleExpr#; |
| 40 | /// object role complex expression (including role chains and projections) |
| 41 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TORoleComplexExprcxx . . $ ReasoningKernel#TORoleComplexExpr# TORoleComplexExprcxx . . $ DLLispParser#TORoleComplexExpr#; |
| 42 | /// object role expression |
| 43 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TORoleExprcxx . . $ ReasoningKernel#TORoleExpr# TORoleExprcxx . . $ DLLispParser#TORoleExpr#; |
| 44 | /// data role expression |
| 45 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TDRoleExprcxx . . $ ReasoningKernel#TDRoleExpr# TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#; |
| 46 | /// data expression |
| 47 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TDataExprcxx . . $ ReasoningKernel#TDataExpr# TDataExprcxx . . $ DLLispParser#TDataExpr#; |
| 48 | /// data type expression |
| 49 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TDataTypeExprcxx . . $ ReasoningKernel#TDataTypeExpr# TDataTypeExprcxx . . $ DLLispParser#TDataTypeExpr#; |
| 50 | /// data value expression |
| 51 | typedef ReasoningKernelcxx . . $ ReasoningKernel#::TDataValueExprcxx . . $ ReasoningKernel#TDataValueExpr# TDataValueExprcxx . . $ DLLispParser#TDataValueExpr#; |
| 52 | |
| 53 | protected: // members |
| 54 | /// Kernel to be filled |
| 55 | ReasoningKernelcxx . . $ ReasoningKernel#* Kernelcxx . . $ DLLispParser#Kernel.; |
| 56 | /// expression manager to be used |
| 57 | TExpressionManagercxx . . $ TExpressionManager#* EManagercxx . . $ DLLispParser#EManager.; |
| 58 | /// set of known data role names |
| 59 | stdcxx . . $ std/::setcxx . . $ std/set#<stdcxx . . $ std/::stringcxx . . $ std/string#> DataRolescxx . . $ DLLispParser#DataRoles.; |
| 60 | |
| 61 | protected: // methods |
| 62 | /// error by given exception |
| 63 | void errorByExceptioncxx . . $ DLLispParser#errorByException(6b73d06f443355f0). ( const EFPPCantRegNamecxx . . $ EFPPCantRegName#& ex ) const { parseErrorcxx . . $ CommonParser#parseError(acfedb98bf840c77).(ex.whatcxx . . $ EFaCTPlusPlus#what(a9f41ea0e82d88cf).()); } |
| 64 | |
| 65 | /// @return concept-like Id of just scanned name |
| 66 | TConceptExprcxx . . $ DLLispParser#TConceptExpr#* getConceptcxx . . $ DLLispParser#getConcept(13b03fa3a15e39e7). ( void ) |
| 67 | { |
| 68 | TConceptExprcxx . . $ DLLispParser#TConceptExpr#* ret = EManagercxx . . $ DLLispParser#EManager.->Conceptcxx . . $ TExpressionManager#Concept(f43767f328f84e3).(scancxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); |
| 69 | NextLexcxx . . $ CommonParser#NextLex(49f6e7a06ebc5aa8).(); |
| 70 | return ret; |
| 71 | } |
| 72 | /// @return singleton Id of just scanned name |
| 73 | TIndividualExprcxx . . $ DLLispParser#TIndividualExpr#* getSingletoncxx . . $ DLLispParser#getSingleton(6b6c17f94ede7fae). ( void ) |
| 74 | { |
| 75 | TIndividualExprcxx . . $ DLLispParser#TIndividualExpr#* ret = EManagercxx . . $ DLLispParser#EManager.->Individualcxx . . $ TExpressionManager#Individual(fa65f56176e0b266).(scancxx . . $ CommonParser#scan..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); |
| 76 | NextLexcxx . . $ CommonParser#NextLex(49f6e7a06ebc5aa8).(); |
| 77 | return ret; |
| 78 | } |
| 79 | /// @return data- or object role build from just scanned name |
| 80 | TRoleExprcxx . . $ DLLispParser#TRoleExpr#* getRolecxx . . $ DLLispParser#getRole(fb30ad9ce55dbcf7). ( void ) |
| 81 | { |
| 82 | TRoleExprcxx . . $ DLLispParser#TRoleExpr#* ret; |
| 83 | if ( DataRolescxx . . $ DLLispParser#DataRoles..findcxx . . $ std/set#find(f8922f46a681e6cc).(scancxx . . $ CommonParser#scan..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()) !=cxx . . $ std/`operator!=`(7e1308a0738ea758). DataRolescxx . . $ DLLispParser#DataRoles..endcxx . . $ std/set#end(a1617ab40ea76896).() ) |
| 84 | ret = EManagercxx . . $ DLLispParser#EManager.->DataRolecxx . . $ TExpressionManager#DataRole(850aa2aceb89231f).(scancxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); // found data role |
| 85 | else // object role |
| 86 | ret = EManagercxx . . $ DLLispParser#EManager.->ObjectRolecxx . . $ TExpressionManager#ObjectRole(9eb6018165b5acba).(scancxx . . $ CommonParser#scan..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); |
| 87 | NextLexcxx . . $ CommonParser#NextLex(49f6e7a06ebc5aa8).(); |
| 88 | return ret; |
| 89 | } |
| 90 | /// @return data role build from just scanned name |
| 91 | TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#* getDataRolecxx . . $ DLLispParser#getDataRole(c543e5b0a3ce84d2). ( void ) |
| 92 | { |
| 93 | DataRolescxx . . $ DLLispParser#DataRoles..insertcxx . . $ std/set#insert(10916b2dbd511ba8).(scancxx . . $ CommonParser#scan..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); |
| 94 | TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#* ret = EManagercxx . . $ DLLispParser#EManager.->DataRolecxx . . $ TExpressionManager#DataRole(850aa2aceb89231f).(scancxx . . $ CommonParser#scan..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); |
| 95 | NextLexcxx . . $ CommonParser#NextLex(49f6e7a06ebc5aa8).(); |
| 96 | return ret; |
| 97 | } |
| 98 | /// @return object role build from just scanned name |
| 99 | TORoleExprcxx . . $ DLLispParser#TORoleExpr#* getObjectRolecxx . . $ DLLispParser#getObjectRole(c66348bd9c8594d4). ( void ) |
| 100 | { |
| 101 | TORoleExprcxx . . $ DLLispParser#TORoleExpr#* ret = EManagercxx . . $ DLLispParser#EManager.->ObjectRolecxx . . $ TExpressionManager#ObjectRole(9eb6018165b5acba).(scancxx . . $ CommonParser#scan..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).()); |
| 102 | NextLexcxx . . $ CommonParser#NextLex(49f6e7a06ebc5aa8).(); |
| 103 | return ret; |
| 104 | } |
| 105 | /// @return datavalue of a data type TYPE with an Id of a just scanned name |
| 106 | TDataValueExprcxx . . $ DLLispParser#TDataValueExpr#* getDTValuecxx . . $ DLLispParser#getDTValue(91bd0d659265132b). ( TDataTypeExprcxx . . $ DLLispParser#TDataTypeExpr#* type ) |
| 107 | { |
| 108 | TDataValueExprcxx . . $ DLLispParser#TDataValueExpr#* ret = EManagercxx . . $ DLLispParser#EManager.->DataValuecxx . . $ TExpressionManager#DataValue(20efe8b18616abe3). ( scancxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..GetNamecxx . . $ CommonScanner#GetName(a9f41ea0e82d88cf).(), type ); |
| 109 | NextLexcxx . . $ CommonParser#NextLex(49f6e7a06ebc5aa8).(); |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | /// check whether expression R is data role |
| 114 | bool isDataRolecxx . . $ DLLispParser#isDataRole(affb06d02a10040d). ( const TRoleExprcxx . . $ DLLispParser#TRoleExpr#* R ) const { return dynamic_cast<const TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#*>(R) != nullptr; } |
| 115 | /// generate object role axiom between R and S according to the operation TAG |
| 116 | void tellRoleAxiomcxx . . $ DLLispParser#tellRoleAxiom(45aca2c298be4c49). ( LispTokencxx . . $ LispToken# tag, TORoleExprcxx . . $ DLLispParser#TORoleExpr#* R, TORoleExprcxx . . $ DLLispParser#TORoleExpr#* S ); |
| 117 | /// generate data role axiom between R and S according to the operation TAG |
| 118 | void tellRoleAxiomcxx . . $ DLLispParser#tellRoleAxiom(a6b0df800255d88e). ( LispTokencxx . . $ LispToken# tag, TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#* R, TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#* S ); |
| 119 | /// get role expression, ie (data)role or its inverse |
| 120 | TRoleExprcxx . . $ DLLispParser#TRoleExpr#* getRoleExpressioncxx . . $ DLLispParser#getRoleExpression(fb30ad9ce55dbcf7). ( void ); |
| 121 | /// get object role expression, ie object role, OR constant or their inverse |
| 122 | TORoleExprcxx . . $ DLLispParser#TORoleExpr#* getORoleExpressioncxx . . $ DLLispParser#getORoleExpression(c66348bd9c8594d4). ( void ); |
| 123 | /// get data role expression, ie data role or DR constant |
| 124 | TDRoleExprcxx . . $ DLLispParser#TDRoleExpr#* getDRoleExpressioncxx . . $ DLLispParser#getDRoleExpression(c543e5b0a3ce84d2). ( void ); |
| 125 | /// get simple role expression or role projection or chain |
| 126 | TRoleExprcxx . . $ DLLispParser#TRoleExpr#* getComplexRoleExpressioncxx . . $ DLLispParser#getComplexRoleExpression(fb30ad9ce55dbcf7). ( void ); |
| 127 | /// parse simple DL command |
| 128 | void parseCommandcxx . . $ DLLispParser#parseCommand(49f6e7a06ebc5aa8). ( void ); |
| 129 | /// parse role arguments if defprimrole command |
| 130 | void parseRoleArgumentscxx . . $ DLLispParser#parseRoleArguments(4301d0bef5e81149). ( TORoleExprcxx . . $ DLLispParser#TORoleExpr#* role ); |
| 131 | /// parse list of concept expressions (in disjoint-like commands) |
| 132 | void parseConceptListcxx . . $ DLLispParser#parseConceptList(b45ddcbc8423892c). ( bool singletonsOnly ); |
| 133 | /// get concept-like expression for simple variants |
| 134 | TConceptExprcxx . . $ DLLispParser#TConceptExpr#* getConceptExpressioncxx . . $ DLLispParser#getConceptExpression(13b03fa3a15e39e7). ( void ); |
| 135 | /// get concept-like expression for complex constructors |
| 136 | TConceptExprcxx . . $ DLLispParser#TConceptExpr#* getComplexConceptExpressioncxx . . $ DLLispParser#getComplexConceptExpression(13b03fa3a15e39e7). ( void ); |
| 137 | /// get data expression |
| 138 | TDataExprcxx . . $ DLLispParser#TDataExpr#* getDataExpressioncxx . . $ DLLispParser#getDataExpression(52b0f360576e8085). ( void ); |
| 139 | |
| 140 | public: // interface |
| 141 | /// the only c'tor |
| 142 | DLLispParsercxx . . $ DLLispParser#DLLispParser(4766a9693cc45d57). ( stdcxx . . $ std/::istreamcxx . . $ std/istream#* in, ReasoningKernelcxx . . $ ReasoningKernel#* kernel ) |
| 143 | : CommonParsercxx . . $ CommonParser#CommonParser(6a35a7fc14119650).<TsScannercxx . . $ TsScanner#>(in) |
| 144 | , Kernelcxx . . $ DLLispParser#Kernel. (kernel) |
| 145 | , EManagercxx . . $ DLLispParser#EManager.(kernel->getExpressionManagercxx . . $ ReasoningKernel#getExpressionManager(867f96a8caac8aab).()) |
| 146 | { |
| 147 | // locally register Top/Bottom data properties |
| 148 | DataRolescxx . . $ DLLispParser#DataRoles..insertcxx . . $ std/set#insert(10916b2dbd511ba8).("*UDROLE*"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 149 | DataRolescxx . . $ DLLispParser#DataRoles..insertcxx . . $ std/set#insert(10916b2dbd511ba8).("*EDROLE*"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 150 | } |
| 151 | |
| 152 | /// main parsing method |
| 153 | void Parsecxx . . $ DLLispParser#Parse(49f6e7a06ebc5aa8). ( void ); |
| 154 | }; // DLLispParser |
| 155 | |
| 156 | #endif |