3
J'essaie de créer une classe qui utilise la fonction de distance Levenshtein pour comparer le texte d'un document spécifié parmi tous les autres documents d'un répertoire.Computing Levenshtein Distance
J'ai l'idée de base en tête mais je ne sais pas comment la coder en PHP. Je viens d'un contexte C# donc je vais fournir autant de détails que possible.
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;
}
}
Toute raison pour laquelle vous réimplémentant quelque chose PHP a déjà? [php levenshtein] (http://php.net/manual/fr/function.levenshtein.php) – birryree
Je ne réimplémente pas levenshtein, je l'utilise juste pour comparer le texte brut d'un document entre et la liste d'autres documents dans un répertoire. – user478636
écrire un emballage de session est à mon humble avis le chemin à parcourir. Vous pouvez le faire en créant une classe nommée User. – greg0ire