00001 00009 #ifndef _CONTEXT_H 00010 #define _CONTEXT_H 00011 00012 #include <vector> 00013 00014 // Some base datatypes. 00015 #include "config.h" 00016 00017 namespace ace { 00018 00021 typedef unsigned int context_frequency_t; 00022 00023 #if defined(_MSC_VER) || defined(__GNUC__) 00024 // Save default pack value. 00025 #pragma pack(push) 00026 // Pack following structure data on 2 bytes data boundary. 00027 #pragma pack(2) 00028 #endif 00029 00036 class PartOfContext { 00039 static const context_frequency_t _max_frequency; 00042 static const context_frequency_t _narrow_flag_bitmask; 00045 context_frequency_t _frequency; // 4 bytes 00048 TaggedLemma _tagged_lemma; // 4 bytes 00049 public: 00056 PartOfContext(string_index_t lemma, tag_index_t tag, bool narrow = false): _frequency(1), _tagged_lemma(lemma, tag) { 00057 if ( narrow ) { 00058 _frequency |= _narrow_flag_bitmask; 00059 } 00060 } 00065 inline bool operator==(const PartOfContext& rhs) const { 00066 return (lemma() == rhs.lemma()) && (tag() == rhs.tag()) 00067 && ( 00068 ((_frequency ^ rhs._frequency) // If MSB is the same, would be zero now... 00069 & _narrow_flag_bitmask) // ...all non MSB bits will now be zero too. 00070 == 0); // So. 00071 } 00074 inline context_frequency_t frequency(void) const { return _frequency & _max_frequency; } 00078 void inc(void); 00081 inline bool is_part_of_narrow(void) const { return (_frequency & _narrow_flag_bitmask) > 0; } 00084 inline bool is_part_of_wide(void) const { return (_frequency & _narrow_flag_bitmask) == 0; } 00087 inline string_index_t lemma(void) const { return _tagged_lemma.lemma(); } 00090 inline tag_index_t tag(void) const { return _tagged_lemma.tag(); } 00091 }; 00092 00093 #if defined(_MSC_VER) || defined(__GNUC__) 00094 // Restore default pack value. 00095 #pragma pack(pop) 00096 #endif 00097 00100 typedef std::vector<PartOfContext> context_t; 00101 00102 } // namespace ace 00103 00104 #endif
1.5.6