public function testItWorks()
 {
     $a = @file_get_contents('./tests/mocks/toBeComparedA.txt');
     $b = @file_get_contents('./tests/mocks/toBeComparedB.txt');
     $an = new Normalizer($a);
     $bn = new Normalizer($b);
     $al = $an->getLines();
     $bl = $bn->getLines();
     $at = $an->getTokens();
     $bt = $bn->getTokens();
     $slm = new SequenceMatcher($al, $bl);
 }
Example #2
0
 public function testGroupedNormalize()
 {
     $content = @file_get_contents('./tests/mocks/toBeLineBlocked.txt');
     $normalizer = Normalizer::fromString($content);
     $expected = @file_get_contents('./tests/mocks/alreadyLineBlocked.txt');
     $expected = rtrim($expected);
     $this->assertEquals($expected, $normalizer->getText(true));
 }
Example #3
0
 private function precalculate()
 {
     $an = Normalizer::fromString($this->a);
     $bn = Normalizer::fromString($this->b);
     $al = $an->getLines(true);
     $bl = $bn->getLines(true);
     $slm = new SequenceMatcher($al, $bl, 0.7);
     $lops = $slm->getOpCodes(true);
     $ops = [];
     foreach ($lops as $lop) {
         $atn = Normalizer::fromArray($lop[5]);
         $btn = Normalizer::fromArray($lop[6]);
         $at = $atn->getTokens();
         $bt = $btn->getTokens();
         $swm = new SequenceMatcher($at, $bt, 0.9);
         $wops = $swm->getOpCodes(true);
         $op = $lop;
         $op['wops'] = $wops;
         $ops[] = $op;
     }
     $this->ops = $ops;
     foreach ($this->ops as $o => $lop) {
         foreach ($lop['wops'] as $wop) {
             list($wtag, $as, $al, $bs, $bl, $at, $bt) = $wop;
             switch ($wop[0]) {
                 case 'delete':
                     $this->removals += count($at);
                     break;
                 case 'insert':
                     $this->additions += count($bt);
                     break;
                 case 'replace':
                     $this->removals += count($at);
                     $this->additions += count($bt);
                     break;
             }
         }
     }
 }