Debian Codegraph @

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

raw symbols SCIP
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 LOGICFEATURE_H
21 #define LOGICFEATURE_H
22
23 class TConcept;
24 class TRole;
25 class DLVertex;
26
27 // contains class for currently used logic's features
28 class LogicFeatures
29 {
30 protected: // types
31 enum lfEnum {
32 lfInvalid = 0,
33 // role description
34 lfTransitiveRoles = (1 << 0),
35 lfRolesSubsumption = (1 << 1),
36 lfDirectRoles = (1 << 2),
37 lfInverseRoles = (1 << 3),
38 lfRangeAndDomain = (1 << 4),
39 lfFunctionalRoles = (1 << 5),
40
41 // concept description
42 lfSomeConstructor = (1 << 6),
43 lfFConstructor = (1 << 7),
44 lfNConstructor = (1 << 8),
45 lfQConstructor = (1 << 9),
46 lfSingleton = (1 << 10),
47
48 // global description
49 lfGeneralAxioms = (1 << 11),
50 lfBothRoles = (1 << 12),
51
52 // new constructions
53 lfSelfRef = (1 << 13),
54 lfTopRole = (1 << 14),
55 };
56
57 protected: // members
58 /// all flags in one long
59 unsigned long flags = 0;
60
61 protected: // methods
62 /// set any flag
63 void setX ( lfEnum val ) { flags |= val; }
64 /// get value of any flag
65 bool getX ( lfEnum val ) const { return (flags & val) != 0; }
66
67 public: // interface
68 /// default c'tor
69 LogicFeatures() = default;
70 /// copy c'tor
71 LogicFeatures(const LogicFeatures&) = default;
72 /// assignment
73 LogicFeatures& operator = (const LogicFeatures&) = default;
74 /// operator add
75 LogicFeatures& operator |= ( const LogicFeatures& lf ) { flags |= lf.flags; return *this; }
76
77 // bool hasInverseRole ( void ) const { return getX(lfDirectRoles) && getX(lfInverseRoles); }
78 bool hasInverseRole ( void ) const { return getX(lfBothRoles); }
79 bool hasRoleHierarchy ( void ) const { return getX(lfRolesSubsumption); }
80 bool hasTransitiveRole ( void ) const { return getX(lfTransitiveRoles); }
81 bool hasSomeAll ( void ) const { return getX(lfSomeConstructor); }
82 bool hasFunctionalRestriction ( void ) const { return getX(lfFConstructor) || getX(lfFunctionalRoles); }
83 bool hasNumberRestriction ( void ) const { return getX(lfNConstructor); }
84 bool hasQNumberRestriction ( void ) const { return getX(lfQConstructor); }
85 bool hasSingletons ( void ) const { return getX(lfSingleton); }
86 bool hasSelfRef ( void ) const { return getX(lfSelfRef); }
87 bool hasTopRole ( void ) const { return getX(lfTopRole); }
88
89 // overall state
90
91 /// check whether no flags are set
92 bool empty ( void ) const { return flags == 0; }
93 /// get all the flags at once
94 unsigned long getAllFlags ( void ) const { return flags; }
95 /// set all flags to a given value; @return old value of the flags
96 unsigned long setAllFlags ( unsigned long value ) { unsigned long old = flags; flags = value; return old; }
97 /// clear all the flags
98 void clear ( void ) { setAllFlags(0); }
99
100 // collect statistic from different things
101
102 /// get features from given TConcept
103 void fillConceptData ( const TConcept* p );
104 /// get features from given TRole
105 void fillRoleData ( const TRole* p, bool both );
106 /// get features from given DAG entry with given sign
107 void fillDAGData ( const DLVertex& v, bool pos );
108
109 /// build bothRoles from single Roles flags
110 void mergeRoles ( void )
111 {
112 if ( getX(lfDirectRoles) && getX(lfInverseRoles) )
113 setX(lfBothRoles);
114 }
115 /// allow user to set presence of inverse roles
116 void setInverseRoles ( void ) { setX(lfBothRoles); }
117
118 /// write gathered features
119 void writeState ( void ) const;
120 }; // LogicFeatures
121
122 #endif