OpenMS  2.8.0
Classes | Friends | List of all members
FuzzyStringComparator Class Reference

Fuzzy comparison of strings, tolerates numeric differences. More...

#include <OpenMS/CONCEPT/FuzzyStringComparator.h>

Collaboration diagram for FuzzyStringComparator:
[legend]

Classes

struct  AbortComparison
 Internal exception class. More...
 
struct  InputLine
 Stores information about the current input line (i.e., stream for the line and the current position in the stream) More...
 
struct  PrefixInfo_
 Wrapper for the prefix information computed for the failure report. More...
 
struct  StreamElement_
 Stores information about characters, numbers, and white spaces loaded from the InputStream. More...
 

Friends

void Internal::ClassTest::testStringSimilar (const char *file, int line, const std::string &string_1, const char *string_1_stringified, const std::string &string_2, const char *string_2_stringified)
 
bool Internal::ClassTest::isFileSimilar (const std::string &, const std::string &)
 

the fabulous four

std::ostream * log_dest_
 Log and results output goes here. More...
 
std::string input_1_name_
 Name of first input e.g., filename. More...
 
std::string input_2_name_
 Name of second input e.g., filename. More...
 
InputLine input_line_1_
 
InputLine input_line_2_
 
int line_num_1_
 
int line_num_2_
 
int line_num_1_max_
 
int line_num_2_max_
 
std::string line_str_1_max_
 
std::string line_str_2_max_
 
double ratio_max_allowed_
 Maximum ratio of numbers allowed, see ratio_max_. More...
 
double ratio_max_
 Maximum ratio of numbers observed so far, see ratio_max_allowed_. More...
 
double absdiff_max_allowed_
 Maximum absolute difference of numbers allowed, see absdiff_max_. More...
 
double absdiff_max_
 Maximum difference of numbers observed so far, see absdiff_max_allowed_. More...
 
StreamElement_ element_1_
 Stores information about characters, numbers, and white spaces loaded from the first input stream. More...
 
StreamElement_ element_2_
 Stores information about characters, numbers, and white spaces loaded from the second input stream. More...
 
bool is_absdiff_small_
 
int verbose_level_
 
int tab_width_
 
int first_column_
 
bool is_status_success_
 Has comparison been successful so far? Note: this flag is changed in reportFailure_();. More...
 
bool use_prefix_
 use a prefix when reporting More...
 
StringList whitelist_
 Whitelist. More...
 
std::map< String, UIntwhitelist_cases_
 Occurrences of whitelist entries. More...
 
std::vector< std::pair< std::string, std::string > > matched_whitelist_
 Alternative Whitelist. More...
 
 FuzzyStringComparator ()
 Constructor. More...
 
virtual ~FuzzyStringComparator ()
 Destructor. More...
 
 FuzzyStringComparator (const FuzzyStringComparator &rhs)
 Copy constructor intentionally not implemented. More...
 
FuzzyStringComparatoroperator= (const FuzzyStringComparator &rhs)
 Assignment operator intentionally not implemented. More...
 
const double & getAcceptableRelative () const
 Acceptable relative error (a number >= 1.0) More...
 
void setAcceptableRelative (const double rhs)
 Acceptable relative error (a number >= 1.0) More...
 
const double & getAcceptableAbsolute () const
 Acceptable absolute difference (a number >= 0.0) More...
 
void setAcceptableAbsolute (const double rhs)
 Acceptable absolute difference (a number >= 0.0) More...
 
const StringListgetWhitelist () const
 White list. If both lines contain the same element from this list, they are skipped over. More...
 
StringListgetWhitelist ()
 White list. If both lines contain the same element from this list, they are skipped over. More...
 
void setWhitelist (const StringList &rhs)
 White list. If both lines contain the same element from this list, they are skipped over. More...
 
void setMatchedWhitelist (const std::vector< std::pair< std::string, std::string > > &rhs)
 Matched white list. If file 1 contains element 1 and file 2 contains element 2, they are skipped over. More...
 
const std::vector< std::pair< std::string, std::string > > & getMatchedWhitelist () const
 Matched white list. If file 1 contains element 1 and file 2 contains element 2, they are skipped over. More...
 
const int & getVerboseLevel () const
 verbose level More...
 
void setVerboseLevel (const int rhs)
 verbose level More...
 
const int & getTabWidth () const
 get tab width (for column numbers) More...
 
void setTabWidth (const int rhs)
 set tab width (for column numbers) More...
 
const int & getFirstColumn () const
 get first column (for column numbers) More...
 
void setFirstColumn (const int rhs)
 set first column (for column numbers) More...
 
