Download tools/mosesdecoder/moses/TranslationModel/CompactPT/BlockHashIndex.h from Quagmire1/wiki-cased: direct link, hf CLI and curl.
- Browser
- Download file 4.59 kB
-
https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses/TranslationModel/CompactPT/BlockHashIndex.h
- Command line
-
hf download hf://Quagmire1/wiki-cased/tools/mosesdecoder/moses/TranslationModel/CompactPT/BlockHashIndex.h
-
curl -L -o BlockHashIndex.h https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/moses/TranslationModel/CompactPT/BlockHashIndex.h
4.59 kB
| // $Id$ | |
| // vim:tabstop=2 | |
| /*********************************************************************** | |
| Moses - factored phrase-based language decoder | |
| Copyright (C) 2006 University of Edinburgh | |
| This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Lesser General Public | |
| License as published by the Free Software Foundation; either | |
| version 2.1 of the License, or (at your option) any later version. | |
| This library is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| Lesser General Public License for more details. | |
| You should have received a copy of the GNU Lesser General Public | |
| License along with this library; if not, write to the Free Software | |
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| ***********************************************************************/ | |
| namespace Moses | |
| { | |
| class BlockHashIndex | |
| { | |
| private: | |
| std::priority_queue<int> m_queue; | |
| size_t m_orderBits; | |
| size_t m_fingerPrintBits; | |
| std::FILE* m_fileHandle; | |
| size_t m_fileHandleStart; | |
| StringVector<unsigned char, unsigned long> m_landmarks; | |
| std::vector<void*> m_hashes; | |
| std::vector<clock_t> m_clocks; | |
| std::vector<PairedPackedArray<>*> m_arrays; | |
| std::vector<size_t> m_seekIndex; | |
| size_t m_size; | |
| int m_lastSaved; | |
| int m_lastDropped; | |
| size_t m_numLoadedRanges; | |
| ThreadPool m_threadPool; | |
| boost::mutex m_mutex; | |
| template <typename Keys> | |
| class HashTask : public Task | |
| { | |
| public: | |
| HashTask(int id, BlockHashIndex& hash, Keys& keys) | |
| : m_id(id), m_hash(hash), m_keys(new Keys(keys)) {} | |
| virtual void Run() { | |
| m_hash.CalcHash(m_id, *m_keys); | |
| } | |
| virtual ~HashTask() { | |
| delete m_keys; | |
| } | |
| private: | |
| int m_id; | |
| BlockHashIndex& m_hash; | |
| Keys* m_keys; | |
| }; | |
| size_t GetFprint(const char* key) const; | |
| size_t GetHash(size_t i, const char* key); | |
| public: | |
| BlockHashIndex(size_t orderBits, size_t fingerPrintBits, | |
| size_t threadsNum = 2); | |
| BlockHashIndex(size_t orderBits, size_t fingerPrintBits); | |
| ~BlockHashIndex(); | |
| size_t GetHash(const char* key); | |
| size_t GetHash(std::string key); | |
| size_t operator[](std::string key); | |
| size_t operator[](char* key); | |
| void BeginSave(std::FILE* mphf); | |
| void SaveRange(size_t i); | |
| void SaveLastRange(); | |
| size_t FinalizeSave(); | |
| void WaitAll(); | |
| void DropRange(size_t i); | |
| void DropLastRange(); | |
| size_t LoadIndex(std::FILE* mphf); | |
| void LoadRange(size_t i); | |
| size_t Save(std::string filename); | |
| size_t Save(std::FILE * mphf); | |
| size_t Load(std::string filename); | |
| size_t Load(std::FILE * mphf); | |
| size_t GetSize() const; | |
| void KeepNLastRanges(float ratio = 0.1, float tolerance = 0.1); | |
| template <typename Keys> | |
| void AddRange(Keys &keys) { | |
| size_t current = m_landmarks.size(); | |
| if(m_landmarks.size() && m_landmarks.back().str() >= keys[0]) { | |
| util::StringStream strme; | |
| strme << "ERROR: Input file does not appear to be sorted with LC_ALL=C sort\n"; | |
| strme << "1: " << m_landmarks.back().str() << "\n"; | |
| strme << "2: " << keys[0] << "\n"; | |
| UTIL_THROW2(strme.str()); | |
| } | |
| m_landmarks.push_back(keys[0]); | |
| m_size += keys.size(); | |
| if(keys.size() == 1) { | |
| // add dummy key to avoid null hash | |
| keys.push_back("###DUMMY_KEY###"); | |
| } | |
| boost::shared_ptr<HashTask<Keys> > | |
| ht(new HashTask<Keys>(current, *this, keys)); | |
| m_threadPool.Submit(ht); | |
| CalcHash(current, keys); | |
| } | |
| template <typename Keys> | |
| void CalcHash(size_t current, Keys &keys) { | |
| void* source = vectorAdapter(keys); | |
| CalcHash(current, source); | |
| } | |
| void CalcHash(size_t current, void* source); | |
| void* vectorAdapter(std::vector<std::string>& v); | |
| void* vectorAdapter(StringVector<unsigned, size_t, std::allocator>& sv); | |
| void* vectorAdapter(StringVector<unsigned, size_t, MmapAllocator>& sv); | |
| }; | |
| } | |