Exemple #1
0
 /**
  * Build regular expression
  *
  * Builds the regilar expression from the provided automaton, where each 
  * node associates with one of the equivalency classes, and a topologically 
  * sorted list of these nodes.
  *
  * The provided automaton must be an instance of the 
  * slCountingSingleOccurenceAutomaton, so t at it provides information on 
  * how often the token occur in the learned strings.
  * 
  * @param slCountingSingleOccurenceAutomaton $automaton 
  * @param array $classes 
  * @return slRegularExpression
  */
 protected function buildRegularExpression(slCountingSingleOccurenceAutomaton $automaton, array $classes)
 {
     // xsd:all may only occur outmost and makes only sense for equivalence
     // classes with more then one elment.
     if (count($classes) === 1) {
         $class = reset($classes);
         $term = $eClasses = $this->equivalenceClasses[$class];
         $count = $automaton->getOccurenceSum($eClasses);
         $nodes = $automaton->getNodes();
         $generalCount = $automaton->getGeneralOccurences($eClasses);
         if (count($term) > 1 && $generalCount['max'] === 1 && $count['max'] > 1) {
             // Inference all
             $term = new slRegularExpressionAll(array_map(function ($term) use($nodes) {
                 return new slRegularExpressionElement($nodes[$term]);
             }, $term));
             $term->minOccurences = $generalCount['min'];
             return $term;
         }
     }
     return parent::buildRegularExpression($automaton, $classes);
 }
Exemple #2
0
 /**
  * Build regular expression
  *
  * Builds the regilar expression from the provided automaton, where each 
  * node associates with one of the equivalency classes, and a topologically 
  * sorted list of these nodes.
  *
  * The provided automaton must be an instance of the 
  * slCountingSingleOccurenceAutomaton, so t at it provides information on 
  * how often the token occur in the learned strings.
  * 
  * @param slCountingSingleOccurenceAutomaton $automaton 
  * @param array $classes 
  * @return slRegularExpression
  */
 protected function buildRegularExpression(slCountingSingleOccurenceAutomaton $automaton, array $classes)
 {
     $terms = array();
     $nodes = $automaton->getNodes();
     foreach ($classes as $class) {
         $term = $classes = $this->equivalenceClasses[$class];
         if (count($term) > 1) {
             $term = new slRegularExpressionChoice(array_map(function ($term) use($nodes) {
                 return new slRegularExpressionElement($nodes[$term]);
             }, $term));
         } else {
             $term = new slRegularExpressionElement($nodes[reset($term)]);
         }
         $terms[] = $this->wrapCountingPattern($automaton->getOccurenceSum($classes), $term);
     }
     return new slRegularExpressionSequence($terms);
 }