我正在尝试编写一个类,使用Levenshtein距离函数来比较指定文档中的文本与目录中所有其他文档的文本。
我有基本的思路,但不知道如何在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;
}
}