Debian Codegraph @

Kernel/tDataEntry.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2005-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 TDATAENTRY_H
21 #define TDATAENTRY_Hcxx . . $ `Kernel/tDataEntry.h:21:9`!
22
23 #include "tNamedEntry.h"cxx . . $ `<file>/Kernel/tNamedEntry.h`/
24 #include "BiPointer.h"cxx . . $ `<file>/Kernel/BiPointer.h`/
25 #include "tLabeller.h"cxx . . $ `<file>/Kernel/tLabeller.h`/
26 #include "DataTypeComparator.h"cxx . . $ `<file>/Kernel/DataTypeComparator.h`/
27
28 // if min() and max() are defined, then they conflicts with a TDI members
29 #undef min
30 #undef max
31
32 /// class for representing general data restriction
33 class TDataIntervalcxx . . $ TDataInterval#
34 {
35 public: // members
36 /// left border of the interval
37 ComparableDTcxx . . $ ComparableDT# mincxx . . $ TDataInterval#min.;
38 /// right border of the interval
39 ComparableDTcxx . . $ ComparableDT# maxcxx . . $ TDataInterval#max.;
40 /// type of the left border
41 bool minExclcxx . . $ TDataInterval#minExcl.;
42 /// type of the right border
43 bool maxExclcxx . . $ TDataInterval#maxExcl.;
44
45 public: // interface
46
47 /// clear an interval
48 void clearcxx . . $ TDataInterval#clear(49f6e7a06ebc5aa8). ( void ) { mincxx . . $ TDataInterval#min. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). maxcxx . . $ TDataInterval#max. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). ComparableDTcxx . . $ ComparableDT#(); }
49
50 /// check if min value range have been set
51 bool hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850). ( void ) const { return mincxx . . $ TDataInterval#min..initedcxx . . $ ComparableDT#inited(50ce9a9e25b4a850).(); }
52 /// check if max value range have been set
53 bool hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850). ( void ) const { return maxcxx . . $ TDataInterval#max..initedcxx . . $ ComparableDT#inited(50ce9a9e25b4a850).(); }
54 /// no constraints
55 bool emptycxx . . $ TDataInterval#empty(50ce9a9e25b4a850). ( void ) const { return !hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() && !hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).(); }
56 /// closed interval
57 bool closedcxx . . $ TDataInterval#closed(50ce9a9e25b4a850). ( void ) const { return hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() && hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).(); }
58
59 /// update MIN border of an interval with VALUE wrt EXCL
60 bool updateMincxx . . $ TDataInterval#updateMin(f0fbbdfeeaf32751). ( bool excl, const ComparableDTcxx . . $ ComparableDT#& value )
61 {
62 if ( hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() ) // another min value: check if we need update
63 {
64 // constraint is >= or >
65 if ( mincxx . . $ TDataInterval#min. >cxx . . $ ComparableDT#`operator>`(91deb93419938144). value ) // was: {7,}; now: {5,}: no update needed
66 return false;
67 if ( mincxx . . $ TDataInterval#min. ==cxx . . $ ComparableDT#`operator==`(91deb93419938144). value && // was: (5,}; now: [5,}: no update needed
68 minExclcxx . . $ TDataInterval#minExcl. && !excl )
69 return false;
70 // fallthrough: update is necessary for everything else
71 }
72
73 mincxx . . $ TDataInterval#min. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). value;
74 minExclcxx . . $ TDataInterval#minExcl. = mincxx . . $ TDataInterval#min..correctMincxx . . $ ComparableDT#correctMin(efaadfb7dc14930a).(excl);
75 return true;
76 }
77 /// update MAX border of an interval with VALUE wrt EXCL
78 bool updateMaxcxx . . $ TDataInterval#updateMax(f0fbbdfeeaf32751). ( bool excl, const ComparableDTcxx . . $ ComparableDT#& value )
79 {
80 if ( hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() ) // another max value: check if we need update
81 {
82 // constraint is <= or <
83 if ( maxcxx . . $ TDataInterval#max. <cxx . . $ ComparableDT#`operator<`(91deb93419938144). value ) // was: {,5}; now: {,7}: no update needed
84 return false;
85 if ( maxcxx . . $ TDataInterval#max. ==cxx . . $ ComparableDT#`operator==`(91deb93419938144). value && // was: {,5); now: {,5]: no update needed
86 maxExclcxx . . $ TDataInterval#maxExcl. && !excl )
87 return false;
88 // fallthrough: update is necessary for everything else
89 }
90
91 maxcxx . . $ TDataInterval#max. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). value;
92 maxExclcxx . . $ TDataInterval#maxExcl. = maxcxx . . $ TDataInterval#max..correctMaxcxx . . $ ComparableDT#correctMax(efaadfb7dc14930a).(excl);
93 return true;
94 }
95 /// update given border of an interval with VALUE wrt EXCL
96 bool updatecxx . . $ TDataInterval#update(facbc98c3426075c). ( bool min, bool excl, const ComparableDTcxx . . $ ComparableDT#& value )
97 { return min ? updateMincxx . . $ TDataInterval#updateMin(f0fbbdfeeaf32751). ( excl, value ) : updateMaxcxx . . $ TDataInterval#updateMax(f0fbbdfeeaf32751). ( excl, value ); }
98 /// update wrt another interval
99 bool updatecxx . . $ TDataInterval#update(c0f23e3b36f53f16). ( const TDataIntervalcxx . . $ TDataInterval#& Int )
100 {
101 bool ret = false;
102 if ( Int.hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() )
103 ret |= updateMincxx . . $ TDataInterval#updateMin(f0fbbdfeeaf32751). ( Int.minExclcxx . . $ TDataInterval#minExcl., Int.mincxx . . $ TDataInterval#min. );
104 if ( Int.hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() )
105 ret |= updateMaxcxx . . $ TDataInterval#updateMax(f0fbbdfeeaf32751). ( Int.maxExclcxx . . $ TDataInterval#maxExcl., Int.maxcxx . . $ TDataInterval#max. );
106 return ret;
107 }
108 /// @return true iff all the data is consistent wrt given TYPE
109 bool consistentcxx . . $ TDataInterval#consistent(91deb93419938144). ( const ComparableDTcxx . . $ ComparableDT#& dtype ) const
110 {
111 if ( hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() && !mincxx . . $ TDataInterval#min..compatiblecxx . . $ ComparableDT#compatible(91deb93419938144).(dtype) )
112 return false;
113 if ( hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() && !maxcxx . . $ TDataInterval#max..compatiblecxx . . $ ComparableDT#compatible(91deb93419938144).(dtype) )
114 return false;
115 return true;
116 }
117
118 /// print an interval
119 void Printcxx . . $ TDataInterval#Print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
120 {
121 if ( hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() )
122 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). (minExclcxx . . $ TDataInterval#minExcl. ? '(' : '[') <<cxx . . $ `operator<<`(e3894dd2e2b77146). mincxx . . $ TDataInterval#min.;
123 else
124 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '{';
125 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ',';
126 if ( hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() )
127 o <<cxx . . $ `operator<<`(e3894dd2e2b77146). maxcxx . . $ TDataInterval#max. <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). (maxExclcxx . . $ TDataInterval#maxExcl. ? ')' : ']');
128 else
129 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '}';
130 }
131 /// print an interval as a LISP; FIXME!! hack
132 void printLISPcxx . . $ TDataInterval#printLISP(5a62ef92febfbe9). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, const char* type ) const
133 {
134 if ( hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() && hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() )
135 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(and ";
136 if ( hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() )
137 {
138 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(g" <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). (minExclcxx . . $ TDataInterval#minExcl. ? 't' : 'e') <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). type;
139 mincxx . . $ TDataInterval#min..printValuecxx . . $ ComparableDT#printValue(be3b0a5ae87fb0b4).(o);
140 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "))";
141 }
142 if ( hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() )
143 {
144 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(l" <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). (maxExclcxx . . $ TDataInterval#maxExcl. ? 't' : 'e') <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). type;
145 maxcxx . . $ TDataInterval#max..printValuecxx . . $ ComparableDT#printValue(be3b0a5ae87fb0b4).(o);
146 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "))";
147 }
148 if ( hasMincxx . . $ TDataInterval#hasMin(50ce9a9e25b4a850).() && hasMaxcxx . . $ TDataInterval#hasMax(50ce9a9e25b4a850).() )
149 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
150 }
151 }; // TDataInterval
152
153 /// class for representing general data entry ("name" of data type or data value)
154 class TDataEntrycxx . . $ TDataEntry#: public TNamedEntrycxx . . $ TNamedEntry#
155 {
156 private: // members
157 /// label to use in relevant-only checks
158 TLabellercxx . . $ TLabeller#::LabelTypecxx . . $ TLabeller#LabelType# relcxx . . $ TDataEntry#rel.;
159
160 protected: // members
161 /// corresponding type (Type has NULL in the field)
162 const TDataEntrycxx . . $ TDataEntry#* Typecxx . . $ TDataEntry#Type.;
163 /// DAG index of the entry
164 BipolarPointercxx . . $ BipolarPointer# pNamecxx . . $ TDataEntry#pName.;
165 /// ComparableDT, used only for values
166 ComparableDTcxx . . $ ComparableDT# compcxx . . $ TDataEntry#comp.;
167 /// restriction to the entry
168 TDataIntervalcxx . . $ TDataInterval# Constraintscxx . . $ TDataEntry#Constraints.;
169
170 protected: // methods
171 /// set COMP for the (typed) data value
172 void setCompcxx . . $ TDataEntry#setComp(9c546c94e5fcce4e). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& typeName )
173 {
174 // FIXME!! do the thing properly; unify the usage of DT names
175 if ( typeName ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "string" )
176 compcxx . . $ TDataEntry#comp. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). ComparableDTcxx . . $ ComparableDT#ComparableDT(85c52e162fed56f9).(getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).());
177 else if ( typeName ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "number" )
178 compcxx . . $ TDataEntry#comp. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). ComparableDTcxx . . $ ComparableDT#(atol(getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).()));
179 else if ( typeName ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "real" )
180 compcxx . . $ TDataEntry#comp. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). ComparableDTcxx . . $ ComparableDT#ComparableDT(9364e6e7bff7660).((float)atof(getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).()));
181 else if ( typeName ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "bool" ) // FIXME!! dirty hack
182 compcxx . . $ TDataEntry#comp. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). ComparableDTcxx . . $ ComparableDT#(getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).());
183 else if ( typeName ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "time" )
184 compcxx . . $ TDataEntry#comp. =cxx . . $ ComparableDT#`operator=`(d6659132de7aa9cd). ComparableDTcxx . . $ ComparableDT#ComparableDT(3b75d2d14f60ac6a). ( atol(getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).()), 0 );
185 else // no more types available
186 fpp_unreachablecxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9).();
187 }
188
189 public: // interface
190 /// create data entry with given name
191 explicit TDataEntrycxx . . $ TDataEntry#TDataEntry(9c546c94e5fcce4e). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name )
192 : TNamedEntrycxx . . $ TNamedEntry#(name)
193 , Typecxx . . $ TDataEntry#Type.(nullptr)
194 , pNamecxx . . $ TDataEntry#pName.(bpINVALIDcxx . . $ bpINVALID.)
195 , compcxx . . $ TDataEntry#comp.()
196 {}
197 /// no copy c'tor
198 TDataEntrycxx . . $ TDataEntry#TDataEntry(846208f2324501dc). ( const TDataEntrycxx . . $ TDataEntry#& ) = delete;
199 /// no assignment
200 TDataEntrycxx . . $ TDataEntry#& operatorcxx . . $ TDataEntry#`operator=`(1235768f1c8c0d4). = ( const TDataEntrycxx . . $ TDataEntry#& ) = delete;
201
202 // type/value part
203
204 /// check if data entry represents basic data type
205 bool isBasicDataTypecxx . . $ TDataEntry#isBasicDataType(50ce9a9e25b4a850). ( void ) const { return Typecxx . . $ TDataEntry#Type. == nullptr && Constraintscxx . . $ TDataEntry#Constraints..emptycxx . . $ TDataInterval#empty(50ce9a9e25b4a850).(); }
206 /// check if data entry represents restricted data type
207 bool isRestrictedDataTypecxx . . $ TDataEntry#isRestrictedDataType(50ce9a9e25b4a850). ( void ) const { return !Constraintscxx . . $ TDataEntry#Constraints..emptycxx . . $ TDataInterval#empty(50ce9a9e25b4a850).(); }
208 /// check if data entry represents data value
209 bool isDataValuecxx . . $ TDataEntry#isDataValue(50ce9a9e25b4a850). ( void ) const { return Typecxx . . $ TDataEntry#Type. != nullptr && Constraintscxx . . $ TDataEntry#Constraints..emptycxx . . $ TDataInterval#empty(50ce9a9e25b4a850).(); }
210
211 /// set host data type for the data value
212 void setHostTypecxx . . $ TDataEntry#setHostType(e6573819832c2575). ( const TDataEntrycxx . . $ TDataEntry#* type ) { Typecxx . . $ TDataEntry#Type. = type; setCompcxx . . $ TDataEntry#setComp(9c546c94e5fcce4e).(typecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).()); }
213 /// get host type
214 const TDataEntrycxx . . $ TDataEntry#* getTypecxx . . $ TDataEntry#getType(bcfda270e2d2df96). ( void ) const { return Typecxx . . $ TDataEntry#Type.; }
215
216 /// get comparable variant of DE
217 const ComparableDTcxx . . $ ComparableDT#& getCompcxx . . $ TDataEntry#getComp(6323d4ca51d1ffbc). ( void ) const { return compcxx . . $ TDataEntry#comp.; }
218
219 // facet part
220
221 /// get RW access to constraints of the DE
222 TDataIntervalcxx . . $ TDataInterval#* getFacetcxx . . $ TDataEntry#getFacet(16432bf5479cc8c3). ( void ) { return &Constraintscxx . . $ TDataEntry#Constraints.; }
223 /// get RO access to constraints of the DE
224 const TDataIntervalcxx . . $ TDataInterval#* getFacetcxx . . $ TDataEntry#getFacet(e55f2b8bb1ed2996). ( void ) const { return &Constraintscxx . . $ TDataEntry#Constraints.; }
225
226 // relevance part
227
228 /// is given concept relevant to given Labeller's state
229 bool isRelevantcxx . . $ TDataEntry#isRelevant(cb76649e174af24). ( const TLabellercxx . . $ TLabeller#& lab ) const { return lab.isLabelledcxx . . $ TLabeller#isLabelled(7ba91045e28e2316).(relcxx . . $ TDataEntry#rel.); }
230 /// make given concept relevant to given Labeller's state
231 void setRelevantcxx . . $ TDataEntry#setRelevant(9ce72ecab6fc8b2b). ( const TLabellercxx . . $ TLabeller#& lab ) { lab.setcxx . . $ TLabeller#set(702af1567bd3bb3c).(relcxx . . $ TDataEntry#rel.); }
232
233 // BP part
234
235 /// get pointer to DAG entry corresponding to the data entry
236 BipolarPointercxx . . $ BipolarPointer# getBPcxx . . $ TDataEntry#getBP(455f465bc33b4cdf). ( void ) const { return pNamecxx . . $ TDataEntry#pName.; }
237 /// set DAG index of the data entry
238 void setBPcxx . . $ TDataEntry#setBP(d4f767463ce0a6b3). ( BipolarPointercxx . . $ BipolarPointer# p ) { pNamecxx . . $ TDataEntry#pName. = p; }
239
240 // printing LISP FIXME!!
241 void printLISPcxx . . $ TDataEntry#printLISP(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
242 {
243 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ';
244 if ( isBasicDataTypecxx . . $ TDataEntry#isBasicDataType(50ce9a9e25b4a850).() )
245 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
246 else if ( isDataValuecxx . . $ TDataEntry#isDataValue(50ce9a9e25b4a850).() )
247 {
248 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getTypecxx . . $ TDataEntry#getType(bcfda270e2d2df96).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
249 compcxx . . $ TDataEntry#comp..printValuecxx . . $ ComparableDT#printValue(be3b0a5ae87fb0b4).(o);
250 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
251 }
252 else if ( isRestrictedDataTypecxx . . $ TDataEntry#isRestrictedDataType(50ce9a9e25b4a850).() )
253 Constraintscxx . . $ TDataEntry#Constraints..printLISPcxx . . $ TDataInterval#printLISP(5a62ef92febfbe9). ( o, getTypecxx . . $ TDataEntry#getType(bcfda270e2d2df96).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() );
254 else
255 fpp_unreachablecxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9).();
256 }
257 }; // TDataEntry
258
259 inline stdcxx . . $ std/::ostreamcxx . . $ std/ostream#&
260 operatorcxx . . $ `operator<<`(71e68dfacb67ce94). << ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, const TDataIntervalcxx . . $ TDataInterval#& c )
261 {
262 c.Printcxx . . $ TDataInterval#Print(490063bd7e6d8d5d).(o);
263 return o;
264 }
265
266 #endif