/** * 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; }
/** * Returns all located Loomp annotations (ARS_LocatedAnnotation) * for a given ARS_UIMA_Annotation. * * @param ARS_UIMA_Annotation $uimaAnnotation * The UIMA annotation. * @return array The located loomp annotations (ARS_LocatedAnnotation). */ public function getLocatedLoompAnnotationsForARS_UIMA_Annotation($uimaAnnotation) { $loompAnnotations = array(); $begin = $uimaAnnotation->hasAttribute('begin') ? $uimaAnnotation->getAttribute('begin') : null; $end = $uimaAnnotation->hasAttribute('end') ? $uimaAnnotation->getAttribute('end') : null; $namespaceUrl = $uimaAnnotation->getNamespaceUrl($uimaAnnotation->getNamespace()); $full = $namespaceUrl ? $namespaceUrl . '/' : ''; $full .= $uimaAnnotation->getName(); $mappedAttributes = array_key_exists($full, $this->_mappings) ? $this->_mappings[$full] : null; if (!empty($mappedAttributes)) { foreach ($mappedAttributes as $attribute => $uris) { if (empty($attribute) || $uimaAnnotation->hasAttribute($attribute)) { foreach ($uris as $uri) { if (array_key_exists($uri, $this->_annotations)) { $seeAlsoProp = array_key_exists($full, $this->_seeAlso_mappings) ? $this->_seeAlso_mappings[$full] : null; $seeAlso = $seeAlsoProp && $uimaAnnotation->hasAttribute($seeAlsoProp) ? $uimaAnnotation->getAttribute($seeAlsoProp) : null; $loompAnnotations[] = new ARS_LocatedAnnotation($this->_annotations[$uri], $begin, $end, null, $seeAlso); } } } } } return array_values(array_unique($loompAnnotations)); }