::: µ¨ÆÄÀÌ Tip&Trick :::

µ¨ÆÄÀÌ Tip&Trick ¼º°Ý¿¡ ¸ÂÁö ¾Ê´Â ±¤°í,ºñ¹æ,Áú¹®ÀÇ ±ÛÀº Áï½Ã »èÁ¦Çϸç
³»¿ëÀ» º¹»çÇÏ¿© »ç¿ëÇÒ °æ¿ì ¹Ýµå½Ã ÀÌ°÷(http://www.howto.pe.kr)À» Ãâó·Î ¸í½ÃÇÏ¿© ÁÖ¼¼¿ä


Category

  ±è¿µ´ë(2004-09-04 15:03:47, Hit : 5553, Vote : 1227
 http://www.howto.pe.kr
 µÎ ¹®ÀÚ¿­ÀÇ À¯»çµµ °Ë»çÇϱâ

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Math;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Levenshtein matching gives the number of steps (single character replacement or addition)
// needed to transform StringA into String B.
function CompareStrings_Levenshtein(const A, B: String; CaseSensitive: Boolean = False): Integer;
  function Minimum3(x, y, z: Integer): Integer;
  begin
    Result := Min(x, y);
    Result := Min(Result, z);
  end;
  function iff(bool: Boolean; x, y: Integer): Integer;
  begin
    if bool then
      Result := x
    else
      Result := y;
  end;

var
  D: array of array of Integer;
  n, m, i, j, Cost: Integer;
  AI, BJ: char;
  A1, B1: String;
begin
  n := Length(A);
  m := Length(B);
  if (n = 0) then
    Result := m
  else if m = 0 then
    Result := n
  else
  begin
    if CaseSensitive then
      A1 := A
    else
      A1 := UpperCase(A);

    if CaseSensitive then
      B1 := B
    else
      B1 := UpperCase(B);

    Setlength(D, n + 1, m + 1);
    for i := 0 to n do
      D[i, 0] := i;

    for j := 0 to m do
      D[0, j] := j;

    for i := 1 to n do
    begin
      AI := A1[i];

      for j := 1 to m do
      begin
        BJ := B1[j];

        Cost := iff(AI = BJ, 0, 1);
        D[i, j] := Minimum3(D[i - 1][j] + 1,
                            D[i][j - 1] + 1,
                            D[i - 1][j - 1] + Cost);
      end;
    end;
    Result := D[n, m];
  end;
end;

// Ratcliffe matching gives the percentage of possible character matches between StringA and
// StringB, based on the longest matching sequences and subsequences between the two strings
function CompareStrings_Ratcliff(const A, B: String; CaseSensitive: Boolean = False): Double;
var
  A1, B1: String;
  LenA, LenB: Integer;

  function CSR_Sub(StartA, EndA, StartB, EndB: Integer): Integer;
  var
    a, b, i, Matches, NewStartA, NewStartB: Integer;
  begin
    Result := 0;
    NewStartA := 0;
    NewStartB := 0;

    if (StartA > EndA) or (StartB > EndB) or (StartA <= 0) or (StartB <= 0) then
      Exit;

    for a := StartA to EndA do
    begin
      for B := StartB to EndB do
      begin
        Matches := 0;

        i := 0;

        while (a + i <= EndA) and (b + i <= EndB) and (A1[a + i] = B1[b + i]) do
        begin
          Inc(Matches);

          if Matches > Result then
          begin
            NewStartA := a;
            NewStartB := b;
            Result := Matches;
          end;

          Inc(i);
        end;
      end;
    end;

    if Result > 0 then
    begin
      Inc( Result, CSR_Sub(NewStartA + Result, EndA, NewStartB + Result, EndB) );
      Inc( Result, CSR_Sub(StartA, NewStartA - 1, StartB, NewStartB - 1) );
    end;
  end;

begin
  if CaseSensitive then
    A1 := A
  else
    A1 := UpperCase(A);

  if CaseSensitive then
    B1 := B
  else
    B1 := UpperCase(B);

  LenA := Length(A1);
  LenB := Length(B1);

  if A1 = B1 then
    Result := 100
  else if (LenA = 0) or (LenB = 0) then
    Result := 0
  else
    Result := CSR_Sub(1, LenA, 1, LenB) * 200 / (LenA + LenB);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(CompareStrings_Levenshtein(Edit1.Text, Edit2.Text, True))+'°³ÀÇ Æ²¸° ºÎºÐÀÌ ÀÖ½À´Ï´Ù');
  ShowMessage(FloatToStr(CompareStrings_Ratcliff(Edit1.Text, Edit2.Text, True))+'% ÀÏÄ¡ÇÕ´Ï´Ù');
end;

end.





291   [µ¥ÀÌÅͺ£À̽º] µ¥ÀÌÅÍ ¼¼Æ®(data set)ÀÇ DisableControls  ±è¿µ´ë 2003/03/05 5294 1240
290   [À©µµ¿ìÁî API] IEÀÇ ÇöÀç url °¡Á®¿À±â  ±è¿µ´ë 2003/03/07 5062 1239
289   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] StringGrid ¸¦ ÅؽºÆ®ÆÄÀÏ(csv)·Î ÀúÀåÇÏ°í ºÒ·¯¿À±â  ±è¿µ´ë 2004/09/11 5814 1238
288   [½Ã½ºÅÛ] PC¿¡ ¼³Ä¡µÈ µå¶óÀÌºê ¸ñ·Ï ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 5204 1238
287   [½Ã½ºÅÛ] ÇÁ¸°ÅÍÀÇ ´ë±â¹®¼­,µî·ÏÁ¤º¸,Ãß°¡ ¸¶¹ý»ç È£ÃâÇÏ±â  ±è¿µ´ë 2003/03/05 4797 1238
286   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¸ðµç µå¶óÀ̺ê,µð·ºÅ丮 °Ë»öÇÏ¿© ÆÄÀÏ Ã£±â  ±è¿µ´ë 2003/03/07 5109 1237
285   [À©µµ¿ìÁî API] ¾îÇø®ÄÉÀ̼ÇÀÇ Áߺ¹½ÇÇà ¹æÁö  ±è¿µ´ë 2003/03/05 5169 1237
284   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¹®ÀÚ¿­ÀÇ word °¹¼ö ¼¼±â  ±è¿µ´ë 2003/03/04 4633 1237
283   [À©µµ¿ìÁî API] ¹Ù·Î Á÷Àü¿¡ active µÇ¾ú´ø À©µµ¿ì¿Í ÄÜÆ®·Ñ ±¸ÇÏ±â  ±è¿µ´ë 2004/07/24 5051 1236
282   [½Ã½ºÅÛ] À©µµ¿ìÁî Àç½ÃÀÛ  ±è¿µ´ë 2004/08/30 4929 1235
281   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ÄÄÆ÷³ÍÆ®¿¡ µ¿ÀûÀ¸·Î À̺¥Æ® ÇÒ´çÇÏ±â  ±è¿µ´ë 2004/10/08 5518 1234
280   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¸ð¼­¸®°¡ µÕ±Ù(rounded ends) TMemo ¸¸µé±â  ±è¿µ´ë 2004/07/25 4995 1234
279   [³×Æ®¿÷/ÀÎÅͳÝ] ³×Æ®¿öÅ©ÀÇ ÄÄÇ»ÅÍ À̸§,ÀÛ¾÷ ±×·ì,ÄÄÇ»ÅÍ ¼³¸í  ±è¿µ´ë 2003/03/06 5589 1234
278   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] URL encoding ÇÏ±â  ±è¿µ´ë 2003/03/30 4872 1233
277   [½Ã½ºÅÛ] CPU speed ±¸Çϱâ 2  ±è¿µ´ë 2003/03/07 4555 1233
276   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ŸÀÌƲ¹Ù Ŭ¸¯½Ã »ç¿ëÀÚ Æ˾÷¸Þ´º º¸ÀÌ±â  ±è¿µ´ë 2003/03/07 5203 1232
275   [À©µµ¿ìÁî API] "¹®¼­" ¸Þ´º¿¡ ÆÄÀÏÀ» µî·ÏÇÏ°í »èÁ¦ÇÏ±â  ±è¿µ´ë 2003/03/05 4735 1232
274   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] º£Áê(Bezier) °î¼± ±×¸®±â2  ±è¿µ´ë 2003/03/07 6478 1231
273   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TEdit ÀÔ·ÂÀÌ ÃÖ´ë ±æÀ̸¦ ¹ù¾î³ª¸é focus À̵¿  ±è¿µ´ë 2003/03/07 4782 1230
272   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] StringGrid ÀÇ BeginUpdate/EndUpdate ?  ±è¿µ´ë 2003/03/07 6006 1229
271   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ListView ÀÇ Ä÷³º°·Î Sort (³»¸²Â÷¼ø Æ÷ÇÔ)  ±è¿µ´ë 2003/03/05 5908 1229
270   [À©µµ¿ìÁî API] À©µµ¿ìÁîÀÇ ½Ã½ºÅÛ Æú´õµéÀÇ ½ÇÁ¦ µð·ºÅ丮  ±è¿µ´ë 2003/03/05 4653 1229
269   [À©µµ¿ìÁî API] TreeView¿¡ Data »ç¿ë¹ý  ½ÅÈÆÀç 2003/03/10 5348 1228
268   [µ¥ÀÌÅͺ£À̽º] ¸î°¡Áö BDE ȯ°æÁ¤º¸ ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 4744 1228
267   [½Ã½ºÅÛ] HintÀÇ ÆùÆ® ¹Ù²Ù±â  ±è¿µ´ë 2003/03/05 4448 1228
  [¾Ë°í¸®Áò] µÎ ¹®ÀÚ¿­ÀÇ À¯»çµµ °Ë»çÇÏ±â  ±è¿µ´ë 2004/09/04 5553 1227
