WordBoundaryInfo Struct Reference

#include <word-align-lattice.h>

Collaboration diagram for WordBoundaryInfo:

Public Types

enum  PhoneType {
  kNoPhone = 0, kWordBeginPhone, kWordEndPhone, kWordBeginAndEndPhone,
  kWordInternalPhone, kNonWordPhone
}
 

Public Member Functions

 WordBoundaryInfo (const WordBoundaryInfoOpts &opts)
 
 WordBoundaryInfo (const WordBoundaryInfoNewOpts &opts)
 
 WordBoundaryInfo (const WordBoundaryInfoNewOpts &opts, std::string word_boundary_file)
 
void Init (std::istream &stream)
 
PhoneType TypeOfPhone (int32 p) const
 

Public Attributes

std::vector< PhoneTypephone_to_type
 
int32 silence_label
 
int32 partial_word_label
 
bool reorder
 

Private Member Functions

void SetOptions (const std::string int_list, PhoneType phone_type)
 

Detailed Description

Definition at line 119 of file word-align-lattice.h.

Member Enumeration Documentation

◆ PhoneType

enum PhoneType
Enumerator
kNoPhone 
kWordBeginPhone 
kWordEndPhone 
kWordBeginAndEndPhone 
kWordInternalPhone 
kNonWordPhone 

Definition at line 136 of file word-align-lattice.h.

136  {
137  kNoPhone = 0,
142  kNonWordPhone // non-word phones are typically silence phones; but the point
143  // is that there is
144  // no word label associated with them in the lattice. If a silence phone
145  // had a word label with it, we'd have to call it kWordBeginAndEndPhone.
146  };

Constructor & Destructor Documentation

◆ WordBoundaryInfo() [1/3]

Definition at line 669 of file word-align-lattice.cc.

References WordBoundaryInfoOpts::partial_word_label, WordBoundaryInfoOpts::reorder, WordBoundaryInfoOpts::silence_has_olabels, WordBoundaryInfoOpts::silence_label, WordBoundaryInfoOpts::silence_phones, WordBoundaryInfoOpts::wbegin_and_end_phones, WordBoundaryInfoOpts::wbegin_phones, WordBoundaryInfoOpts::wend_phones, and WordBoundaryInfoOpts::winternal_phones.

669  {
670  SetOptions(opts.wbegin_phones, kWordBeginPhone);
671  SetOptions(opts.wend_phones, kWordEndPhone);
672  SetOptions(opts.wbegin_and_end_phones, kWordBeginAndEndPhone);
673  SetOptions(opts.winternal_phones, kWordInternalPhone);
674  SetOptions(opts.silence_phones, (opts.silence_has_olabels ?
676  reorder = opts.reorder;
677  silence_label = opts.silence_label;
678  partial_word_label = opts.partial_word_label;
679 }
void SetOptions(const std::string int_list, PhoneType phone_type)

◆ WordBoundaryInfo() [2/3]

Definition at line 681 of file word-align-lattice.cc.

References WordBoundaryInfoNewOpts::partial_word_label, WordBoundaryInfoNewOpts::reorder, and WordBoundaryInfoNewOpts::silence_label.

681  {
682  reorder = opts.reorder;
683  silence_label = opts.silence_label;
684  partial_word_label = opts.partial_word_label;
685 }

◆ WordBoundaryInfo() [3/3]

WordBoundaryInfo ( const WordBoundaryInfoNewOpts opts,
std::string  word_boundary_file 
)

Definition at line 687 of file word-align-lattice.cc.

References KALDI_ASSERT, WordBoundaryInfoNewOpts::partial_word_label, WordBoundaryInfoNewOpts::reorder, WordBoundaryInfoNewOpts::silence_label, and Input::Stream().

688  {
689  reorder = opts.reorder;
690  silence_label = opts.silence_label;
691  partial_word_label = opts.partial_word_label;
692  bool binary_in;
693  Input ki(word_boundary_file, &binary_in);
694  KALDI_ASSERT(!binary_in && "Not expecting binary word-boundary file.");
695  Init(ki.Stream());
696 }
void Init(std::istream &stream)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

Member Function Documentation

◆ Init()

void Init ( std::istream &  stream)

Definition at line 698 of file word-align-lattice.cc.

References kaldi::ConvertStringToInteger(), KALDI_ASSERT, KALDI_ERR, and kaldi::SplitStringToVector().

698  {
699  std::string line;
700  while (std::getline(stream, line)) {
701  std::vector<std::string> split_line;
702  SplitStringToVector(line, " \t\r", true, &split_line);// split the line by space or tab
703  int32 p = 0;
704  if (split_line.size() != 2 ||
705  !ConvertStringToInteger(split_line[0], &p))
706  KALDI_ERR << "Invalid line in word-boundary file: " << line;
707  KALDI_ASSERT(p > 0);
708  if (phone_to_type.size() <= static_cast<size_t>(p))
709  phone_to_type.resize(p+1, kNoPhone);
710  std::string t = split_line[1];
711  if (t == "nonword") phone_to_type[p] = kNonWordPhone;
712  else if (t == "begin") phone_to_type[p] = kWordBeginPhone;
713  else if (t == "singleton") phone_to_type[p] = kWordBeginAndEndPhone;
714  else if (t == "end") phone_to_type[p] = kWordEndPhone;
715  else if (t == "internal") phone_to_type[p] = kWordInternalPhone;
716  else
717  KALDI_ERR << "Invalid line in word-boundary file: " << line;
718  }
719  if (phone_to_type.empty())
720  KALDI_ERR << "Empty word-boundary file";
721 }
bool ConvertStringToInteger(const std::string &str, Int *out)
Converts a string into an integer via strtoll and returns false if there was any kind of problem (i...
Definition: text-utils.h:118
std::vector< PhoneType > phone_to_type
kaldi::int32 int32
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
Definition: text-utils.cc:63
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ SetOptions()

void SetOptions ( const std::string  int_list,
PhoneType  phone_type 
)
private

Definition at line 650 of file word-align-lattice.cc.

References rnnlm::i, KALDI_ASSERT, KALDI_ERR, and kaldi::SplitStringToIntegers().

650  {
651  KALDI_ASSERT(!int_list.empty() && phone_type != kNoPhone);
652  std::vector<int32> phone_list;
653  if (!kaldi::SplitStringToIntegers(int_list, ":",
654  false,
655  &phone_list)
656  || phone_list.empty())
657  KALDI_ERR << "Invalid argument to --*-phones option: " << int_list;
658  for (size_t i= 0; i < phone_list.size(); i++) {
659  if (phone_to_type.size() <= phone_list[i])
660  phone_to_type.resize(phone_list[i]+1, kNoPhone);
661  if (phone_to_type[phone_list[i]] != kNoPhone)
662  KALDI_ERR << "Phone " << phone_list[i] << "was given two incompatible "
663  "assignments.";
664  phone_to_type[phone_list[i]] = phone_type;
665  }
666 }
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:68
std::vector< PhoneType > phone_to_type
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ TypeOfPhone()

Member Data Documentation

◆ partial_word_label

◆ phone_to_type

std::vector<PhoneType> phone_to_type

Definition at line 154 of file word-align-lattice.h.

◆ reorder

◆ silence_label


The documentation for this struct was generated from the following files: