Debian Codegraph @

Kernel/Taxonomy.cpp

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 /*******************************************************\
21 |* Implementation of taxonomy building for the FaCT++ *|
22 \*******************************************************/
23
24 #include "Taxonomy.h"cxx . . $ `<file>/Kernel/Taxonomy.h`/
25 #include "logging.h"cxx . . $ `<file>/Kernel/logging.h`/
26
27 /********************************************************\
28 |* Implementation of class Taxonomy *|
29 \********************************************************/
30 Taxonomycxx . . $ Taxonomy# :: ~cxx . . $ Taxonomy#`~Taxonomy`(49f6e7a06ebc5aa8).Taxonomycxx . . $ Taxonomy#()
31 {
32 delete Currentcxx . . $ Taxonomy#Current.;
33 for ( TaxVertexVeccxx . . $ Taxonomy#TaxVertexVec#::iteratorcxx . . $ std/vector#iterator# p = Graphcxx . . $ Taxonomy#Graph..begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = Graphcxx . . $ Taxonomy#Graph..endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
34 delete *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p;
35 }
36
37 void Taxonomycxx . . $ Taxonomy# :: printcxx . . $ Taxonomy#print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
38 {
39 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "All entries are in format:\n\"entry\" {n: parent_1 ... parent_n} {m: child_1 child_m}\n\n";
40
41 TVSetcxx . . $ TVSet# sortedcxx . . $ std/set#set(50ef72ff69bc573d).(Graphcxx . . $ Taxonomy#Graph..begincxx . . $ std/vector#begin(359ca5030082c9f).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).2, Graphcxx . . $ Taxonomy#Graph..endcxx . . $ std/vector#end(359ca5030082c9f).());
42
43 getTopVertexcxx . . $ Taxonomy#getTopVertex(16f9ca5fa66f7d36).()->printcxx . . $ TaxonomyVertex#print(490063bd7e6d8d5d).(o);
44 for ( const TaxonomyVertexcxx . . $ TaxonomyVertex#* vertex : sorted )
45 if ( likelycxx . . $ `Kernel/globaldef.h:28:10`!(vertex->isInUse()) )
46 vertex->printcxx . . $ TaxonomyVertex#print(490063bd7e6d8d5d).(o);
47 getBottomVertexcxx . . $ Taxonomy#getBottomVertex(16f9ca5fa66f7d36).()->printcxx . . $ TaxonomyVertex#print(490063bd7e6d8d5d).(o);
48 }
49
50 //---------------------------------------------------
51 // classification part
52 //---------------------------------------------------
53 void
54 Taxonomycxx . . $ Taxonomy# :: addCurrentToSynonymcxx . . $ Taxonomy#addCurrentToSynonym(ea5ea6ad7488bb8a). ( TaxonomyVertexcxx . . $ TaxonomyVertex#* syn )
55 {
56 const ClassifiableEntrycxx . . $ ClassifiableEntry#* curEntry = Currentcxx . . $ Taxonomy#Current.->getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).();
57 if ( queryModecxx . . $ Taxonomy#queryMode(50ce9a9e25b4a850).() ) // no need to insert; just mark SYN as a host to curEntry
58 syn->setVertexAsHostcxx . . $ TaxonomyVertex#setVertexAsHost(25e3a48069a92e6e).(curEntry);
59 else
60 {
61 syn->addSynonymcxx . . $ TaxonomyVertex#addSynonym(25e3a48069a92e6e).(curEntry);
62
63 if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llTaxInsertcxx . . $ llTaxInsert.) )
64 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nTAX:set " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). curEntry->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " equal " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). syn->getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
65 }
66 }
67
68 /// insert current node either directly or as a synonym
69 void
70 Taxonomycxx . . $ Taxonomy# :: finishCurrentNodecxx . . $ Taxonomy#finishCurrentNode(49f6e7a06ebc5aa8). ( void )
71 {
72 TaxonomyVertexcxx . . $ TaxonomyVertex#* syn = Currentcxx . . $ Taxonomy#Current.->getSynonymNodecxx . . $ TaxonomyVertex#getSynonymNode(e005a88f538258f6).();
73 if ( syn )
74 addCurrentToSynonymcxx . . $ Taxonomy#addCurrentToSynonym(ea5ea6ad7488bb8a).(syn);
75 else if ( !queryModecxx . . $ Taxonomy#queryMode(50ce9a9e25b4a850).() ) // insert node into taxonomy
76 {
77 Currentcxx . . $ Taxonomy#Current.->incorporatecxx . . $ TaxonomyVertex#incorporate(49f6e7a06ebc5aa8).();
78 Graphcxx . . $ Taxonomy#Graph..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(Currentcxx . . $ Taxonomy#Current.);
79 // we used the Current so need to create a new one
80 Currentcxx . . $ Taxonomy#Current. = new TaxonomyVertexcxx . . $ TaxonomyVertex#TaxonomyVertex(49f6e7a06ebc5aa8).();
81 }
82 }
83
84 bool Taxonomycxx . . $ Taxonomy# :: processSynonymcxx . . $ Taxonomy#processSynonym(c9857a73d68e59ba). ( void )
85 {
86 const ClassifiableEntrycxx . . $ ClassifiableEntry#* curEntry = Currentcxx . . $ Taxonomy#Current.->getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).();
87 const ClassifiableEntrycxx . . $ ClassifiableEntry#* syn = resolveSynonymcxx . . $ resolveSynonym(bd9f52c6ae4be57a).(curEntry);
88
89 if ( syn == curEntry )
90 return false; // not a synonym
91
92 // update synonym vertex:
93 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( syn->getTaxVertex() != nullptr );
94 addCurrentToSynonymcxx . . $ Taxonomy#addCurrentToSynonym(ea5ea6ad7488bb8a).(syn->getTaxVertexcxx . . $ ClassifiableEntry#getTaxVertex(16f9ca5fa66f7d36).());
95
96 return true;
97 }
98
99 /// call this method after taxonomy is built
100 void
101 Taxonomycxx . . $ Taxonomy# :: finalisecxx . . $ Taxonomy#finalise(49f6e7a06ebc5aa8). ( void )
102 { // create links from leaf concepts to bottom
103 const bool upDirection = false;
104 for ( TaxVertexVeccxx . . $ Taxonomy#TaxVertexVec#::iteratorcxx . . $ std/vector#iterator# p = Graphcxx . . $ Taxonomy#Graph..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).1, p_end = Graphcxx . . $ Taxonomy#Graph..endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
105 if ( likelycxx . . $ `Kernel/globaldef.h:28:10`!((*p)->isInUse()) && (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->noNeighbourscxx . . $ TaxonomyVertex#noNeighbours(962fae8be55e1d9).(upDirection) )
106 {
107 (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->addNeighbourcxx . . $ TaxonomyVertex#addNeighbour(93beaa2f49a74c7). ( upDirection, getBottomVertexcxx . . $ Taxonomy#getBottomVertex(16f9ca5fa66f7d36).() );
108 getBottomVertexcxx . . $ Taxonomy#getBottomVertex(16f9ca5fa66f7d36).()->addNeighbourcxx . . $ TaxonomyVertex#addNeighbour(93beaa2f49a74c7). ( !upDirection, *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p );
109 }
110 willInsertIntoTaxonomycxx . . $ Taxonomy#willInsertIntoTaxonomy. = false; // after finalisation one shouldn't add new entries to taxonomy
111 }
112
113 /// unlink the bottom from the taxonomy
114 void
115 Taxonomycxx . . $ Taxonomy# :: deFinalisecxx . . $ Taxonomy#deFinalise(49f6e7a06ebc5aa8). ( void )
116 {
117 const bool upDirection = true;
118 TaxonomyVertexcxx . . $ TaxonomyVertex#* bot = getBottomVertexcxx . . $ Taxonomy#getBottomVertex(16f9ca5fa66f7d36).();
119 for ( TaxonomyVertexcxx . . $ TaxonomyVertex#::iteratorcxx . . $ TaxonomyVertex#iterator# p = bot->begincxx . . $ TaxonomyVertex#begin(98265602f6db0361).(upDirection), p_end = bot->endcxx . . $ TaxonomyVertex#end(98265602f6db0361).(upDirection); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
120 (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( !upDirection, bot );
121 bot->clearLinkscxx . . $ TaxonomyVertex#clearLinks(b45ddcbc8423892c).(upDirection);
122 willInsertIntoTaxonomycxx . . $ Taxonomy#willInsertIntoTaxonomy. = true; // it's possible again to add entries
123 }