Source for file RdfUtil.php
Documentation is available at RdfUtil.php
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
* Useful utility methods.
* @version $Id: fsource_utility__utilRdfUtil.php.html 443 2007-06-01 16:25:38Z cax $
* @author Chris Bizer <chris@bizer.de>, Daniel Westphal <dawe@gmx.de>
* @author Anton Köstlbacher <anton1@koestlbacher.de>
* Extracts the namespace prefix out of a URI.
$l =
RDFUtil::getNamespaceEnd($uri);
return $l >
1 ?
substr($uri ,0, $l) :
"";
* Delivers the name out of the URI (without the namespace prefix).
* Extracts the namespace prefix out of the URI of a Resource.
* @param Object Resource $resource
* Delivers the Localname (without the namespace prefix) out of the URI of a Resource.
* @param Object Resource $resource
* Position of the namespace end
* Method looks for # : and /
function getNamespaceEnd($uri) {
if($c ==
'#' ||
$c ==
':' ||
$c ==
'/')
* Short Prefix for known Namespaces by given URI
$short_p =
$statement->getLabelPredicate();
* Tests if the URI of a resource belongs to the RDF syntax/model namespace.
* @param Object Resource $resource
function isRDF($resource) {
* @param String $textValue
* Converts an ordinal RDF resource to an integer.
* e.g. Resource(RDF:_1) => 1
* @param object Resource $resource
if($resource ==
NULL ||
!is_a($resource, 'Resource') ||
!RDFUtil::isRDF($resource))
//noch rein : chekcen ob $n Nummer ist !!!!!!!!!!!!!!!!!!!!!!if($n)
* Creates ordinal RDF resource out of an integer.
* @return object Resource
* Prints a MemModel as HTML table.
* You can change the colors in the configuration file.
* @param object MemModel &$model
$nms =
$model->getParsedNamespaces();
echo
'<table border="1" cellpadding="3" cellspacing="0" width="100%">' .
LINEFEED;
echo
'<p><b>Base URI:</b> ' .
$model->getBaseURI() .
'</p></td>' .
LINEFEED;
echo
'<tr><td><b>Prefix:</b>'.
'<br/></td><td colspan="3"><b>Namespace:</b>'.
'<br/></td></tr>';
foreach($nms as $namespace =>
$prefix){
echo
'<tr bgcolor="'.
$col.
'"><td>'.
$prefix.
'</td><td colspan="3">'.
$namespace.
'</td></tr>';
echo
'<tr><td>-</td><td colspan="3">-</td></tr>';
foreach($model->triples as $key =>
$statement) {
if (is_a($statement,'InfStatement')) $infered=
'<small>(infered)</small>';
echo
RDFUtil::chooseColor($statement->getSubject());
echo
'<p>' .
RDFUtil::getNodeTypeName($statement->getSubject());
if(is_a($statement->subj,'Resource')){
$ns =
$statement->subj->getNamespace();
echo
$statement->subj->getLabel();
echo
RDFUtil::chooseColor($statement->getPredicate());
echo
'<p>' .
RDFUtil::getNodeTypeName($statement->getPredicate());
if(is_a($statement->pred,'Resource')){
$ns =
$statement->pred->getNamespace();
echo
$statement->pred->getLabel();
echo
RDFUtil::chooseColor($statement->getObject());
if (is_a($statement->getObject(), 'Literal')) {
if ($statement->obj->getLanguage() !=
null) {
$lang =
' <b>(xml:lang="' .
$statement->obj->getLanguage() .
'") </b> ';
if ($statement->obj->getDatatype() !=
null) {
$dtype =
' <b>(rdf:datatype="' .
$statement->obj->getDatatype() .
'") </b> ';
$label =
$statement->obj->getLabel();
if(is_a($statement->obj,'Resource')){
$ns =
$statement->obj->getNamespace();
$label =
$statement->obj->getLabel();
echo
RDFUtil::getNodeTypeName($statement->getObject())
* Used by RDFUtil::writeHTMLTable()
* @param object Node $node
* @return object Resource
function chooseColor($node) {
if (is_a($node, 'BlankNode'))
elseif (is_a($node, 'Literal'))
* Used by RDFUtil::writeHTMLTable()
* @param object Node $node
* @return object Resource
function getNodeTypeName($node) {
if (is_a($node, "BlankNode"))
elseif (is_a($node, 'Literal'))
* Short Prefix for known and/or parsed Namespaces by given URI and Model
* Uses $default_prefixes defined in constants.php and getParsedNamespaces()
* Returns FALSE if no matching prefix is found
* @author Anton Köstlbacher <anton1@koestlbacher.de>
* @return string, boolean
global $default_prefixes;
$par_nms =
$model->getParsedNamespaces();
if (isset
($par_nms[$namespace]))
$prefix =
$par_nms[$namespace];
* Generates a dot-file for drawing graphical output with the
* graphviz-application which can be downloaded at http://www.graphviz.org
* If the graphviz-application is installed and its path is set to the
* correct value in constants.php we can directly generate any
* file format graphviz supports, e.g. SVG, PNG
* Parameters: model to visualize, output format, use prefixes
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* WARNING: Graphviz can be slow with large models.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* @author Anton Köstlbacher <anton1@koestlbacher.de>
* @param boolean $short_prefix
function visualizeGraph(&$model, $format =
"input_dot", $short_prefix =
TRUE)
foreach ($model->triples as $key =>
$statement)
$subject =
$statement->getLabelSubject();
$predicate =
$statement->getLabelPredicate();
$object =
$statement->getLabelObject();
if (!isset
($attrib[$subject]))
if (is_a($statement->subject(),'BlankNode'))
$attrib[$subject] =
$graphviz_param['BLANKNODE_STYLE'];
$attrib[$subject] =
"label=\"".
$subject_label.
"\" ";
if(!isset
($prefix_array[$prefix]))
$attrib[$subject] .=
"URL=\"".
$subject.
"\"";
if(!isset
($prefix_array[$prefix]))
$predicate_label =
"label=\"".
$predicate.
"\"";
if (is_a($statement,'InfStatement'))
$predicate_label .=
" ".
$graphviz_param['INFERRED_STYLE'];
$predicate_label .=
"URL=\"".
$predicate.
"\"";
if (!isset
($attrib[$object]))
if (is_a($statement->object(),'BlankNode'))
$attrib[$object] =
$graphviz_param['BLANKNODE_STYLE'];
elseif (is_a($statement->object(),'Literal'))
$attrib[$object] =
"label=\"$object_label\" ".
$graphviz_param['LITERAL_STYLE'];
$attrib[$object] =
"label=\"".
$object_label.
"\" ";
if(!isset
($prefix_array[$prefix]))
$attrib[$object] .=
"URL=\"".
$object.
"\"";
$graph[] =
"\"".
$subject.
"\" -> \"".
$object.
"\" [".
$predicate_label.
"];";
$dot =
"digraph G { ".
$graphviz_param['GRAPH_STYLE'].
"\n edge [".
$graphviz_param['PREDICATE_STYLE'].
"]\n node [".
$graphviz_param['RESOURCE_STYLE'].
"]\n";
foreach ($attrib AS $key =>
$value)
$dot .=
"\"$key\" [$value];\n";
$dot .=
"error [shape=box,label=\"No Statements found!\"]";
$stat_label =
"| ".
$model->size().
" Statements drawn";
if ((strstr($graphviz_param['GRAPH_STYLE'], 'rankdir="LR"') ===
FALSE) &&
(strstr($graphviz_param['GRAPH_STYLE'], 'rankdir=LR') ===
FALSE))
if ($short_prefix ==
TRUE && isset
($prefix_array))
$struct_label =
"{ { Base URI: ".
$model->getBaseURI().
" $sep1 | { { ".
implode("|", array_keys($prefix_array)).
" } | { ".
implode("|", $prefix_array).
" } } $stat_label } $sep2";
$struct_label =
"{ { Base URI: ".
$model->getBaseURI().
"$sep1 ".
$stat_label.
" } }";
$dot .=
"\n struct [shape=Mrecord,label=\"$struct_label\",".
$graphviz_param['BOX_STYLE'].
"];\n";
$dot .=
" vocabulary [style=invis];\n struct -> vocabulary [style=invis];\n}";
// if needed call dot.exe
$file_handle =
@fopen($filename, 'w');
$dotinput =
" -T".
$format.
" ".
$filename;
elseif ($format ==
"input_dot")
Documentation generated on Fri, 1 Jun 2007 16:50:57 +0200 by phpDocumentor 1.3.2