Debian Codegraph @

FaCT++.Python/lib/Kernel/AtomicDecomposer.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 ATOMICDECOMPOSER_H
21 #define ATOMICDECOMPOSER_H
22
23 #include <ostream>
24
25 #include "tOntologyAtom.h"
26 #include "tSignature.h"
27 #include "Modularity.h"
28
29 class ProgressIndicatorInterface;
30
31 /// atomic ontology structure
32 class AOStructure
33 {
34 public: // types
35 /// vector of atoms as a type
36 typedef std::vector<TOntologyAtom*> AtomVec;
37 /// RW iterator of it
38 typedef AtomVec::iterator iterator;
39
40 protected: // members
41 /// all the atoms
42 AtomVec Atoms;
43
44 public: // interface
45 /// d'tor: delete all atoms
46 ~AOStructure()
47 {
48 for ( TOntologyAtom* atom : Atoms )
49 delete atom;
50 }
51
52 /// create a new atom and get a pointer to it
53 TOntologyAtom* newAtom ( void )
54 {
55 TOntologyAtom* ret = new TOntologyAtom();
56 ret->setId(Atoms.size());
57 Atoms.push_back(ret);
58 return ret;
59 }
60 /// reduce graph of the atoms in the structure
61 void reduceGraph ( void )
62 {
63 TOntologyAtom::AtomSet checked;
64 for ( TOntologyAtom* atom : Atoms )
65 atom->getAllDepAtoms(checked);
66 }
67
68 /// RW iterator begin
69 iterator begin ( void ) { return Atoms.begin(); }
70 /// RW iterator end
71 iterator end ( void ) { return Atoms.end(); }
72 /// get RW atom by its index
73 TOntologyAtom* operator[] ( unsigned int index ) { return Atoms[index]; }
74 /// get RO atom by its index
75 const TOntologyAtom* operator[] ( unsigned int index ) const { return Atoms[index]; }
76 /// size of the structure
77 size_t size ( void ) const { return Atoms.size(); }
78 }; // AOStructure
79
80 /// atomic decomposer of the ontology
81 class AtomicDecomposer
82 {
83 protected: // members
84 /// atomic structure to build
85 AOStructure* AOS = nullptr;
86 /// modularizer to build modules
87 TModularizer* pModularizer = nullptr;
88 /// tautologies of the ontology
89 AxiomVec Tautologies;
90 /// progress indicator
91 ProgressIndicatorInterface* PI = nullptr;
92 /// fake atom that represents the whole ontology
93 TOntologyAtom* rootAtom = nullptr;
94 /// module type for current AOS creation
95 ModuleType type;
96
97 protected: // methods
98 /// remove tautologies (axioms that are always local) from the ontology temporarily
99 void removeTautologies ( TOntology* O );
100 /// restore all tautologies back
101 void restoreTautologies ( void )
102 {
103 for ( TDLAxiom* axiom : Tautologies )
104 axiom->setUsed(true);
105 }
106 /// build a module for given signature SIG; use parent atom's module as a base for the module search
107 TOntologyAtom* buildModule ( const TSignature& sig, TOntologyAtom* parent );
108 /// create atom for given axiom AX; use parent atom's module as a base for the module search
109 TOntologyAtom* createAtom ( TDLAxiom* ax, TOntologyAtom* parent );
110
111 public: // interface
112 /// init c'tor; M would NOT be deleted in d'tor
113 explicit AtomicDecomposer ( TModularizer* m ) : pModularizer(m) {}
114 /// d'tor
115 ~AtomicDecomposer();
116
117 /// get the atomic structure for given module type TYPE
118 AOStructure* getAOS ( TOntology* O, ModuleType type );
119 /// get already created atomic structure
120 const AOStructure* getAOS ( void ) const { return AOS; }
121
122 /// set progress indicator to be PI
123 void setProgressIndicator ( ProgressIndicatorInterface* pi ) { PI = pi; }
124 /// get number of performed locality checks
125 unsigned long long getLocCheckNumber(void) const { return pModularizer->getNChecks(); }
126 }; // AtomicDecomposer
127
128 #endif