 |
ถามผู้รู้ ช่วยแปลง Pseudocodes นี้และอธิบายให้ ดิฉันเข้าใจหน่อยคะ งง |
|
 |
|
|
 |
 |
|
Code (PHP)
Levenshtein Distance Algorithm
int LevenshteinDistance(char s[1..m], char t[1..n])
{
//for all i and j, d[I,j] will hold the Levenshtein distance between
//the first i characters of s and the first j characters of t;
// note that d has (m+1)x(n+1)values
declare int d[0..m, 0..n]
for i from 0 to m
d[i, 0]:=i//the distance of any first string to an empty second string
for j from 0 to n
d[i, 0]:=j //the distance of any second string to an empty first string
for j from 1 to n
{
for i from 1 to m
{
if s[i]=t[j] then
d[i,j]:=d[i-1,j-1] //no operation required
else
d[i.j]:=minimum
(
d[i-1,j]+1, //a deletion
d[i, j-1,j]+1, //an insertion
d[i-1,j-1]+1, //a substitution
)
}
}
return d[m,n]
}
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2012-01-28 01:12:44 |
By :
ปอปลาตาโต |
View :
1054 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ไม่ง่ายเลยน่ะครับ จะต้องดูผลลัพธ์ ว่ามันได้อะไร 
|
 |
 |
 |
 |
Date :
2012-01-28 07:43:43 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นตาราง matrix เป็น algorithm ที่ใช้การหาค่าความต่างของอักขระสองชุด ต้องไปดูนิยามความสัมพันธ์อ่ะครับ
|
 |
 |
 |
 |
Date :
2012-09-23 23:11:55 |
By :
thanapon26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมช่วยจัดเรียงโค้ดให้ใหม่ จะได้อ่านง่ายๆ
Levenshtein Distance Algorithm
int LevenshteinDistance(char s[1..m], char t[1..n])
{
//for all i and j, d[I,j] will hold the Levenshtein distance between
//the first i characters of s and the first j characters of t;
// note that d has (m+1)x(n+1)values
declare int d[0..m, 0..n]
for i from 0 to m
d[i, 0]:=i //the distance of any first string to an empty second string
for j from 0 to n
d[i, 0]:=j //the distance of any second string to an empty first string
for j from 1 to n
{
for i from 1 to m
{
if s[i]=t[j] then
d[i,j]:=d[i-1,j-1] //no operation required
else
d[i.j]:=minimum
(
d[i-1,j]+1, //a deletion
d[i, j-1,j]+1, //an insertion
d[i-1,j-1]+1, //a substitution
)
}
}
return d[m,n]
}
แต่ไม่ได้อธิบายอะไรน่ะครับ รอท่านอื่นมาตอบ
|
 |
 |
 |
 |
Date :
2012-09-24 14:22:14 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|