Example #1
0
void stringPairToFst(Strings const& inputTokens, std::vector<std::string> const& outputTokens,
                     IMutableHypergraph<Arc>* pHgResult,
                     StringToHypergraphOptions const& opts = StringToHypergraphOptions()) {
  if (inputTokens.size() != outputTokens.size()) {
    SDL_THROW_LOG(Hypergraph.stringPairToFst, IndexException,
                  "The two strings must have same number of words");
  }

  // 1. Create simple FSA from input tokens:
  stringToHypergraph(inputTokens, pHgResult, opts);

  // 2. Insert output tokens:
  IVocabularyPtr pVoc = pHgResult->getVocabulary();
  std::vector<std::string>::const_iterator it = outputTokens.begin();
  StateId stateId = pHgResult->start();
  const StateId finalId = pHgResult->final();
  while (stateId != finalId) {
    Arc* arc = pHgResult->outArc(stateId, 0);
    const Sym sym = opts.terminalMaybeUnk(pVoc.get(), *it);
    setFsmOutputLabel(pHgResult, *arc, sym);
    ++it;
    stateId = arc->head();
  }
}
Example #2
0
inline void writeLabel(Util::StringBuilder& out, Sym sym, IVocabularyPtr const& voc,
                       SymbolQuotation quote = kQuoted) {
  writeLabel(out, sym, voc.get(), quote);
}
Example #3
0
inline void writeLabel(std::ostream& out, Sym sym, IVocabularyPtr const& voc, SymbolQuotation quote = kQuoted) {
  writeLabel(out, sym, voc.get(), quote);
}
Example #4
0
void lookupAndPrintSymbols(ForwardIterator begin, ForwardIterator end, IVocabularyPtr const& pVoc,
                           std::ostream& out) {
  lookupAndPrintSymbols(begin, end, pVoc.get(), out);
}
Example #5
0
 GetSymbol(IVocabularyPtr const& pVoc) : pVoc(pVoc.get()) {}
Example #6
0
File: Syms.hpp Project: graehl/hyp
inline void print(std::ostream &out, Syms const& phrase, IVocabularyPtr const& vocab) {
  Util::printRangeState(out, vocab.get(), phrase);
}
Example #7
0
File: Syms.hpp Project: graehl/hyp
inline void print(std::ostream &out, Sym sym, IVocabularyPtr const& vocab
                  , char const* variablePrefix="X") {
  print(out, sym, vocab.get(), variablePrefix);
}
Example #8
0
File: Syms.hpp Project: graehl/hyp
inline std::string typedStrOrIndex(Sym sym, IVocabularyPtr const& pVoc) {
  return typedStrOrIndex(sym, pVoc.get());
}
Example #9
0
File: Syms.hpp Project: graehl/hyp
inline std::string orTypedIndex(Sym sym, IVocabularyPtr const& pVoc) {
  return orTypedIndex(sym, pVoc.get());
}
Example #10
0
File: Syms.hpp Project: graehl/hyp
inline std::string orId(Sym sym, IVocabularyPtr const& pVoc) {
  return orId(sym, pVoc.get());
}