/** * Use the namespaces from the RDF / SPARQL source, to shorten the URIs. * @param string $uri * @param array $nsPrefixes * @return string */ function abbreviateParserNSPrefixes($uri, $nsPrefixes) { foreach ($nsPrefixes as $namespace => $prefix) { $nslength = strlen($namespace); $basepart = ''; $localpart = ''; $uriContainsNamepace = substr($uri, 0, $nslength) === $namespace; if ($uriContainsNamepace) { $localpart = substr($uri, $nslength); $basepart = $prefix; break; } } /* * Take care of some special cases: */ if ($basepart === '' && $localpart === '') { $uriParts = $this->splitURI($uri); $basepart = $uriParts[0]; $localpart = $uriParts[1]; } if ($localpart === '') { $abbreviatedUri = $basepart; } elseif (RDFIOUtils::isURI($basepart)) { // FIXME: Shouldn't the above check the local part instead?? // Change ARC:s default "random string", to indicate more clearly that // it lacks title $abbreviatedUri = str_replace('arc', 'untitled', $localpart); } elseif (RDFIOUtils::isURI($basepart)) { // If the abbreviation does not seem to have succeeded, // fall back to use only the local part $abbreviatedUri = $localpart; } elseif (RDFIOUtils::endsWithColon($basepart)) { // Don't add another colon $abbreviatedUri = $basepart . $localpart; } elseif ($basepart == false || $basepart == '') { $abbreviatedUri = $localpart; } else { $abbreviatedUri = $basepart . ':' . $localpart; } return $abbreviatedUri; }