Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
Pattern.hh
Go to the documentation of this file.
1 #ifndef SGM_PATTERN_HH_
2 #define SGM_PATTERN_HH_
3 
4 #include "sgm/Graph_Interface.hh"
5 #include "sgm/Match.hh"
6 #include <climits>
7 
8 
9 namespace sgm {
10 
11 
12  /*! @brief Pattern description to be matched
13  *
14  * Abstract pattern description to be used in graph matching algorithms.
15  *
16  * @author Martin Mann - 2010 - http://www.bioinf.uni-freiburg.de/~mmann/
17  */
19 
20  public:
21 
22  //=========================================================================
23 
24 
25  /*!
26  * A match constraint describes additional properties that have to be
27  * fullfilled by a given match on a given target.
28  *
29  */
31 
32  public:
33 
34  //! construction
36  {}
37 
38  //! destruction
39  virtual
41  {}
42 
43  /*!
44  * Checks whether or not a match on a given target fullfills the
45  * additional matching constraint.
46  *
47  * @param pattern the pattern graph that was matched
48  * @param target the target graph the pattern was matched on
49  * @param match the match information for the pattern
50  * on the target graph
51  * @return true if the match is valid; false if the constraint is
52  * violated
53  */
54  virtual
55  bool
56  isValidMatch( const Pattern_Interface & pattern,
57  const Graph_Interface & target,
58  const Match & match ) const = 0;
59 
60  /*!
61  * Checks whether or not a given label is part of the constraint
62  * information. This check is needed by some parsers to verify the
63  * wildcard definition.
64  *
65  * @param label the label of interest
66  * @return true if the label is part of the constraint; false otherwise
67  */
68  virtual
69  bool
70  isConstrainedLabel( const std::string & label ) const = 0;
71 
72  /*!
73  * Checks whether or not this constraint covers the node with the
74  * given ID.
75  *
76  * @param nodeID the ID of the node of interest
77  * @return true if the node is covered by the constraint; false
78  * otherwise
79  */
80  virtual
81  bool
82  isConstraining( const size_t nodeID ) const = 0;
83 
84 
85  /*!
86  * Creates a new Match_Constraint heap object that equals the current
87  * object.
88  * NOTE: YOU have to delete it later on! There is no garbage
89  * collection!
90  * @return a new allocated Match_Constraint object that equals this
91  */
92  virtual
94  clone( void ) const = 0;
95 
96  /*!
97  * Creates a new Match_Constraint heap object that equals the current
98  * object but uses the new indices given by old2newIndexMapping.
99  * NOTE: YOU have to delete it later on! There is no garbage
100  * collection!
101  * @param old2newIndexMapping the index mapping to be used for the
102  * remapping
103  * @param unmatchedIndex an optional specific index that marks
104  * unmatched nodes within old2newIndexMapping. if this
105  * constrains one of these nodes, no remapping is done and
106  * NULL is returned
107  * @return a new allocated Match_Constraint object or NULL if the
108  * constraint was covering unmatched nodes
109  */
110  virtual
112  remap( const Match & old2newIndexMapping, const size_t unmatchedIndex = UINT_MAX ) = 0;
113 
114  /*!
115  * Equality comparison to another match constraint.
116  * @param toCompare the constraint to compare to
117  * @return true if the constraints are equal; false otherwise
118  */
119  virtual
120  bool
121  operator==( const Match_Constraint& toCompare ) const = 0;
122 
123  };
124 
125  //=========================================================================
126 
127 
128  //! container of matching constraints
129  typedef std::vector< Match_Constraint* > ConstraintVec;
130 
131 
132  public:
133 
134 
135  //! destruction
136  virtual ~Pattern_Interface();
137 
138  //! Equality comparison
139  //! @param toCompare the Pattern to compare to
140  //! @return true if both describe the same pattern
141  virtual
142  bool
143  operator==(const Pattern_Interface& toCompare ) const;
144 
145  //! Inequality comparison
146  //! @param toCompare the Pattern to compare to
147  //! @return true if both describe the different patterns
148  virtual
149  bool
150  operator!=(const Pattern_Interface& toCompare ) const;
151 
152 
153  //! Access to the pattern graph to be matched
154  //! @return the pattern graph
155  virtual
156  const Graph_Interface &
157  getPatternGraph( void ) const = 0;
158 
159  //! Access to the matching constraints that have to be fulfilled by
160  //! a match of this pattern graph
161  //! @return the matching constraints to validate
162  virtual
163  const ConstraintVec&
164  getConstraints( void ) const = 0;
165 
166  //! Access to the wildcard to be used when matching this pattern onto
167  //! some other graph.
168  //! @return the wildcard string to be used for edge and node labels,
169  //! or NULL if no wildcard should be applied
170  virtual
171  const std::string *
172  getUsedWildcard( void ) const = 0;
173 
174  };
175 
176 } // namespace sgm
177 
178 
179 
180 namespace sgm {
181 
182 
183  //! A wrapper class around a given Graph_interface that can serve as a
184  //! pattern.
185  //!
186  //! @author Martin Mann - 2010 - http://www.bioinf.uni-freiburg.de/~mmann/
187  //!
188  class Pattern : public Pattern_Interface {
189 
190  protected:
191 
192  //! the graph to be represented as a pattern
194 
195  //! the additional match constraints to be fulfilled by each match
197 
198  //! the wildcard string to be used for matching
199  const std::string * usedWildcard;
200 
201  public:
202 
203  //! constructs a pattern without additional constraints
204  //! @param graph the graph to represent
205  Pattern( const Graph_Interface& graph );
206 
207  //! constructs a pattern without additional constraints
208  //! @param graph the graph to represent
209  //! @param wildcardToUse the wildcard to use for matching
211  , const std::string & wildcardToUse );
212 
213  //! constructs a pattern with additional constraints
214  //! @param graph the graph to represent
215  //! @param matchConstraints the additional constraints to be fulfilled
217  , const ConstraintVec & matchConstraints );
218 
219  //! constructs a pattern with additional constraints
220  //! @param graph the graph to represent
221  //! @param matchConstraints the additional constraints to be fulfilled
222  //! @param wildcardToUse the wildcard to use for matching
225  , const std::string & wildcardToUse );
226 
227  //! copy construction
228  //! @param toCopy the pattern to make this object a copy of
229  Pattern( const Pattern& toCopy );
230 
231  //! destruction
232  virtual ~Pattern();
233 
234 
235  //! Access to the pattern graph to be matched
236  //! @return the pattern graph
237  virtual
238  const Graph_Interface &
239  getPatternGraph( void ) const;
240 
241  //! Access to the matching constraints that have to be fulfilled by
242  //! a match of this pattern graph
243  //! @return the matching constraints to validate
244  virtual
245  const ConstraintVec&
246  getConstraints( void ) const;
247 
248  //! Access to the wildcard to be used when matching this pattern onto
249  //! some other graph.
250  //! @return the wildcard string to be used for edge and node labels,
251  //! or NULL if no wildcard should be applied
252  virtual
253  const std::string *
254  getUsedWildcard( void ) const;
255 
256  //! assignment operator
257  //! @param toCopy the instance to make this a copy of
258  //! @return the altered object (*this)
259  sgm::Pattern&
260  operator=(const sgm::Pattern& toCopy );
261 
262  public:
263 
264  //! Does a deep copy of the given constraint vector
265  //! @param toCopy the ConstraintVec instance to copy
266  //! @return the deep copy of the given vector of MatchConstraints
267  static
269  copyConstraintVec( const ConstraintVec & toCopy );
270 
271  };
272 
273 } // namespace sgm
274 
275 
276 
277 #include <iostream>
278 #include <iomanip>
279 
280 
281  /*! Prints a Pattern instance to stream. For each node its label and
282  * the adjancent nodes including the edge label is printed.
283  *
284  * @param out the stream to write to
285  * @param g the graph to write
286  * @return the modified out stream
287  */
288 std::ostream&
289 operator <<( std::ostream & out, const sgm::Pattern& g );
290 
291 
292 #endif /*SGM_PATTERN_HH_*/