Debian Codegraph @

Kernel/KnowledgeExplorer.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 KNOWLEDGEEXPLORER_H
21 #define KNOWLEDGEEXPLORER_H
22
23 #include "taxNamEntry.h"
24 #include "tDag2Interface.h"
25
26 // forward declarations
27 class TBox;
28 class DlCompletionTree;
29
30 /// class to perform a knowledge exploration
31 class KnowledgeExplorer
32 {
33 public: // types
34 /// type for the node in the completion graph
35 typedef const DlCompletionTree TCGNode;
36 /// type for the node vector
37 typedef std::vector<TCGNode*> TCGNodeVec;
38 /// type for a set of role expressions (used in KE to return stuff)
39 typedef std::set<const TDLRoleExpression*> TCGRoleSet;
40 /// type for a vector of data/concept expressions (used in KE to return stuff)
41 typedef std::vector<const TDLExpression*> TCGItemVec;
42
43 protected: // classes
44 /// class that maps named entity to a set of ENTITIES
45 template <typename Entity>
46 class EE2Map
47 {
48 public: // type interface
49 /// set of entities
50 typedef std::set<const Entity*> ESet;
51 /// RO iterator to the ESet
52 typedef typename ESet::const_iterator iterator;
53 protected: // members
54 /// the map itself
55 std::map<const TNamedEntity*, ESet> Base;
56 public: // interface
57 /// @return true if the entry does not have correspondent entity
58 bool check ( const TNamedEntry* e ) const;
59 /// add an entity corresponding E to a map corresponding to E0
60 void add ( const TNamedEntry* e0, const TNamedEntry* e )
61 {
62 // check for artificial constructions
63 if ( check(e) || check(e0) )
64 return;
65 const TNamedEntity* E0 = e0->getEntity(), *E = e->getEntity();
66 Base[E0].insert(dynamic_cast<const Entity*>(E));
67 }
68 /// get the set corresponding to the entity E
69 const ESet& get ( const TNamedEntity* e ) { return Base[e]; }
70 /// get the begin iterator of a set corresponding to the entity E
71 iterator begin ( const TNamedEntity* e ) { return Base[e].begin(); }
72 /// get the end iterator of a set corresponding to the entity E
73 iterator end ( const TNamedEntity* e ) { return Base[e].end(); }
74 }; // EE2Map
75
76 protected: // members
77 /// map concept into set of its synonyms
78 EE2Map<TDLConceptName> Cs;
79 /// map individual into set of its synonyms
80 EE2Map<TDLIndividualName> Is;
81 /// map object role to the set of its super-roles (self included)
82 EE2Map<TDLObjectRoleName> ORs;
83 /// map data role to the set of its super-roles (self included)
84 EE2Map<TDLDataRoleName> DRs;
85 /// dag-2-interface translator used in knowledge exploration
86 TDag2Interface D2I;
87 /// node vector to return
88 TCGNodeVec Nodes;
89 /// role set to return
90 TCGRoleSet Roles;
91 /// concept vector to return
92 TCGItemVec Concepts;
93
94 protected: // methods
95 /// adds an entity as a synonym to a map MAP
96 template <typename Entity>
97 void addE ( EE2Map<Entity>& map, const ClassifiableEntry* entry )
98 {
99 map.add(entry,entry);
100 if ( entry->isSynonym() )
101 map.add ( entry->getSynonym(), entry );
102 }
103 /// add concept-like expression E (possibly with synonyms) to CONCEPTS
104 void addC ( const TDLExpression* e );
105
106 public: // interface
107 /// init c'tor
108 KnowledgeExplorer ( const TBox* box, TExpressionManager* pEM );
109
110 /// @return the set of data neighbours of a NODE
111 const TCGRoleSet& getDataRoles ( const TCGNode* node, bool onlyDet );
112 /// @return the set of object neighbours of a NODE
113 const TCGRoleSet& getObjectRoles ( const TCGNode* node, bool onlyDet, bool needIncoming );
114 /// @return the set of neighbours of a NODE via role ROLE
115 const TCGNodeVec& getNeighbours ( const TCGNode* node, const TRole* role );
116 /// @return the set of all the expressions from the NODE label
117 const TCGItemVec& getLabel ( const TCGNode* node, bool onlyDet );
118 /// @return blocker of a blocked node NODE or NULL if node is not blocked
119 const TCGNode* getBlocker ( const TCGNode* node ) const;
120 }; // KnowledgeExplorer
121
122 #endif