home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Include / OFuzzSearch.hpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  3KB  |  129 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OFuzzSearch.hpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31.  
  32. // $Header:$
  33.  
  34. #ifndef OFUZZSRC_INCLUDED
  35.   #define OFUZZSRC_INCLUDED
  36.  
  37.  
  38. #ifndef OCLOBJECT_INCLUDED
  39.   #include <OCLObject.hpp>
  40. #endif
  41.  
  42. #ifndef OSTRING_INCLUDED
  43.   #include <OString.hpp>
  44. #endif
  45.  
  46. #ifndef OLIST_INCLUDED
  47.   #include <OList.hpp>
  48. #endif
  49.  
  50.  
  51.  
  52. // classes
  53.  
  54.  
  55. typedef class  OFuzzSearch *pOFuzzSearch;
  56. typedef struct OFuzzMatch  *pOFuzzMatch;
  57. typedef class  OList<OFuzzMatch> OFuzzMatchList;
  58.  
  59. struct OFuzzMatch
  60. {
  61.  OString  text;
  62.  float    similarity;
  63. };
  64.  
  65.  
  66. class __CPP_EXPORT__ OFuzzSearch
  67.   : public OCLObject
  68. {
  69.  private:
  70.    OString         file;    // text file to search
  71.    ULONG           parLen;  // max paragraph length to search
  72.    float           threshold;
  73.    OString         searchFor;
  74.  
  75.    class __CPP_EXPORT__ OFuzzMatchPrint
  76.      : public OConstIterator<OFuzzMatch>
  77.      {
  78.       public:
  79.         void applyToElement(const OFuzzMatch* elem) const;
  80.      };
  81.  
  82.    OFuzzMatchPrint  printer;
  83.  
  84.  
  85.  protected:
  86.    
  87.    void
  88.       fuzzyMatching ();
  89.  
  90.    LONG
  91.       prepareString (PSZ  ConvStr,
  92.                      PSZ  OriginStr);
  93.  
  94.    INT
  95.       NGramMatch    (PSZ  TextPara,
  96.                      PSZ  SearchStr,
  97.                      INT  SearchStrLen,
  98.                      INT  NGramLen,
  99.                      INT* MaxMatch);
  100.  
  101.  
  102.  public:
  103.    OFuzzMatchList   matches;
  104.  
  105.  
  106.    OFuzzSearch      (PCSZ  FileName,
  107.                      PCSZ  SearchString,
  108.                      float Threshold = 100.0, // exact match
  109.                      ULONG MaxParLen = 0x0000ffffL); 
  110.  
  111.    virtual
  112.      ~OFuzzSearch   ();
  113.  
  114.   virtual
  115.      PSZ isOfType   () const;
  116.  
  117.    void
  118.       startSearch   ();
  119.  
  120.    void
  121.       printMatches  ();
  122. };
  123.  
  124.  
  125. #endif // OFUZZSRC_INCLUDED
  126.  
  127.  
  128. // end of source
  129.