Browse Source

allow setting levenstein distance for checking drives

tags/0.9.1
itismadness 4 years ago
parent
commit
3b6198375d
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      src/Logchecker.php

+ 7
- 3
src/Logchecker.php View File

@@ -7,6 +7,10 @@ use OrpheusNET\Logchecker\Parser\EAC\Translator;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Exception\ParseException;


if (!defined('LOGCHECKER_LEVENSTEIN_DISTANCE')) {
define('LOGCHECKER_LEVENSTEIN_DISTANCE', 0);
}

/******************************************************************* /*******************************************************************
* Automated EAC/XLD log checker * * Automated EAC/XLD log checker *
********************************************************************/ ********************************************************************/
@@ -1433,16 +1437,16 @@ class Logchecker
$DriveName = preg_replace('/\s+/', ' ', $DriveName); $DriveName = preg_replace('/\s+/', ' ', $DriveName);
$DriveName = preg_replace('/\(revision [a-zA-Z0-9\.\,\-]*\)/', '', $DriveName); $DriveName = preg_replace('/\(revision [a-zA-Z0-9\.\,\-]*\)/', '', $DriveName);
$DriveName = preg_replace('/ Adapter.*$/', '', $DriveName); $DriveName = preg_replace('/ Adapter.*$/', '', $DriveName);
$DriveName = strtolower($DriveName);
$DriveName = trim(strtolower($DriveName));


$MatchedDrives = []; $MatchedDrives = [];
for ($i = 0; $i < 5; $i++) {
for ($i = 0; $i < LOGCHECKER_LEVENSTEIN_DISTANCE + 1; $i++) {
$MatchedDrives[$i] = ['drives' => [], 'offsets' => []]; $MatchedDrives[$i] = ['drives' => [], 'offsets' => []];
} }


foreach ($this->AllDrives as [$Drive, $Offset]) { foreach ($this->AllDrives as [$Drive, $Offset]) {
$Distance = levenshtein($Drive, $DriveName); $Distance = levenshtein($Drive, $DriveName);
if ($Distance < 5) {
if ($Distance < LOGCHECKER_LEVENSTEIN_DISTANCE + 1) {
$MatchedDrives[$Distance]['drives'][] = $Drive; $MatchedDrives[$Distance]['drives'][] = $Drive;
$MatchedDrives[$Distance]['offsets'][] = preg_replace('/[^0-9]/s', '', (string) $Offset); $MatchedDrives[$Distance]['offsets'][] = preg_replace('/[^0-9]/s', '', (string) $Offset);
} }


Loading…
Cancel
Save