Exemple #1
0
 /**
  * Analyzes the $data and creates all annotations that was found.
  * 
  * @param   string  $data
  * 		The XML result document from the service.
  * @return  ARS_Service_Result
  */
 private function _analyze($data)
 {
     $namespaces = $this->_extractNamespaces($data);
     $members = $this->_getAllMembers($data);
     $annotations = array();
     preg_match_all('#<(\\S+):(\\S+)\\s+[^>]*/>#', $data, $matches);
     for ($i = 0; $i < count($matches[0]); $i++) {
         $annotation = new ARS_UIMA_Annotation($matches[2][$i], $matches[1][$i], $namespaces[$matches[1][$i]]);
         // check, if it is an annotation / member
         if (preg_match('#xmi:id="(\\d+)"#', $matches[0][$i], $idMatch) && in_array($idMatch[1], $members)) {
             // get all attributes
             preg_match_all('#\\s+(\\S+)="([^"]*)"#', $matches[0][$i], $attrs_matches);
             for ($k = 0; $k < count($attrs_matches[0]); $k++) {
                 $splitted = split(':', $attrs_matches[1][$k]);
                 $name = 1 == count($splitted) ? $splitted[0] : $splitted[1];
                 $value = $attrs_matches[2][$k];
                 $namespace = 1 == count($splitted) ? null : $splitted[0];
                 $namespaceUrl = null == $namespace ? null : $namespaces[$namespace];
                 $annotation->addAttribute($name, $value, $namespace, $namespaceUrl);
             }
             $annotations[(int) $idMatch[1]] = $annotation;
         }
     }
     // sort annotations by id (lower id => higher priority)
     ksort($annotations);
     $this->_annotations = array_values($annotations);
     return $this;
 }