Debian Codegraph @

Kernel/taxVertex.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 vertex class *|
22 \*******************************************************/
23
24 #include <algorithm>
25 #include <ostream>
26
27 #include "taxVertex.h"cxx . . $ `<file>/Kernel/taxVertex.h`/
28 #include "logging.h"cxx . . $ `<file>/Kernel/logging.h`/
29
30 // removes given pointer from neigh.
31 bool TaxonomyVertexcxx . . $ TaxonomyVertex# :: removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( bool upDirection, TaxonomyVertexcxx . . $ TaxonomyVertex#* p )
32 {
33 // for all neighbours of current vertex...
34 auto& neighbours = neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(upDirection);
35 auto exists = stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(neighbours.begincxx . . $ std/vector#begin(33b10a496a38335b).(), neighbours.endcxx . . $ std/vector#end(33b10a496a38335b).(), p);
36 // Vertex P is not a neighbour -- nothing to do
37 if ( exists ==cxx . . $ __gnu_cxx/`operator==`(ef3c5749062e825c). neighbours.endcxx . . $ std/vector#end(33b10a496a38335b).() )
38 return false;
39 // replace P with the last entry
40 *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).exists = neighbours.backcxx . . $ std/vector#back(feee51535944b307).();
41 // remove last entry (by resizing)
42 neighbours.pop_backcxx . . $ std/vector#pop_back(49f6e7a06ebc5aa8).();
43 // there is at most one link to a node, so return now
44 return true;
45 }
46
47 void TaxonomyVertexcxx . . $ TaxonomyVertex# :: incorporatecxx . . $ TaxonomyVertex#incorporate(49f6e7a06ebc5aa8). ( void )
48 {
49 // setup links
50 auto& subs = neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(/*upDirection=*/false);
51 auto& supers = neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(/*upDirection=*/true);
52
53 // correct links on sub concepts...
54 for ( auto& sub: subs )
55 {
56 // remove all links between subs and supers, if exists
57 for ( auto& super: supers )
58 if ( sub->removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( /*upDirection=*/true, super ) )
59 super->removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( /*upDirection=*/false, sub );
60
61 // add new link between sub-class and current
62 sub->removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( /*upDirection=*/true, this ); // safe in general case (link doesn't exists), crucial for incremental
63 sub->addNeighbourcxx . . $ TaxonomyVertex#addNeighbour(93beaa2f49a74c7). ( /*upDirection=*/true, this );
64 }
65
66 // add new links between current and supers
67 for ( auto& super: supers )
68 super->addNeighbourcxx . . $ TaxonomyVertex#addNeighbour(93beaa2f49a74c7). ( /*upDirection=*/false, this );
69
70 CHECK_LL_RETURNcxx . . $ `Kernel/LeveLogger.h:60:9`!(llTaxInsert);
71
72 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nTAX:inserting '" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "' with up =";
73 printNeighbourscxx . . $ TaxonomyVertex#printNeighbours(25a4e5f405a65361). ( LLcxx . . $ LL., /*upDirection=*/true );
74 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " and down =";
75 printNeighbourscxx . . $ TaxonomyVertex#printNeighbours(25a4e5f405a65361). ( LLcxx . . $ LL., /*upDirection=*/false );
76 }
77
78 /// remove one half of a given node from a graph
79 void
80 TaxonomyVertexcxx . . $ TaxonomyVertex# :: removeLinkscxx . . $ TaxonomyVertex#removeLinks(b45ddcbc8423892c). ( bool upDirection )
81 {
82 for ( auto& vertex: neighcxx . . $ TaxonomyVertex#neigh(236378ee10472645).(upDirection) )
83 vertex->removeLinkcxx . . $ TaxonomyVertex#removeLink(d30eddcb12e17ac7). ( !upDirection, this );
84
85 clearLinkscxx . . $ TaxonomyVertex#clearLinks(b45ddcbc8423892c).(upDirection);
86 }
87
88 void TaxonomyVertexcxx . . $ TaxonomyVertex# :: printSynonymscxx . . $ TaxonomyVertex#printSynonyms(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
89 {
90 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( sample != nullptr );
91
92 if ( likelycxx . . $ `Kernel/globaldef.h:28:10`!(Synonyms.empty()) )
93 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '"' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '"';
94 else
95 {
96 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(\"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
97 for ( const auto& synonym: synonymscxx . . $ TaxonomyVertex#synonyms(c783afb9bc916663).() )
98 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\"=\"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). synonym->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
99 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\")";
100 }
101 }
102
103 void TaxonomyVertexcxx . . $ TaxonomyVertex# :: printNeighbourscxx . . $ TaxonomyVertex#printNeighbours(25a4e5f405a65361). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, bool upDirection ) const
104 {
105 // write number of elements
106 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " {" <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). neighcxx . . $ TaxonomyVertex#neigh(58eee4fe2eb59d79).(upDirection).sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ":";
107
108 TVSetcxx . . $ TVSet# sortedcxx . . $ std/set#set(50ef72ff69bc573d). ( begincxx . . $ TaxonomyVertex#begin(6bd8ccf6026be727).(upDirection), endcxx . . $ TaxonomyVertex#end(6bd8ccf6026be727).(upDirection) );
109 for ( auto vertex: sorted)
110 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). vertex->getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '"';
111
112 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "}";
113 }
114
115 /// print taxonomy vertex in format <equals parents children>
116 void
117 TaxonomyVertexcxx . . $ TaxonomyVertex# :: printcxx . . $ TaxonomyVertex#print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
118 {
119 printSynonymscxx . . $ TaxonomyVertex#printSynonyms(490063bd7e6d8d5d).(o);
120 printNeighbourscxx . . $ TaxonomyVertex#printNeighbours(25a4e5f405a65361). ( o, true );
121 printNeighbourscxx . . $ TaxonomyVertex#printNeighbours(25a4e5f405a65361). ( o, false );
122 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n";
123 }