/** * Get the Turtle serialization string for the given SMWExpElement. The * method just computes a name, and does not serialize triples, so the * parameter must be an SMWExpResource or SMWExpLiteral, no SMWExpData. * * @param $expElement SMWExpElement being SMWExpLiteral or SMWExpResource * @return string */ public static function getTurtleNameForExpElement(SMWExpElement $expElement) { if ($expElement instanceof SMWExpResource) { if ($expElement->isBlankNode()) { return '[]'; } elseif ($expElement instanceof SMWExpNsResource && $expElement->hasAllowedLocalName()) { return $expElement->getQName(); } else { return '<' . str_replace('>', '\\>', SMWExporter::getInstance()->expandURI($expElement->getUri())) . '>'; } } elseif ($expElement instanceof SMWExpLiteral) { $dataType = $expElement->getDatatype(); $lexicalForm = self::getCorrectLexicalForm($expElement); if ($dataType !== '' && $dataType != 'http://www.w3.org/2001/XMLSchema#string') { $count = 0; $newdt = str_replace('http://www.w3.org/2001/XMLSchema#', 'xsd:', $dataType, $count); return $count == 1 ? "{$lexicalForm}^^{$newdt}" : "{$lexicalForm}^^<{$dataType}>"; } else { return $lexicalForm; } } else { throw new InvalidArgumentException('The method can only serialize atomic elements of type SMWExpResource or SMWExpLiteral.'); } }