3
Levenshtein 거리 함수를 사용하여 특정 문서의 텍스트를 디렉토리의 다른 모든 문서와 비교하는 클래스를 만들려고합니다.Levenshtein Distance 거리 계산
나는 염두에두고 기본적인 생각을 가지고 있지만 PHP로 코딩하는 방법을 모르겠습니다. 저는 C# 배경에서 왔으므로 최대한 자세히 설명하겠습니다.
class ComputeLevenshtein
{
public $filePathList = new Array(); //The array that stores the absolute path of all documents within a specified directory
public $directory;
public $filePath; //This is the document that will be compared for each document in a directory
public function __construct() {
$this->directory = //;
/* I'm stuck here, once a user registers, a separate directory is
named after the user. I need to be able to read the username
from the Session Variable once the user logs in.
I'll just have to pass it in as a parameter.
Do I have to create a session wrapper?
If it's too complex,
then I'll just start off with a static directory */
}
// Returns the array containing each filePath for every document in a directory.
function computeFilePathList($directory)
{
for each file in Directory
{
$filepath = file.FilePath(); //store the filepath in a variable
$this->filePathList.add($filePath) //add the filepath to the array
}
}
function ($docFilePath) // returns the Levenshtein Distance
{
for each path in filePathList
{
$input= readDoc($docFilePath);
$lev = levenshtein($input, readDoc($path));
}
return $lev;
}
function readDoc($docFilePath) // Returns the raw text of that doc
{
//I Have the code for reading the doc in a seperate function
return $text;
}
}
당신은 PHP가 이미 무언가를 재 구현하고 어떤 이유 :
그것은 다음과 같은 일을 사용 하는가? [php levenshtein] (http://php.net/manual/en/function.levenshtein.php) – birryree
나는 levenshtein을 다시 구현하지 않고있다. 나는 단지 문서의 원시 텍스트와 다른 목록의 원시 텍스트를 비교하기 위해 사용하고있다. 디렉토리에있는 문서들. – user478636
세션 래퍼 작성 방법은 IMHO입니다. User라는 클래스를 작성하면됩니다. – greg0ire