std::ostream & getLogDestination () const
 Log output is written to this destination. More...
 
void setLogDestination (std::ostream &rhs)
 Log output is written to this destination. More...
 
bool compareStrings (std::string const &lhs, std::string const &rhs)
 Compare two strings. More...
 
bool compareStreams (std::istream &input_1, std::istream &input_2)
 Compare two streams of input. More...
 
bool compareFiles (const std::string &filename_1, const std::string &filename_2)
 Simple diff-like application to compare two input files. Numeric differences are tolerated up to a certain ratio or absolute difference. More...
 
bool compareLines_ (std::string const &line_str_1, std::string const &line_str_2)
 Compare two lines of input. More...
 
void reportSuccess_ () const
 Report good news. More...
 
void reportFailure_ (char const *const message) const
 
void writeWhitelistCases_ (const std::string &prefix) const
 Write info about hits in the whitelist. More...
 
void readNextLine_ (std::istream &input_stream, std::string &line_string, int &line_number) const
 
bool openInputFileStream_ (const std::string &filename, std::ifstream &input_stream) const
 opens and checks an input file stream std::ifstream More...
 

Detailed Description

Fuzzy comparison of strings, tolerates numeric differences.


Class Documentation

◆ OpenMS::FuzzyStringComparator::AbortComparison

struct OpenMS::FuzzyStringComparator::AbortComparison

Internal exception class.

Constructor & Destructor Documentation

◆ FuzzyStringComparator() [1/2]

Constructor.

◆ ~FuzzyStringComparator()

virtual ~FuzzyStringComparator ( )
virtual

Destructor.

◆ FuzzyStringComparator() [2/2]

Copy constructor intentionally not implemented.

Member Function Documentation

◆ compareFiles()

bool compareFiles ( const std::string &  filename_1,
const std::string &  filename_2 
)

Simple diff-like application to compare two input files. Numeric differences are tolerated up to a certain ratio or absolute difference.

where

Parameters
filename_1first input file
filename_2second input file
Returns
true in case of no differences found
See also
ratio_max_allowed_
absdiff_max_allowed_
verbose_level_

◆ compareLines_()

bool compareLines_ ( std::string const &  line_str_1,
std::string const &  line_str_2 
)
protected

Compare two lines of input.

This implements the core functionality. Intended to be used for a single line of input.

Returns
true (non-zero) in case of success

◆ compareStreams()

bool compareStreams ( std::istream &  input_1,
std::istream &  input_2 
)

Compare two streams of input.

This compares all lines of the input. Intended to be used for file streams.

Returns
true in case of no differences found

◆ compareStrings()

bool compareStrings ( std::string const &  lhs,
std::string const &  rhs 
)

Compare two strings.

This compares all lines of the input.

Returns
true in case of no differences found

◆ getAcceptableAbsolute()

const double& getAcceptableAbsolute ( ) const

Acceptable absolute difference (a number >= 0.0)

◆ getAcceptableRelative()

const double& getAcceptableRelative ( ) const

Acceptable relative error (a number >= 1.0)

◆ getFirstColumn()

const int& getFirstColumn ( ) const

get first column (for column numbers)

◆ getLogDestination()

std::ostream& getLogDestination ( ) const

Log output is written to this destination.

The default is std::cout. Use std::ostringstream etc. to save the output in a string.

◆ getMatchedWhitelist()

const std::vector< std::pair<std::string, std::string> >& getMatchedWhitelist ( ) const

Matched white list. If file 1 contains element 1 and file 2 contains element 2, they are skipped over.

◆ getTabWidth()

const int& getTabWidth ( ) const

get tab width (for column numbers)

◆ getVerboseLevel()

const int& getVerboseLevel ( ) const

verbose level

  • 0 = very quiet mode (absolutely no output)
  • 1 = quiet mode (no output unless differences detected)
  • 2 = default (include summary at end)
  • 3 = continue after errors

◆ getWhitelist() [1/2]

StringList& getWhitelist ( )

White list. If both lines contain the same element from this list, they are skipped over.

◆ getWhitelist() [2/2]

const StringList& getWhitelist ( ) const

White list. If both lines contain the same element from this list, they are skipped over.

◆ openInputFileStream_()

bool openInputFileStream_ ( const std::string &  filename,
std::ifstream &  input_stream 
) const
protected

opens and checks an input file stream std::ifstream

◆ operator=()

FuzzyStringComparator& operator= ( const FuzzyStringComparator rhs)

Assignment operator intentionally not implemented.

◆ readNextLine_()

void readNextLine_ ( std::istream &  input_stream,
std::string &  line_string,
int &  line_number 
) const
protected

