/**
  * @dataProvider getAutomatons
  */
 public function testVisitAutomaton(array $sequences, array $ranks)
 {
     $visitor = new slAutomatonSupportVisitor();
     $automaton = new slSingleOccurenceAutomaton();
     foreach ($sequences as $sequence) {
         $automaton->learn($sequence);
     }
     $result = $visitor->visit($automaton, array());
     $this->assertEquals($ranks, $result, 'Ranks are not as expected', 0.001);
 }
 /**
  * @dataProvider getAutomatons
  */
 public function testVisitAutomaton(array $sequences, array $labels, $name)
 {
     $visitor = new slAutomatonDotVisitor();
     $automaton = new slSingleOccurenceAutomaton();
     foreach ($sequences as $sequence) {
         $automaton->learn($sequence);
     }
     $result = $visitor->visit($automaton, $labels);
     // Read expectation from file, if available
     if (!is_file($file = __DIR__ . '/data/' . $name . '.dot')) {
         $this->MarkTestSkipped("No comparision file available; Generated result:\n" . $result);
     }
     $this->assertEquals(file_get_contents($file), $result);
 }
Example #3
0
 /**
  * Optional rule
  *
  * Precondition: Every r′ ∈ Pred(r), Succ(r) ⊆ Succ(r′). (Thus:
  * every node that can be reached through r from a predecessor, can
  * also be reached directly from that predecessor.)
  *
  * Action: Relabel r by r?, remove all edges (r′ , r′′) such that 
  * r′ ∈ Pred(r) and r′′ ∈ Succ(r) \ {r}.
  *
  * @param slSingleOccurenceAutomaton $automaton 
  * @return void
  */
 protected function optional(slSingleOccurenceAutomaton $automaton)
 {
     $nodeCount = count($this->nodes);
     $nodeNames = array_keys($this->nodes);
     for ($i = 0; $i < $nodeCount; ++$i) {
         // Precondition
         $outgoing = $automaton->getOutgoing($nodeNames[$i]);
         $incoming = $automaton->getIncoming($nodeNames[$i]);
         if (!count($incoming) || !count($outgoing)) {
             continue;
         }
         foreach ($incoming as $precedessor) {
             if (!$this->superset($automaton->getOutgoing($precedessor), $outgoing)) {
                 continue 2;
             }
         }
         // Action
         $this->nodes[$nodeNames[$i]] = new slRegularExpressionOptional($this->nodes[$nodeNames[$i]]);
         foreach ($incoming as $src) {
             if ($src === $nodeNames[$i]) {
                 continue;
             }
             foreach ($outgoing as $dst) {
                 if ($dst === $nodeNames[$i]) {
                     continue;
                 }
                 $automaton->removeEdge($src, $dst);
             }
         }
         return true;
     }
     return false;
 }
 public function testLearnAll()
 {
     $automaton = new slSingleOccurenceAutomaton();
     $automaton->learn(array('a', 'b', 'c'));
     $automaton->learn(array('a', 'c', 'b'));
     $automaton->learn(array('b', 'a', 'c'));
     $automaton->learn(array('b', 'c', 'a'));
     $automaton->learn(array('c', 'a', 'b'));
     $automaton->learn(array('c', 'b', 'a'));
     $converter = new slSoreConverter();
     $regexp = $converter->convertAutomaton($automaton);
     $this->assertEquals(false, $regexp);
 }