265   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TPanel ·Î ¸¸µç ÈùÆ®  ±è¿µ´ë 2004/08/05 4884 1227
264   [¾Ë°í¸®Áò] String Hash ÇÔ¼ö  ±è¿µ´ë 2004/09/17 4813 1226
263   [À©µµ¿ìÁî API] µ¥½ºÅ©Å¾ ¾ÆÀÌÄÜ ÀüºÎ °¨Ãß±â/º¸ÀÌ±â  ±è¿µ´ë 2003/03/07 4274 1226
262   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ·¹Áö½ºÆ®¸®ÀÇ "(±âº»°ª)" ¿¡ Àаí/¾²±â  ±è¿µ´ë 2003/03/07 4312 1225
261   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TList ¸¦ ÀÌ¿ëÇÑ stack ±¸Á¶ ±¸Çö  ±è¿µ´ë 2004/07/25 4686 1224
260   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ListBoxÀÇ È­¸é¿¡ º¸¿©Áö´Â ÃÖ»óÀ§ Item ¹øÈ£  ±è¿µ´ë 2003/03/07 4661 1224
259   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¹®ÀÚ¿­ÀÇ ³¡¿¡¼­ºÎÅÍ °Ë»öÇÏ´Â Pos() ÇÔ¼ö  ±è¿µ´ë 2003/03/07 5405 1224
258   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¼öÁ÷ ½ºÅ©·ÑÀÌ ¸Ç¸¶Áö¸·À¸·Î À̵¿Çß´ÂÁö °Ë»ç  ±è¿µ´ë 2003/03/07 4203 1223
257   [½Ã½ºÅÛ] Thread »ç¿ëÇÏ±â  ±è¿µ´ë 2003/03/07 4577 1223
256   [COM/OLE] How to register an OCX  ±è¿µ´ë 2003/03/06 5407 1222
255     [COM/OLE] [re] PDF ActiveX »ç¿ëÇÏ±â  Ãʺ¸µ¨ÇÇ 2005/07/18 5734 1221
254   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TListView Subcolumn Sorting  ±è¿µ´ë 2003/03/06 4867 1221
253   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TStringGrid ÀμâÇÏ±â  ±è¿µ´ë 2003/03/07 5088 1219
252   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] StringGridÀÇ ¸ðµç Cell ¼±ÅÃ/ÇØÁ¦ÇÏ±â  ±è¿µ´ë 2004/09/25 5165 1218

[ÀÌÀü 10°³] [1]..[11][12][13][14][15][16][17] 18 [19][20]..[25] [´ÙÀ½ 10°³]
 

Copyright 1999-2024 Zeroboard / skin by zero