read the next line in input stream, skipping over empty lines and lines consisting of whitespace only

◆ reportFailure_()

void reportFailure_ ( char const *const  message) const
protected

Report bad news.

Exceptions
AbortComparison

◆ reportSuccess_()

void reportSuccess_ ( ) const
protected

Report good news.

◆ setAcceptableAbsolute()

void setAcceptableAbsolute ( const double  rhs)

Acceptable absolute difference (a number >= 0.0)

◆ setAcceptableRelative()

void setAcceptableRelative ( const double  rhs)

Acceptable relative error (a number >= 1.0)

◆ setFirstColumn()

void setFirstColumn ( const int  rhs)

set first column (for column numbers)

◆ setLogDestination()

void setLogDestination ( std::ostream &  rhs)

Log output is written to this destination.

The default is std::cout. Use std::ostringstream etc. to save the output in a string.

There seems to be an issue with this under Windows, see comment in FuzzyStringComparator_test.cpp

◆ setMatchedWhitelist()

void setMatchedWhitelist ( const std::vector< std::pair< std::string, std::string > > &  rhs)

Matched white list. If file 1 contains element 1 and file 2 contains element 2, they are skipped over.

◆ setTabWidth()

void setTabWidth ( const int  rhs)

set tab width (for column numbers)

◆ setVerboseLevel()

void setVerboseLevel ( const int  rhs)

verbose level

  • 0 = very quiet mode (absolutely no output)
  • 1 = quiet mode (no output unless differences detected)
  • 2 = default (include summary at end)
  • 3 = continue after errors

◆ setWhitelist()

void setWhitelist ( const StringList rhs)

White list. If both lines contain the same element from this list, they are skipped over.

◆ writeWhitelistCases_()

void writeWhitelistCases_ ( const std::string &  prefix) const
protected

Write info about hits in the whitelist.

Friends And Related Function Documentation

◆ Internal::ClassTest::isFileSimilar

bool Internal::ClassTest::isFileSimilar ( const std::string &  ,
const std::string &   
)
friend

◆ Internal::ClassTest::testStringSimilar

void Internal::ClassTest::testStringSimilar ( const char *  file,
int  line,
const std::string &  string_1,
const char *  string_1_stringified,
const std::string &  string_2,
const char *  string_2_stringified 
)
friend

Member Data Documentation

◆ absdiff_max_

double absdiff_max_
protected

Maximum difference of numbers observed so far, see absdiff_max_allowed_.

◆ absdiff_max_allowed_

double absdiff_max_allowed_
protected

Maximum absolute difference of numbers allowed, see absdiff_max_.

◆ element_1_

StreamElement_ element_1_
protected

Stores information about characters, numbers, and white spaces loaded from the first input stream.

◆ element_2_

StreamElement_ element_2_
protected

Stores information about characters, numbers, and white spaces loaded from the second input stream.

◆ first_column_

int first_column_
protected

◆ input_1_name_

std::string input_1_name_
protected

Name of first input e.g., filename.

◆ input_2_name_

std::string input_2_name_
protected

Name of second input e.g., filename.

◆ input_line_1_

InputLine input_line_1_
protected

◆ input_line_2_

InputLine input_line_2_
protected

◆ is_absdiff_small_

bool is_absdiff_small_
protected

◆ is_status_success_

bool is_status_success_
protected

Has comparison been successful so far? Note: this flag is changed in reportFailure_();.

◆ line_num_1_

int line_num_1_
protected

◆ line_num_1_max_

int line_num_1_max_
protected

◆ line_num_2_

int line_num_2_
protected

◆ line_num_2_max_

int line_num_2_max_
protected

◆ line_str_1_max_

std::string line_str_1_max_
protected

◆ line_str_2_max_

std::string line_str_2_max_
protected

◆ log_dest_

std::ostream* log_dest_
protected

Log and results output goes here.

◆ matched_whitelist_

std::vector< std::pair<std::string, std::string> > matched_whitelist_
protected

Alternative Whitelist.

◆ ratio_max_

double ratio_max_
protected

Maximum ratio of numbers observed so far, see ratio_max_allowed_.

◆ ratio_max_allowed_

double ratio_max_allowed_
protected

Maximum ratio of numbers allowed, see ratio_max_.

◆ tab_width_

int tab_width_
protected

◆ use_prefix_

bool use_prefix_
protected

use a prefix when reporting

◆ verbose_level_

int verbose_level_
protected

◆ whitelist_

StringList whitelist_
protected

Whitelist.

◆ whitelist_cases_

std::map<String, UInt> whitelist_cases_
protected

Occurrences of whitelist entries.