Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
6.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: KEYMAK.HXX
  7. //
  8. // Contents: Key Maker
  9. //
  10. // Classes: CKeyMaker
  11. //
  12. // History: 31-Jan-92 BartoszM Created
  13. // 08-June-91 t-WadeR Added CKeyMaker
  14. //
  15. // Notes: The filtering pipeline is hidden in the Data Repository
  16. // object which serves as a sink for the filter.
  17. // The sink for the Data Repository is the Key Repository.
  18. // The language dependent part of the pipeline
  19. // is obtained from the Language List object and is called
  20. // Language Dependent Key Maker. It consists of:
  21. //
  22. // Word Breaker
  23. // Stemmer (optional)
  24. // Normalizer
  25. // Noise List
  26. //
  27. // Each object serves as a sink for its predecessor,
  28. // Key Repository is the final sink.
  29. //
  30. //----------------------------------------------------------------------------
  31. #pragma once
  32. #include <lang.hxx>
  33. #include <enforcer.hxx>
  34. #include <plang.hxx>
  35. class PWordRepository;
  36. //+---------------------------------------------------------------------------
  37. //
  38. // Class: CSafeLanguage
  39. //
  40. // Purpose: Safe class for borrowing and returning language objects
  41. //
  42. // Notes: There are two constructors: one that borrows a language,
  43. // and one that doesn't. The destructor returns a language
  44. // iff it was borrowed in the constructor.
  45. //
  46. // History: 19-Aug-94 SitaramR Created.
  47. //
  48. //----------------------------------------------------------------------------
  49. class CSafeLanguage
  50. {
  51. public:
  52. CSafeLanguage( LCID locale,
  53. PROPID pid,
  54. CLangList * pLangList,
  55. ULONG resources = LANG_LOAD_ALL )
  56. {
  57. Win4Assert( 0 != pLangList );
  58. _pLangList = pLangList;
  59. _pLang = _pLangList->BorrowLang( locale, pid, resources );
  60. }
  61. CSafeLanguage( )
  62. {
  63. _pLang = 0;
  64. _pLangList = 0;
  65. }
  66. ~CSafeLanguage()
  67. {
  68. if ( _pLang )
  69. _pLangList->ReturnLang( _pLang );
  70. }
  71. CLanguage *operator->() { return _pLang; }
  72. BOOL Supports( PROPID pid, LCID lcid )
  73. {
  74. return _pLangList->Supports( _pLang, pid, lcid );
  75. }
  76. private:
  77. CLangList *_pLangList;
  78. CLanguage *_pLang;
  79. };
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Class: CKeyMaker
  83. //
  84. // Purpose: Language dependent key maker object
  85. //
  86. // History: 03-June-91 t-WadeR Created.
  87. // 12-Oct-92 AmyA Added Unicode support
  88. // 18-Nov-92 AmyA Overloaded PutStream
  89. //
  90. //----------------------------------------------------------------------------
  91. class CKeyMaker : public IWordSink
  92. {
  93. public:
  94. //
  95. // From IUnknown
  96. //
  97. virtual SCODE STDMETHODCALLTYPE QueryInterface(REFIID riid, void * * ppvObject);
  98. virtual ULONG STDMETHODCALLTYPE AddRef();
  99. virtual ULONG STDMETHODCALLTYPE Release();
  100. //
  101. // From IWordSink
  102. //
  103. virtual SCODE STDMETHODCALLTYPE PutWord( ULONG cwc,
  104. WCHAR const *pwcInBuf,
  105. ULONG cwcSrcLen,
  106. ULONG cwcSrcPos);
  107. virtual SCODE STDMETHODCALLTYPE PutAltWord( ULONG cwc,
  108. WCHAR const *pwcInBuf,
  109. ULONG cwcSrcLen,
  110. ULONG cwcSrcPos);
  111. virtual SCODE STDMETHODCALLTYPE StartAltPhrase();
  112. virtual SCODE STDMETHODCALLTYPE EndAltPhrase();
  113. virtual SCODE STDMETHODCALLTYPE PutBreak( WORDREP_BREAK_TYPE breakType );
  114. //
  115. // Local
  116. //
  117. CKeyMaker( LCID locale,
  118. PROPID pid,
  119. PKeyRepository& krep,
  120. IPhraseSink *pPhraseSink,
  121. BOOL fQuery,
  122. ULONG fuzzy,
  123. CLangList & langList );
  124. CKeyMaker( IWordBreaker * pWBreak, PNoiseList & Noise );
  125. virtual ~CKeyMaker();
  126. inline void PutStream( OCCURRENCE &occ, TEXT_SOURCE * stm );
  127. void NormalizeWStr( WCHAR const *pwcInBuf, ULONG cwcInBuf,
  128. BYTE *pbOutBuf, unsigned *pcbOutBuf );
  129. BOOL ContainedNoiseWords() { return _xNoiseList->FoundNoise(); }
  130. BOOL Supports( PROPID pid, LCID lcid );
  131. private:
  132. unsigned _cwcMaxNormBuf;
  133. ULONG* _pcwcSrcPos; // Position of word in source chunk
  134. ULONG* _pcwcSrcLen; // Length of word in source chunk
  135. IWordBreaker* _pWBreak;
  136. XPtr<PWordRepository> _xWordRep;
  137. XPtr<PWordRepository> _xWordRep2;
  138. XPtr<PNoiseList> _xNoiseList;
  139. IPhraseSink* _pPhraseSink; // sink for phrases
  140. BOOL _fQuery;
  141. CSafeLanguage _sLang;
  142. LCID _lcid; // Current language
  143. PROPID _pid; // Current pid
  144. CAltWordsEnforcer _altWordsEnforcer; // constraint enforcers for word
  145. CAltPhrasesEnforcer _altPhrasesEnforcer; // sink methods
  146. };
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Member: CKeyMaker::PutStream
  150. //
  151. // Synopsis: Breaks file into normalized keys, and puts them in the
  152. // keyrepository.
  153. //
  154. // Effects: occ is set to the new occurrence
  155. //
  156. // Arguments: [occ] -- occurrence number to start at
  157. // [stm] -- stream to get words from.
  158. //
  159. // History: 05-Jun-91 t-WadeR Created.
  160. // 18-Nov-92 AmyA Overloaded.
  161. // 19-Apr-94 KyleP Sync to spec
  162. //
  163. // Notes: occ gets updated to the current occurrence.
  164. //
  165. //----------------------------------------------------------------------------
  166. inline void CKeyMaker::PutStream( OCCURRENCE &occ, TEXT_SOURCE * stm )
  167. {
  168. _xWordRep->SetOccurrence( occ );
  169. SCODE sc = _pWBreak->BreakText( stm, this, _pPhraseSink );
  170. if ( FAILED( sc ) )
  171. THROW( CException( sc ) );
  172. occ = _xWordRep->GetOccurrence();
  173. };