コード例 #1
0
size_t BlockHashIndex::FinalizeSave()
{
#ifdef WITH_THREADS
  m_threadPool.Stop(true);
#endif

  SaveLastRange();

  size_t relIndexPos = std::ftell(m_fileHandle) - m_fileHandleStart;

  std::fseek(m_fileHandle, m_fileHandleStart, SEEK_SET);
  ThrowingFwrite(&relIndexPos, sizeof(size_t), 1, m_fileHandle);

  std::fseek(m_fileHandle, m_fileHandleStart + relIndexPos, SEEK_SET);
  m_landmarks.save(m_fileHandle);

  size_t seekIndexSize = m_seekIndex.size();
  ThrowingFwrite(&seekIndexSize, sizeof(size_t), 1, m_fileHandle);
  ThrowingFwrite(&m_seekIndex[0], sizeof(size_t), seekIndexSize, m_fileHandle);

  ThrowingFwrite(&m_size, sizeof(size_t), 1, m_fileHandle);

  size_t fileHandleStop = std::ftell(m_fileHandle);
  return fileHandleStop - m_fileHandleStart + sizeof(m_orderBits)
         + sizeof(m_fingerPrintBits);
}
void LexicalReorderingTableCreator::Save()
{  
  ThrowingFwrite(&m_numScoreComponent, sizeof(m_numScoreComponent), 1, m_outFile);
  ThrowingFwrite(&m_multipleScoreTrees, sizeof(m_multipleScoreTrees), 1, m_outFile);
  for(size_t i = 0; i < m_scoreTrees.size(); i++)
    m_scoreTrees[i]->Save(m_outFile);
  
  m_compressedScores.save(m_outFile);
}
コード例 #3
0
void BlockHashIndex::BeginSave(std::FILE * mphf)
{
  m_fileHandle = mphf;
  ThrowingFwrite(&m_orderBits, sizeof(size_t), 1, m_fileHandle);
  ThrowingFwrite(&m_fingerPrintBits, sizeof(size_t), 1, m_fileHandle);

  m_fileHandleStart = std::ftell(m_fileHandle);

  size_t relIndexPos = 0;
  ThrowingFwrite(&relIndexPos, sizeof(size_t), 1, m_fileHandle);
}
コード例 #4
0
void PhraseTableCreator::Save()
{
  // Save type of encoding
  ThrowingFwrite(&m_coding, sizeof(m_coding), 1, m_outFile);
  ThrowingFwrite(&m_numScoreComponent, sizeof(m_numScoreComponent), 1, m_outFile);
  ThrowingFwrite(&m_useAlignmentInfo, sizeof(m_useAlignmentInfo), 1, m_outFile);
  ThrowingFwrite(&m_maxRank, sizeof(m_maxRank), 1, m_outFile);
  ThrowingFwrite(&m_maxPhraseLength, sizeof(m_maxPhraseLength), 1, m_outFile);

  if(m_coding == REnc) {
    // Save source language symbols for REnc
    std::vector<std::string> temp1;
    temp1.resize(m_sourceSymbolsMap.size());
    for(boost::unordered_map<std::string, unsigned>::iterator it
        = m_sourceSymbolsMap.begin(); it != m_sourceSymbolsMap.end(); it++)
      temp1[it->second] = it->first;
    std::sort(temp1.begin(), temp1.end());
    StringVector<unsigned char, unsigned, std::allocator> sourceSymbols;
    for(std::vector<std::string>::iterator it = temp1.begin();
        it != temp1.end(); it++)
      sourceSymbols.push_back(*it);
    sourceSymbols.save(m_outFile);

    // Save lexical translation table for REnc
    size_t size = m_lexicalTableIndex.size();
    ThrowingFwrite(&size, sizeof(size_t), 1, m_outFile);
    ThrowingFwrite(&m_lexicalTableIndex[0], sizeof(size_t), size, m_outFile);
    size = m_lexicalTable.size();
    ThrowingFwrite(&size, sizeof(size_t), 1, m_outFile);
    ThrowingFwrite(&m_lexicalTable[0], sizeof(SrcTrg), size, m_outFile);
  }

  // Save target language symbols
  std::vector<std::string> temp2;
  temp2.resize(m_targetSymbolsMap.size());
  for(boost::unordered_map<std::string, unsigned>::iterator it
      = m_targetSymbolsMap.begin(); it != m_targetSymbolsMap.end(); it++)
    temp2[it->second] = it->first;
  StringVector<unsigned char, unsigned, std::allocator> targetSymbols;
  for(std::vector<std::string>::iterator it = temp2.begin();
      it != temp2.end(); it++)
    targetSymbols.push_back(*it);
  targetSymbols.save(m_outFile);

  // Save Huffman codes for target language symbols
  m_symbolTree->Save(m_outFile);

  // Save number of Huffman code sets for scores and
  // save Huffman code sets
  ThrowingFwrite(&m_multipleScoreTrees, sizeof(m_multipleScoreTrees), 1, m_outFile);
  size_t numScoreTrees = m_scoreTrees.size();
  for(size_t i = 0; i < numScoreTrees; i++)
    m_scoreTrees[i]->Save(m_outFile);

  // Save Huffman codes for alignments
  if(m_useAlignmentInfo)
    m_alignTree->Save(m_outFile);

  // Save compressed target phrase collections
  m_compressedTargetPhrases->save(m_outFile);
}