示例#1
0
 /**
  * Prints a query result as HTML table.
  * You can change the colors in the configuration file.
  *
  * @param array $queryResult [][?VARNAME] = object Node
  * @access private
  */
 function writeQueryResultAsHtmlTable($queryResult)
 {
     // Import Package Utility
     include_once RDFAPI_INCLUDE_DIR . PACKAGE_UTILITY;
     if (current($queryResult[0]) == NULL) {
         echo 'no match<br>';
         return;
     }
     echo '<table border="1" cellpadding="3" cellspacing="0"><tr><td><b>No.</b></td>';
     foreach ($queryResult[0] as $varName => $value) {
         echo "<td align='center'><b>{$varName}</b></td>";
     }
     echo '</tr>';
     foreach ($queryResult as $n => $var) {
         echo '<tr><td width="20" align="right">' . ($n + 1) . '.</td>';
         foreach ($var as $varName => $value) {
             echo INDENTATION . INDENTATION . '<td bgcolor="';
             echo RDFUtil::chooseColor($value);
             echo '">';
             echo '<p>';
             $lang = NULL;
             $dtype = NULL;
             if (is_a($value, 'Literal')) {
                 if ($value->getLanguage() != NULL) {
                     $lang = ' <b>(xml:lang="' . $value->getLanguage() . '") </b> ';
                 }
                 if ($value->getDatatype() != NULL) {
                     $dtype = ' <b>(rdf:datatype="' . $value->getDatatype() . '") </b> ';
                 }
             }
             echo RDFUtil::getNodeTypeName($value) . $value->getLabel() . $lang . $dtype . '</p>';
         }
         echo '</tr>';
     }
     echo '</table>';
 }
示例#2
0
 /**
  * Prints a MemModel as HTML table.
  * You can change the colors in the configuration file.
  *
  * @param	object MemModel 	&$model
  * @access	public
  */
 function writeHTMLTable(&$model)
 {
     $nms = $model->getParsedNamespaces();
     $names = '';
     $pre = '';
     echo '<table border="1" cellpadding="3" cellspacing="0" width="100%">' . LINEFEED;
     echo INDENTATION . '<tr bgcolor="' . HTML_TABLE_HEADER_COLOR . '">' . LINEFEED . INDENTATION . INDENTATION . '<td td width="68%" colspan="3">';
     echo '<p><b>Base URI:</b> ' . $model->getBaseURI() . '</p></td>' . LINEFEED;
     echo INDENTATION . INDENTATION . '<td width="32%"><p><b>Size:</b> ' . $model->size() . '</p></td>' . LINEFEED . INDENTATION . '</tr>';
     echo '<tr><td><b>Prefix:</b>' . '<br/></td><td colspan="3"><b>Namespace:</b>' . '<br/></td></tr>';
     $i = 0;
     if ($nms != false) {
         foreach ($nms as $namespace => $prefix) {
             if ($i == 0) {
                 $col = HTML_TABLE_NS_ROW_COLOR0;
             } else {
                 $col = HTML_TABLE_NS_ROW_COLOR1;
             }
             echo '<tr bgcolor="' . $col . '"><td>' . $prefix . '</td><td colspan="3">' . $namespace . '</td></tr>';
             $i++;
             $i %= 2;
         }
     } else {
         echo '<tr><td>-</td><td colspan="3">-</td></tr>';
     }
     echo INDENTATION . '<tr bgcolor="' . HTML_TABLE_HEADER_COLOR . '">' . LINEFEED . INDENTATION . INDENTATION . '<td width="4%"><p align=center><b>No.</b></p></td>' . LINEFEED . INDENTATION . INDENTATION . '<td width="32%"><p><b>Subject</b></p></td>' . LINEFEED . INDENTATION . INDENTATION . '<td width="32%"><p><b>Predicate</b></p></td>' . LINEFEED . INDENTATION . INDENTATION . '<td width="32%"><p><b>Object</b></p></td>' . LINEFEED . INDENTATION . '</tr>' . LINEFEED;
     $i = 1;
     foreach ($model->triples as $key => $statement) {
         $infered = '';
         if (is_a($statement, 'InfStatement')) {
             $infered = '<small>(infered)</small>';
         }
         echo INDENTATION . '<tr valign="top">' . LINEFEED . INDENTATION . INDENTATION . '<td><p align=center>' . $i . '.<BR>' . $infered . '</p></td>' . LINEFEED;
         // subject
         echo INDENTATION . INDENTATION . '<td bgcolor="';
         echo RDFUtil::chooseColor($statement->getSubject());
         echo '">';
         echo '<p>' . RDFUtil::getNodeTypeName($statement->getSubject());
         if (is_a($statement->subj, 'Resource')) {
             $ns = $statement->subj->getNamespace();
             if (isset($nms[$ns])) {
                 echo $nms[$ns] . ':' . RDFUtil::getLocalName($statement->subj);
             } else {
                 echo $statement->subj->getLabel();
             }
         }
         echo '</p></td>' . LINEFEED;
         // predicate
         echo INDENTATION . INDENTATION . '<td bgcolor="';
         echo RDFUtil::chooseColor($statement->getPredicate());
         echo '">';
         echo '<p>' . RDFUtil::getNodeTypeName($statement->getPredicate());
         if (is_a($statement->pred, 'Resource')) {
             $ns = $statement->pred->getNamespace();
             if (isset($nms[$ns])) {
                 echo $nms[$ns] . ':' . RDFUtil::getLocalName($statement->pred);
             } else {
                 echo $statement->pred->getLabel();
             }
         }
         echo '</p></td>' . LINEFEED;
         // object
         echo INDENTATION . INDENTATION . '<td bgcolor="';
         echo RDFUtil::chooseColor($statement->getObject());
         echo '">';
         echo '<p>';
         if (is_a($statement->getObject(), 'Literal')) {
             if ($statement->obj->getLanguage() != null) {
                 $lang = ' <b>(xml:lang="' . $statement->obj->getLanguage() . '") </b> ';
             } else {
                 $lang = '';
             }
             if ($statement->obj->getDatatype() != null) {
                 $dtype = ' <b>(rdf:datatype="' . $statement->obj->getDatatype() . '") </b> ';
             } else {
                 $dtype = '';
             }
         } else {
             $lang = '';
             $dtype = '';
         }
         $label = $statement->obj->getLabel();
         if (is_a($statement->obj, 'Resource')) {
             $ns = $statement->obj->getNamespace();
             if (isset($nms[$ns])) {
                 $label = $nms[$ns] . ':' . RDFUtil::getLocalName($statement->obj);
             } else {
                 $label = $statement->obj->getLabel();
             }
         }
         echo RDFUtil::getNodeTypeName($statement->getObject()) . nl2br(htmlspecialchars($label)) . $lang . $dtype;
         echo '</p></td>' . LINEFEED;
         echo INDENTATION . '</tr>' . LINEFEED;
         $i++;
     }
     echo '</table>' . LINEFEED;
 }