Example #1
0
 /**
  * Perform all integrity check and comparisons on source and target string
  * 
  */
 public function realignMTSpaces()
 {
     try {
         list($srcNodeList, $trgNodeList) = $this->_prepareDOMStructures();
     } catch (DOMException $ex) {
         return $this->getErrors();
     }
     $this->_checkTagMismatch($srcNodeList, $trgNodeList);
     if ($this->thereAreErrors()) {
         $this->_getTagDiff();
         return;
         //fail
     }
     list($source_seg, $target_seg) = $this->_realignTMSpaces();
     //- re-import in the dom target after regular expression
     //- perform check again ( recursive over the entire class )
     $qaCheck = new self($this->source_seg, $target_seg);
     $qaCheck->performTagCheckOnly();
     if (!$qaCheck->thereAreErrors()) {
         $this->target_seg = $target_seg;
         $this->trgDom = $this->_loadDom($target_seg, self::ERR_TARGET);
         $this->_resetDOMMaps();
         $this->_prepareDOMStructures();
         return;
         //ALL RIGHT
     } else {
         $this->_addError(self::ERR_TAG_MISMATCH);
     }
 }
Example #2
0
 /**
  * Try to perform an heuristic re-align of tags id by position.
  *
  * Two XML strings are analyzed. They must have the same number of tags,
  * the same number of tag G, the same number of tag X.
  *
  * After realignment a Tag consistency check is performed ( QA::performTagCheckOnly() )
  * if no errors where found the dom is reloaded and tags map are updated.
  *
  * @return errObject[]|null
  */
 public function tryRealignTagID()
 {
     try {
         $this->_prepareDOMStructures();
     } catch (DOMException $ex) {
         Log::doLog("tryRealignTagID: " . $ex->getMessage());
         return $this->getErrors();
     }
     $targetNumDiff = count($this->trgDomMap['DOMElement']) - count($this->srcDomMap['DOMElement']);
     $diffTagG = count(@$this->trgDomMap['g']) - count(@$this->srcDomMap['g']);
     $diffTagX = count(@$this->trgDomMap['x']) - count(@$this->srcDomMap['x']);
     $diffTagBX = count(@$this->trgDomMap['bx']) - count(@$this->srcDomMap['bx']);
     $diffTagEX = count(@$this->trgDomMap['ex']) - count(@$this->srcDomMap['ex']);
     //there are the same number of tags in source and target
     if ($targetNumDiff == 0 && !empty($this->srcDomMap['refID'])) {
         //if tags are in exact number
         if ($diffTagG == 0 && $diffTagX == 0 && $diffTagBX == 0 && $diffTagEX == 0) {
             //Steps:
             //- re-align ids
             foreach ($this->trgDomMap['g'] as $pos => $tagID) {
                 $pattern[] = '|<g id ?= ?["\']{1}(' . $tagID . ')["\']{1} ?>|ui';
                 $replacement[] = '<g id="###' . $this->srcDomMap['g'][$pos] . '###">';
             }
             foreach ($this->trgDomMap['x'] as $pos => $tagID) {
                 $pattern[] = '|<x id ?= ?["\']{1}(' . $tagID . ')["\']{1} ?/>|ui';
                 $replacement[] = '<x id="###' . $this->srcDomMap['x'][$pos] . '###" />';
             }
             foreach ($this->trgDomMap['bx'] as $pos => $tagID) {
                 $pattern[] = '|<bx id ?= ?["\']{1}(' . $tagID . ')["\']{1} ?/>|ui';
                 $replacement[] = '<bx id="###' . $this->srcDomMap['bx'][$pos] . '###" />';
             }
             foreach ($this->trgDomMap['ex'] as $pos => $tagID) {
                 $pattern[] = '|<ex id ?= ?["\']{1}(' . $tagID . ')["\']{1} ?/>|ui';
                 $replacement[] = '<ex id="###' . $this->srcDomMap['ex'][$pos] . '###" />';
             }
             $result = preg_replace($pattern, $replacement, $this->target_seg, 1);
             $result = str_replace("###", "", $result);
             //- re-import in the dom target after regular expression
             //- perform check again ( recursive over the entire class )
             $qaCheck = new self($this->source_seg, $result);
             $qaCheck->performTagCheckOnly();
             if (!$qaCheck->thereAreErrors()) {
                 $this->target_seg = $result;
                 $this->trgDom = $this->_loadDom($result, self::ERR_TARGET);
                 $this->_resetDOMMaps();
                 $this->_prepareDOMStructures();
                 return;
                 //ALL RIGHT
             }
             //                Log::doLog($result);
             //                Log::doLog($pattern);
             //                Log::doLog($replacement);
         }
     } else {
         if ($targetNumDiff < 0) {
             // the target has fewer tags than source
         } else {
             // the target has more tags than source
         }
     }
     $this->_addError(self::ERR_COUNT);
 }