Debian Codegraph @

FaCT++.Python/lib/Kernel/tOntologyAtom.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 TONTOLOGYATOM_H
21 #define TONTOLOGYATOM_H
22
23 #include <set>
24
25 #include "globaldef.h"
26 #include "tDLAxiom.h"
27
28 /// representation of the ontology atom
29 class TOntologyAtom
30 {
31 protected: // internal types
32 /// type to compare 2 atoms
33 struct AtomLess
34 {
35 bool operator()(const TOntologyAtom* a1, const TOntologyAtom* a2) const
36 { return a1->getId() < a2->getId(); }
37 };
38
39 public: // typedefs
40 /// set of axioms
41 typedef AxiomVec AxiomSet;
42 /// set of atoms
43 typedef std::set<TOntologyAtom*, AtomLess> AtomSet;
44
45 protected: // members
46 /// set of axioms in the atom
47 AxiomSet AtomAxioms;
48 /// set of axioms in the module (Atom's ideal)
49 AxiomSet ModuleAxioms;
50 /// set of atoms current one depends on
51 AtomSet DepAtoms;
52 /// set of all atoms current one depends on
53 AtomSet AllDepAtoms;
54 /// unique atom's identifier
55 size_t Id = 0;
56
57 protected: // methods
58 /// remove all atoms in AllDepAtoms from DepAtoms
59 void filterDep ( void )
60 {
61 for ( TOntologyAtom* atom : AllDepAtoms )
62 DepAtoms.erase(atom);
63 }
64 /// build all dep atoms; filter them from DepAtoms
65 void buildAllDepAtoms ( AtomSet& checked )
66 {
67 // first gather all dep atoms from all known dep atoms
68 for ( TOntologyAtom* atom : DepAtoms )
69 {
70 const AtomSet& Dep = atom->getAllDepAtoms(checked);
71 AllDepAtoms.insert ( Dep.begin(), Dep.end() );
72 }
73 // now filter them out from known dep atoms
74 filterDep();
75 // add direct deps to all deps
76 AllDepAtoms.insert ( DepAtoms.begin(), DepAtoms.end() );
77 // now the atom is checked
78 checked.insert(this);
79 }
80
81 public: // interface
82 /// set the module axioms
83 void setModule ( const AxiomSet& module ) { ModuleAxioms = module; }
84 /// add axiom AX to an atom
85 void addAxiom ( TDLAxiom* ax )
86 {
87 AtomAxioms.push_back(ax);
88 ax->setAtom(this);
89 }
90 /// add atom to the dependency set
91 void addDepAtom ( TOntologyAtom* atom )
92 {
93 if ( likely(atom != nullptr) && atom != this )
94 DepAtoms.insert(atom);
95 }
96 /// get all the atoms the current one depends on; build this set if necessary
97 const AtomSet& getAllDepAtoms ( AtomSet& checked )
98 {
99 if ( checked.count(this) == 0 ) // not build yet
100 buildAllDepAtoms(checked);
101 return AllDepAtoms;
102 }
103
104 // access to axioms
105
106 /// get all the atom's axioms
107 const AxiomSet& getAtomAxioms ( void ) const { return AtomAxioms; }
108 /// get all the module axioms
109 const AxiomSet& getModule ( void ) const { return ModuleAxioms; }
110 /// get atoms a given one depends on
111 const AtomSet& getDepAtoms ( void ) const { return DepAtoms; }
112
113 /// get the value of the id
114 size_t getId() const { return Id; }
115 /// set the value of the id to ID
116 void setId ( size_t id ) { Id = id; }
117 }; // TOntologyAtom
118
119 #endif