/** Get a list of types for a resource * * The types will each be a shortened URI as a string. * This method will return an empty array if the resource has no types. * * If $resource is null, then it will get the types for the URI of the graph. * * @param string|null $resource * * @return array All types assocated with the resource (e.g. foaf:Person) */ public function types($resource = null) { $resources = $this->typesAsResources($resource); $types = array(); foreach ($resources as $type) { $types[] = RdfNamespace::shorten($type); } return $types; }
/** Get a shortened version of the resources URI. * * This method will return the full URI if the resource isn't part of any * registered namespace. * * @return string The shortened URI of this resource (e.g. foaf:name) */ public function shorten() { return RdfNamespace::shorten($this->uri); }
/** Return pretty-print view of a literal * * This method is mainly intended for internal use and is used by * EasyRdf\Graph and EasyRdf\Sparql\Result to format a literal * for display. * * @param mixed $literal An EasyRdf\Literal object or an associative array * @param string $format Either 'html' or 'text' * @param string $color The colour of the text * * @throws \InvalidArgumentException * @return string */ public static function dumpLiteralValue($literal, $format = 'html', $color = 'black') { if (!preg_match('/^#?[-\\w]+$/', $color)) { throw new \InvalidArgumentException("\$color must be a legal color code or name"); } if (is_object($literal)) { $literal = $literal->toRdfPhp(); } elseif (!is_array($literal)) { $literal = array('value' => $literal); } $text = '"' . $literal['value'] . '"'; if (isset($literal['lang'])) { $text .= '@' . $literal['lang']; } if (isset($literal['datatype'])) { $short = RdfNamespace::shorten($literal['datatype']); if ($short) { $text .= "^^{$short}"; } else { $text .= "^^<" . $literal['datatype'] . ">"; } } if ($format == 'html') { return "<span style='color:{$color}'>" . htmlentities($text, ENT_COMPAT, "UTF-8") . "</span>"; } else { return $text; } }
/** Returns the shortened datatype URI of the literal. * * @return string Datatype of this literal (e.g. xsd:integer). */ public function getDatatype() { if ($this->datatype) { return RdfNamespace::shorten($this->datatype); } else { return null; } }