Debian Codegraph @

FaCT++.Python/lib/Kernel/tSignatureUpdater.h

raw symbols SCIP
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 TSIGNATUREUPDATER_H
21 #define TSIGNATUREUPDATER_H
22
23 #include "tDLExpression.h"
24 #include "tSignature.h"
25
26 /// update the signature by adding all signature elements from the expression
27 class TExpressionSignatureUpdater: public DLExpressionVisitor
28 {
29 protected: // members
30 /// Signature to be filled
31 TSignature& sig;
32
33 protected: // methods
34 /// helper for concept arguments
35 void vC ( const TConceptArg& expr ) { expr.getC()->accept(*this); }
36 /// helper for individual arguments
37 void vI ( const TIndividualArg& expr ) { expr.getI()->accept(*this); }
38 /// helper for object role arguments
39 void vOR ( const TObjectRoleArg& expr ) { expr.getOR()->accept(*this); }
40 /// helper for object role arguments
41 void vDR ( const TDataRoleArg& expr ) { expr.getDR()->accept(*this); }
42 /// helper for the named entity
43 void vE ( const TNamedEntity& e ) { sig.add(e.getEntity()); }
44 /// array helper
45 template <typename Argument>
46 void processArray ( const TDLNAryExpression<Argument>& expr )
47 {
48 for ( typename TDLNAryExpression<Argument>::iterator p = expr.begin(), p_end = expr.end(); p != p_end; ++p )
49 (*p)->accept(*this);
50 }
51
52 public: // interface
53 /// init c'tor
54 explicit TExpressionSignatureUpdater ( TSignature& s ) : sig(s) {}
55
56 public: // visitor interface
57 // concept expressions
58 void visit ( const TDLConceptTop& ) override {}
59 void visit ( const TDLConceptBottom& ) override {}
60 void visit ( const TDLConceptName& expr ) override { vE(expr); }
61 void visit ( const TDLConceptNot& expr ) override { vC(expr); }
62 void visit ( const TDLConceptAnd& expr ) override { processArray(expr); }
63 void visit ( const TDLConceptOr& expr ) override { processArray(expr); }
64 void visit ( const TDLConceptOneOf& expr ) override { processArray(expr); }
65 void visit ( const TDLConceptObjectSelf& expr ) override { vOR(expr); }
66 void visit ( const TDLConceptObjectValue& expr ) override { vOR(expr); vI(expr); }
67 void visit ( const TDLConceptObjectExists& expr ) override { vOR(expr); vC(expr); }
68 void visit ( const TDLConceptObjectForall& expr ) override { vOR(expr); vC(expr); }
69 void visit ( const TDLConceptObjectMinCardinality& expr ) override { vOR(expr); vC(expr); }
70 void visit ( const TDLConceptObjectMaxCardinality& expr ) override { vOR(expr); vC(expr); }
71 void visit ( const TDLConceptObjectExactCardinality& expr ) override { vOR(expr); vC(expr); }
72 void visit ( const TDLConceptDataValue& expr ) override { vDR(expr); }
73 void visit ( const TDLConceptDataExists& expr ) override { vDR(expr); }
74 void visit ( const TDLConceptDataForall& expr ) override { vDR(expr); }
75 void visit ( const TDLConceptDataMinCardinality& expr ) override { vDR(expr); }
76 void visit ( const TDLConceptDataMaxCardinality& expr ) override { vDR(expr); }
77 void visit ( const TDLConceptDataExactCardinality& expr ) override { vDR(expr); }
78
79 // individual expressions
80 void visit ( const TDLIndividualName& expr ) override { vE(expr); }
81
82 // object role expressions
83 void visit ( const TDLObjectRoleTop& ) override {}
84 void visit ( const TDLObjectRoleBottom& ) override {}
85 void visit ( const TDLObjectRoleName& expr ) override { vE(expr); }
86 void visit ( const TDLObjectRoleInverse& expr ) override { vOR(expr); }
87 void visit ( const TDLObjectRoleChain& expr ) override { processArray(expr); }
88 void visit ( const TDLObjectRoleProjectionFrom& expr ) override { vOR(expr); vC(expr); }
89 void visit ( const TDLObjectRoleProjectionInto& expr ) override { vOR(expr); vC(expr); }
90
91 // data role expressions
92 void visit ( const TDLDataRoleTop& ) override {}
93 void visit ( const TDLDataRoleBottom& ) override {}
94 void visit ( const TDLDataRoleName& expr ) override { vE(expr); }
95
96 // data expressions
97 void visit ( const TDLDataTop& ) override {}
98 void visit ( const TDLDataBottom& ) override {}
99 void visit ( const TDLDataTypeName& ) override {}
100 void visit ( const TDLDataTypeRestriction& ) override {}
101 void visit ( const TDLDataValue& ) override {}
102 void visit ( const TDLDataNot& ) override {}
103 void visit ( const TDLDataAnd& ) override {}
104 void visit ( const TDLDataOr& ) override {}
105 void visit ( const TDLDataOneOf& ) override {}
106
107 // facets
108 void visit ( const TDLFacetMinInclusive& ) override {}
109 void visit ( const TDLFacetMinExclusive& ) override {}
110 void visit ( const TDLFacetMaxInclusive& ) override {}
111 void visit ( const TDLFacetMaxExclusive& ) override {}
112 }; // TExpressionSignatureUpdater
113
114 /// update signature by adding the signature of a given axiom to it
115 class TSignatureUpdater: public DLAxiomVisitor
116 {
117 protected: // members
118 /// helper with expressions
119 TExpressionSignatureUpdater Updater;
120
121 protected: // methods
122 /// helper for the expression processing
123 void v ( const TDLExpression* E ) { E->accept(Updater); }
124 /// helper for the [begin,end) interval
125 template <typename Iterator>
126 void v ( Iterator begin, Iterator end )
127 {
128 for ( ; begin != end; ++begin )
129 v(*begin);
130 }
131
132 public: // visitor interface
133 void visit ( const TDLAxiomDeclaration& axiom ) override { v(axiom.getDeclaration()); }
134
135 void visit ( const TDLAxiomEquivalentConcepts& axiom ) override { v ( axiom.begin(), axiom.end() ); }
136 void visit ( const TDLAxiomDisjointConcepts& axiom ) override { v ( axiom.begin(), axiom.end() ); }
137 void visit ( const TDLAxiomDisjointUnion& axiom ) override { v(axiom.getC()); v ( axiom.begin(), axiom.end() ); }
138 void visit ( const TDLAxiomEquivalentORoles& axiom ) override { v ( axiom.begin(), axiom.end() ); }
139 void visit ( const TDLAxiomEquivalentDRoles& axiom ) override { v ( axiom.begin(), axiom.end() ); }
140 void visit ( const TDLAxiomDisjointORoles& axiom ) override { v ( axiom.begin(), axiom.end() ); }
141 void visit ( const TDLAxiomDisjointDRoles& axiom ) override { v ( axiom.begin(), axiom.end() ); }
142 void visit ( const TDLAxiomSameIndividuals& axiom ) override { v ( axiom.begin(), axiom.end() ); }
143 void visit ( const TDLAxiomDifferentIndividuals& axiom ) override { v ( axiom.begin(), axiom.end() ); }
144 void visit ( const TDLAxiomFairnessConstraint& axiom ) override { v ( axiom.begin(), axiom.end() ); }
145
146 void visit ( const TDLAxiomRoleInverse& axiom ) override { v(axiom.getRole()); v(axiom.getInvRole()); }
147 void visit ( const TDLAxiomORoleSubsumption& axiom ) override { v(axiom.getRole()); v(axiom.getSubRole()); }
148 void visit ( const TDLAxiomDRoleSubsumption& axiom ) override { v(axiom.getRole()); v(axiom.getSubRole()); }
149 void visit ( const TDLAxiomORoleDomain& axiom ) override { v(axiom.getRole()); v(axiom.getDomain()); }
150 void visit ( const TDLAxiomDRoleDomain& axiom ) override { v(axiom.getRole()); v(axiom.getDomain()); }
151 void visit ( const TDLAxiomORoleRange& axiom ) override { v(axiom.getRole()); v(axiom.getRange()); }
152 void visit ( const TDLAxiomDRoleRange& axiom ) override { v(axiom.getRole()); v(axiom.getRange()); }
153 void visit ( const TDLAxiomRoleTransitive& axiom ) override { v(axiom.getRole()); }
154 void visit ( const TDLAxiomRoleReflexive& axiom ) override { v(axiom.getRole()); }
155 void visit ( const TDLAxiomRoleIrreflexive& axiom ) override { v(axiom.getRole()); }
156 void visit ( const TDLAxiomRoleSymmetric& axiom ) override { v(axiom.getRole()); }
157 void visit ( const TDLAxiomRoleAsymmetric& axiom ) override { v(axiom.getRole()); }
158 void visit ( const TDLAxiomORoleFunctional& axiom ) override { v(axiom.getRole()); }
159 void visit ( const TDLAxiomDRoleFunctional& axiom ) override { v(axiom.getRole()); }
160 void visit ( const TDLAxiomRoleInverseFunctional& axiom ) override { v(axiom.getRole()); }
161
162 void visit ( const TDLAxiomConceptInclusion& axiom ) override { v(axiom.getSubC()); v(axiom.getSupC()); }
163 void visit ( const TDLAxiomInstanceOf& axiom ) override { v(axiom.getIndividual()); v(axiom.getC()); }
164 void visit ( const TDLAxiomRelatedTo& axiom ) override { v(axiom.getIndividual()); v(axiom.getRelation()); v(axiom.getRelatedIndividual()); }
165 void visit ( const TDLAxiomRelatedToNot& axiom ) override { v(axiom.getIndividual()); v(axiom.getRelation()); v(axiom.getRelatedIndividual()); }
166 void visit ( const TDLAxiomValueOf& axiom ) override { v(axiom.getIndividual()); v(axiom.getAttribute()); }
167 void visit ( const TDLAxiomValueOfNot& axiom ) override { v(axiom.getIndividual()); v(axiom.getAttribute()); }
168
169 public: // interface
170 /// init c'tor
171 explicit TSignatureUpdater ( TSignature& sig ) : Updater(sig) {}
172 }; // TSignatureUpdater
173
174 #endif