53 return is->
read(reinterpret_cast<char *>(&x),
sizeof(T)) ==
sizeof(T);
60 return os->
write(reinterpret_cast<const char *>(&x),
sizeof(T));
67 template<
class T>
class Item {
72 return loadItem<T>(is,x);
78 return saveItem<T>(os,x);
90 if (!loadItem<Size>(is,saved_size))
return false;
95 x =
reinterpret_cast<T*
>(malloc(saved_size*
sizeof(T)));
104 if (is->
read(reinterpret_cast<char *>(x), wanted) != wanted)
return false;
117 if (!saveItem<Size>(os,tmp))
return false;
120 return os->
write(reinterpret_cast<const char *>(x), n*
sizeof(T));
124 #ifdef MOOT_32BIT_FORCE 132 template<>
class Item<size_t> {
138 if (
sizeof(
size_t)==
sizeof(
Size)) {
140 return loadItem<size_t>(is,x);
143 bool rc = loadItem<Size>(is,tmp);
150 if (
sizeof(
size_t)==
sizeof(
Size)) {
152 return saveItem<size_t>(os,x);
155 return saveItem<Size>(os, tmp);
168 template<>
class Item<char *> {
176 return charItem.
load_n(is,x,len);
182 size_t len = strlen(x)+1;
183 return charItem.
save_n(os,x,len);
185 return charItem.
save_n(os,
"",1);
197 template<>
class Item<string> {
205 bool rc = charItem.
load_n(is,buf,len);
206 if (rc && len) x.assign(buf,len);
213 return charItem.
save_n(os,x.data(),x.size());
221 template<
class ValT>
class Item<vector<ValT> > {
230 if (!size_item.
load(is, len))
return false;
237 for ( ; len > 0; len--) {
239 if (!val_item.
load(is,x.back()))
return false;
248 if (!size_item.
save(os, x.size()))
return false;
251 for (
typename vector<ValT>::const_iterator xi = x.begin(); xi != x.end(); xi++) {
252 if (!val_item.
save(os,*xi))
return false;
263 template<
class ValT>
class Item<set<ValT> > {
272 if (!size_item.
load(is, len))
return false;
279 for ( ; len > 0; len--) {
280 if (!val_item.
load(is,tmp))
291 if (!size_item.
save(os, x.size()))
return false;
294 for (
typename set<ValT>::const_iterator xi = x.begin(); xi != x.end(); xi++) {
295 if (!val_item.
save(os,*xi))
return false;
305 template<
class ValT>
class Item<hash_set<ValT> > {
314 if (!size_item.
load(is, len))
return false;
322 for ( ; len > 0; len--) {
323 if (!val_item.
load(is,tmp))
return false;
333 if (!size_item.
save(os, x.size()))
return false;
336 for (
typename hash_set<ValT>::const_iterator xi = x.begin(); xi != x.end(); xi++) {
337 if (!val_item.
save(os,*xi))
return false;
348 template<
class KeyT,
class ValT>
class Item<map<KeyT,ValT> > {
358 if (!size_item.
load(is, len))
return false;
366 for ( ; len > 0; len--) {
367 if (!key_item.
load(is,key_tmp) || !val_item.
load(is,val_tmp))
369 x[key_tmp] = val_tmp;
378 if (!size_item.
save(os, x.size()))
return false;
381 for (
typename map<KeyT,ValT>::const_iterator xi = x.begin(); xi != x.end(); xi++) {
382 if (!key_item.
save(os,xi->first) || !val_item.
save(os,xi->second))
394 template<
class KeyT,
class ValT,
class HashFuncT,
class EqualFuncT>
395 class Item<hash_map<KeyT,ValT,HashFuncT,EqualFuncT> > {
405 if (!size_item.
load(is, len))
return false;
414 for ( ; len > 0; len--) {
415 if (!key_item.
load(is,key_tmp) || !val_item.
load(is,val_tmp))
417 x[key_tmp] = val_tmp;
422 inline bool save(
mootio::mostream *os,
const hash_map<KeyT,ValT,HashFuncT,EqualFuncT> &x)
const 426 if (!size_item.
save(os, x.size()))
return false;
429 for (
typename hash_map<KeyT,ValT,HashFuncT,EqualFuncT>::const_iterator xi = x.begin();
433 if (!key_item.
save(os,xi->first) || !val_item.
save(os,xi->second))
444 template<
class T1,
class T2>
445 class Item<std::pair<T1,T2> > {
452 return (item1.
load(is,x.first) && !item2.
load(is,x.second));
457 return (item1.
save(os,x.first) && item2.
save(os,x.second));
487 template<
class NameT,
class HashFunc,
class NameEqlFunc>
516 template<
typename KeyT,
typename ValT>
524 {
return vec_item.
load(is,x); };
526 {
return vec_item.
save(os,x); };
532 template <
typename DataT,
typename CharT,
typename UCharT>
575 && vec_item.
load(is,x));
581 && vec_item.
save(os, x));
598 if (!(string_item.
load(is,x.
lab)
600 && uint_item.
load(is,x.
id)))
609 && uint_item.
save(os,x.
id));
UCharT ndtrs
number of daughters
Definition: mootTrieVector.h:66
bool load(mootio::mistream *is, string &x) const
Definition: mootBinIO.h:201
Definition: mootAssocVector.h:39
DataT data
data associated with this node
Definition: mootTrieVector.h:67
1st-order Hidden Markov Model Tagger/Disambiguator class.
Definition: mootHMM.h:120
High-level heuristic token classifier .
Definition: mootFlavor.h:62
CharT label
label of arc to this node
Definition: mootTrieVector.h:65
Hidden Markov Model tagger/disambiguator.
Top-level class for suffix tries.
Definition: mootSuffixTrie.h:46
virtual bool write(const char *buf, size_t n)
Definition: mootIO.h:218
Name2IdMap names2ids
maps names to IDs
Definition: mootEnum.h:78
Binary item I/O template class, used for binary HMM model files.
Definition: mootBinIO.h:67
bool load(mootio::mistream *is, char *&x) const
Definition: mootBinIO.h:173
Namespace for structured binary stream I/O.
Definition: mootBinHeader.h:37
ProbT theta
standard deviation of unigram MLEs
Definition: mootSuffixTrie.h:71
TagID tag1
previous-previous tag_{i-2} or 0
Definition: mootHMM.h:243
Binary I/O template instantiation for signed integers.
Definition: mootBinIO.h:132
bool load(mootio::mistream *is, T &x) const
Definition: mootBinIO.h:70
bool load_n(mootio::mistream *is, T *&x, size_t &n) const
Definition: mootBinIO.h:87
Abstract base class for output stream wrappers.
Definition: mootIO.h:194
bool save(mootio::mostream *os, const T &x) const
Definition: mootBinIO.h:76
LISP-style assoc list using vector<>: map-like class with small memory footprint. Useful for small as...
Definition: mootAssocVector.h:130
Definition: mootEnum.h:67
Definition: mootTrieVector.h:58
void clear(void)
Definition: mootTrieVector.h:205
Tag-trigram key type for HMM probability lookup table (only used if hash_ngrams is true) ...
Definition: mootHMM.h:241
CountT maxcount
raw frequency upper bound
Definition: mootSuffixTrie.h:70
TagID tag3
current tag: tag_i
Definition: mootHMM.h:245
AssocVector< KeyT, ValT >::assoc_vector_type assoc_vector_type
Definition: mootBinIO.h:522
bool save_n(mootio::mostream *os, const T *x, size_t n) const
Definition: mootBinIO.h:114
mootFlavorID noid
id to return if no rule matches (default: empty)
Definition: mootFlavor.h:145
bool saveItem(mootio::mostream *os, const T &x)
Definition: mootBinIO.h:58
Item< char > charItem
Definition: mootBinIO.h:170
bool save(mootio::mostream *os, const char *x) const
Definition: mootBinIO.h:179
Rules rules
matching heuristics in order of decreasing priority
Definition: mootFlavor.h:143
type for a single regex-based token classification heuristic
Definition: mootFlavor.h:74
Item< char > charItem
Definition: mootBinIO.h:199
Namespace for I/O stream wrappers.
Definition: mootBufferIO.h:45
mootFlavorID id
numeric id (zero by default)
Definition: mootFlavor.h:79
std::vector< assoc_node_type > assoc_vector_type
Definition: mootAssocVector.h:138
virtual ByteCount read(char *buf, size_t n)
Definition: mootIO.h:156
string re_s
POSIX.2 regex to match ("extended" regex string; see regex(7) manpage)
Definition: mootFlavor.h:80
Binary I/O template instantiation for STL strings.
Definition: mootBinIO.h:197
bool save(mootio::mostream *os, const size_t &x) const
Definition: mootBinIO.h:148
bool loadItem(mootio::mistream *is, T &x)
Definition: mootBinIO.h:51
bool save(mootio::mostream *os, const string &x) const
Definition: mootBinIO.h:213
mootFlavorStr lab
symbolic label
Definition: mootFlavor.h:78
int ByteCount
typedef for byte counts (should be signed, for compatibility)
Definition: mootIO.h:52
BinUInt Size
Definition: mootTypes.h:89
size_t mindtr
index of first arc from this node
Definition: mootTrieVector.h:47
TagID tag2
previous tag: tag_{i-1} or 0
Definition: mootHMM.h:244
size_t mother
index of this node's mother
Definition: mootTrieVector.h:46
mootFlavorStr nolabel
label to return if no rule matches (default: empty)
Definition: mootFlavor.h:144
Id2NameMap ids2names
maps IDs to names
Definition: mootEnum.h:79
Abstract base class for input stream wrappers.
Definition: mootIO.h:129
bool load(mootio::mistream *is, size_t &x) const
Definition: mootBinIO.h:136