simstring::writer_base< string_tmpl, ngram_generator_tmpl > Class Template Reference

Inheritance diagram for simstring::writer_base< string_tmpl, ngram_generator_tmpl >:

simstring::ngramdb_writer_base< string_tmpl, uint32_t, ngram_generator_tmpl >

Detailed Description

template<class string_tmpl, class ngram_generator_tmpl = ngram_generator>
class simstring::writer_base< string_tmpl, ngram_generator_tmpl >

A SimString database writer.

This template class builds a SimString database. The first template argument (string_tmpl) specifies the type of a character, and the second template argument (ngram_generator_tmpl) customizes generation of feature sets (n-grams) from strings.

Inheriting the base class ngramdb_writer_base that builds indices from n-grams to string IDs, this class maintains associations between strings and string IDs.

Parameters:
string_tmpl The type of a string.
ngram_generator_tmpl The type of an n-gram generator.


Public Types

typedef string_tmpl string_type
 The type representing a string.
typedef uint32_t value_type
 The type of values associated with key strings.
typedef ngram_generator_tmpl ngram_generator_type
 The function type for generating n-grams from a key string.
typedef string_type::value_type char_type
 The type representing a character.

Public Member Functions

 writer_base (const ngram_generator_type &gen)
 Constructs a writer object.
 writer_base (const ngram_generator_type &gen, const std::string &name)
 Constructs a writer object by opening a database.
virtual ~writer_base ()
 Destructs a writer object.
bool open (const std::string &name)
 Opens a database.
bool close ()
 Closes the database.
bool insert (const string_type &str)
 Inserts a string to the database.

Protected Attributes

std::string m_name
 The base name of the database.
std::ofstream m_ofs
 The output stream for the string collection.
int m_num_entries
 The number of strings in the database.


Constructor & Destructor Documentation

template<class string_tmpl, class ngram_generator_tmpl = ngram_generator>
simstring::writer_base< string_tmpl, ngram_generator_tmpl >::writer_base ( const ngram_generator_type gen  )  [inline]

Constructs a writer object.

Parameters:
gen The n-gram generator used by this writer.

template<class string_tmpl, class ngram_generator_tmpl = ngram_generator>
simstring::writer_base< string_tmpl, ngram_generator_tmpl >::writer_base ( const ngram_generator_type gen,
const std::string &  name 
) [inline]

Constructs a writer object by opening a database.

Parameters:
gen The n-gram generator used by this writer.
name The name of the database.


Member Function Documentation

template<class string_tmpl, class ngram_generator_tmpl = ngram_generator>
bool simstring::writer_base< string_tmpl, ngram_generator_tmpl >::open ( const std::string &  name  )  [inline]

Opens a database.

Parameters:
name The name of the database.
Returns:
bool true if the database is successfully opened, false otherwise.

template<class string_tmpl, class ngram_generator_tmpl = ngram_generator>
bool simstring::writer_base< string_tmpl, ngram_generator_tmpl >::close (  )  [inline]

Closes the database.

Parameters:
name The name of the database.
Returns:
bool true if the database is successfully opened, false otherwise.

template<class string_tmpl, class ngram_generator_tmpl = ngram_generator>
bool simstring::writer_base< string_tmpl, ngram_generator_tmpl >::insert ( const string_type str  )  [inline]

Inserts a string to the database.

Parameters:
str The string to be inserted.
Returns:
bool true if the string is successfully inserted, false otherwise.


Copyright (c) 2002-2010 by Naoaki Okazaki
Sun Mar 7 18:17:17 2010