RDF
[ class tree: RDF ] [ index: RDF ] [ all elements ]

Source for file RDF.php

Documentation is available at RDF.php

  1. <?php 
  2.  
  3. /**
  4.  * Include PEAR base class
  5.  */
  6. require_once 'PEAR.php';
  7.  
  8. // ----------------------------------------------------------------------------------
  9. // Constants
  10. // ----------------------------------------------------------------------------------
  11. // Version                   : 0.7
  12. // Authors                   : Chris Bizer (chris@bizer.de),
  13. // Daniel Westphal (dawe@gmx.de),
  14. // Leandro Mariano Lopez (llopez@xinergiaargentina.com),
  15. // Radoslaw Oldakowski (radol@gmx.de)
  16.  
  17. // Description               : Constants and default configuration
  18. // ----------------------------------------------------------------------------------
  19. // General
  20. // ----------------------------------------------------------------------------------
  21. define('RDF_DEFAULT_ALGORITHM',     'MD5');
  22. define('RDF_DEFAULT_ENCODING',      'UTF-8');
  23. define('RDF_INDENTATION',           '    ');
  24. define('RDF_LINEFEED',              chr(10));
  25. // ----------------------------------------------------------------------------------
  26. // Error Messages
  27. // ----------------------------------------------------------------------------------
  28. define('RDF_ERROR',                 -1);
  29. define('RDF_ERROR_NOT_SUPPORTED',   -2);
  30. define('RDF_ERROR_CONFIG_ERROR',    -3);
  31. define('RDF_ERROR_MISSING_DEPS',    -4);
  32. define('RDF_ERROR_UNEXPECTED',      -5);
  33. define('RDF_ERROR_MISMATCH',        -6);
  34. // ----------------------------------------------------------------------------------
  35. // Model
  36. // ----------------------------------------------------------------------------------
  37. define('RDF_BNODE_PREFIX''bNode');
  38. // ----------------------------------------------------------------------------------
  39. // Parser
  40. // ----------------------------------------------------------------------------------
  41. // RDFParser: Set this option to false if you want to use IDs containing CombiningChars or 
  42. // Extenders (see http://www.w3.org/TR/REC-xml-names/#NT-NCName). If set to TRUE, they're assumed to be invalid.
  43. define('RDF_VALIDATE_IDS'true);
  44. // N3 and N-Triple-Parser: Set this option to true in order to override the given bnode 
  45. // labels and rename them to the defined BNODE_PREFIX
  46. define('RDF_FIX_BLANKNODES'true);
  47. define('RDF_NAMESPACE_SEPARATOR_CHAR''^');
  48. define('RDF_NAMESPACE_SEPARATOR_STRING''^');
  49. define('RDF_IN_TOP_LEVEL'0);
  50. define('RDF_IN_RDF'1);
  51. define('RDF_IN_DESCRIPTION'2);
  52. define('RDF_IN_PROPERTY_UNKNOWN_OBJECT'3);
  53. define('RDF_IN_PROPERTY_RESOURCE'4);
  54. define('RDF_IN_PROPERTY_EMPTY_RESOURCE'5);
  55. define('RDF_IN_PROPERTY_LITERAL'6);
  56. define('RDF_IN_PROPERTY_PARSE_TYPE_LITERAL'7);
  57. define('RDF_IN_PROPERTY_PARSE_TYPE_RESOURCE'8);
  58. define('RDF_IN_XML'9);
  59. define('RDF_IN_UNKNOWN'10);
  60. define('RDF_IN_PROPERTY_PARSE_TYPE_COLLECTION'11);
  61. define('RDF_SUBJECT_TYPE_URI'0);
  62. define('RDF_SUBJECT_TYPE_DISTRIBUTED'1);
  63. define('RDF_SUBJECT_TYPE_PREFIX'2);
  64. define('RDF_SUBJECT_TYPE_ANONYMOUS'3);
  65. define('RDF_SUBJECT_TYPE_BNODE'4);
  66. define('RDF_OBJECT_TYPE_RESOURCE'0);
  67. define('RDF_OBJECT_TYPE_LITERAL'1);
  68. define('RDF_OBJECT_TYPE_XML'2);
  69. define('RDF_OBJECT_TYPE_BNODE'3);
  70. // ----------------------------------------------------------------------------------
  71. // Serializer
  72. // ----------------------------------------------------------------------------------
  73. // RDF, N3, N-Triple Serializer: set to TRUE in oder to suppres the "Generated by RAP" 
  74. // comment in the output files.
  75. define('RDF_HIDE_ADVERTISE'false);
  76. // RDF Serializer: Set to TRUE, if the serializer should use entities for URIs.
  77. define('RDF_SER_USE_ENTITIES'false);
  78. // RDF Serializer: Set to TRUE, if the serializer should serialize triples as XML 
  79. // attributes where possible.
  80. define('RDF_SER_USE_ATTRIBUTES'false);
  81. // RDF Serializer: Set to TRUE in order to sort the statements of a model before 
  82. // serializing them.
  83. define('RDF_SER_SORT_MODEL'true);
  84. // RDF Serializer: Set to TRUE, if the serializer should use qualified names for RDF
  85. // reserved words.
  86. // NOTE: There is only one default namespace allowed within an XML document.
  87. //       Therefore if SER_RDF_QNAMES in is set to FALSE and you pass the parameter
  88. //       $xml_default_namespace to the method serialize() of class RDFSerializer, 
  89. //       the model will be serialized as if SER_RDF_QNAMES were set to TRUE.
  90. define('RDF_SER_RDF_QNAMES'true);
  91. // RDF Serializer: Set to TRUE, if the serializer should start documents with the 
  92. // xml declaration <?xml version="1.0" encoding="UTF-8" >.
  93. define('RDF_SER_XML_DECLARATION'true);
  94. // N3 Serializer: Set to TRUE, if the N3 serializer should try to compress the blank node 
  95. // syntax using [] whereever possible.
  96. define('RDF_N3SER_BNODE_SHORT'true);
  97. // RDF Serializer: Set to TRUE, if the serializer should write text values always as 
  98. // escaped CDATA.
  99. define('RDF_USE_CDATA'false);
  100. define('RDF_USE_ANY_QUOTE'false);
  101. define('RDF_GENERAL_PREFIX_BASE''ns');
  102. define('RDF_MAX_ALLOWED_ABBREVIATED_LENGTH'60);
  103. // ----------------------------------------------------------------------------------
  104. // Util
  105. // ----------------------------------------------------------------------------------
  106. // Definition of the colors used by the method RDF_Util:writeHTMLTable
  107. define('RDF_HTML_TABLE_HEADER_COLOR''#FFFFFF');
  108. define('RDF_HTML_TABLE_RESOURCE_COLOR''#FFFFCC');
  109. define('RDF_HTML_TABLE_LITERAL_COLOR''#E7E7EF');
  110. define('RDF_HTML_TABLE_BNODE_COLOR''#FFCCFF');
  111. define('RDF_HTML_TABLE_RDF_NS_COLOR''#CCFFCC');
  112. // ----------------------------------------------------------------------------------
  113. // RDF
  114. // ----------------------------------------------------------------------------------
  115. define('RDF_SYNTAX_COMPACT'true);
  116. define('RDF_NAMESPACE_URI''http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  117. define('RDF_NAMESPACE_PREFIX''rdf');
  118. define('RDF''RDF');
  119. define('RDF_DESCRIPTION''Description');
  120. define('RDF_ID''ID');
  121. define('RDF_ABOUT''about');
  122. define('RDF_ABOUT_EACH''aboutEach');
  123. define('RDF_ABOUT_EACH_PREFIX''aboutEachPrefix');
  124. define('RDF_BAG_ID''bagID');
  125. define('RDF_RESOURCE''resource');
  126. define('RDF_VALUE''value');
  127. define('RDF_PARSE_TYPE''parseType');
  128. define('RDF_PARSE_TYPE_LITERAL''Literal');
  129. define('RDF_PARSE_TYPE_RESOURCE''Resource');
  130. define('RDF_PARSE_TYPE_COLLECTION''Collection');
  131. define('RDF_TYPE''type');
  132. define('RDF_BAG''Bag');
  133. define('RDF_SEQ''Seq');
  134. define('RDF_ALT''Alt');
  135. define('RDF_LI''li');
  136. define('RDF_STATEMENT''Statement');
  137. define('RDF_SUBJECT''subject');
  138. define('RDF_PREDICATE''predicate');
  139. define('RDF_OBJECT''object');
  140. define('RDF_NODEID''nodeID');
  141. define('RDF_DATATYPE''datatype');
  142. define('RDF_SEEALSO''seeAlso');
  143. define('RDF_PROPERTY''Property');
  144. define('RDF_LIST''List');
  145. define('RDF_NIL''nil');
  146. define('RDF_REST''rest');
  147. define('RDF_FIRST''first');
  148. define('RDF_XMLLITERAL''XMLLiteral');
  149. // ----------------------------------------------------------------------------------
  150. // RDF Schema
  151. // ----------------------------------------------------------------------------------
  152. define('RDF_SCHEMA_URI''http://www.w3.org/2000/01/rdf-schema#');
  153. define('RDF_DATATYPE_SCHEMA_URI''http://www.w3.org/TR/xmlschema-2');
  154. define('RDF_SCHEMA_PREFIX''rdfs');
  155. define('RDF_RDFS_SUBCLASSOF''subClassOf');
  156. define('RDF_RDFS_SUBPROPERTYOF''subPropertyOf');
  157. define('RDF_RDF','RDF');
  158. // ----------------------------------------------------------------------------------
  159. // XML
  160. // ----------------------------------------------------------------------------------
  161. define('RDF_XML_NAMESPACE_PREFIX''xml');
  162. define('RDF_XML_NAMESPACE_DECLARATION_PREFIX''xmlns');
  163. define('RDF_XML_NAMESPACE_URI''http://www.w3.org/XML/1998/namespace');
  164. define('RDF_XML_LANG''lang');
  165. define('RDF_DATATYPE_SHORTCUT_PREFIX''datatype:');
  166. // ----------------------------------------------------------------------------------
  167. // RDF DATATYPE SHORTCUTS (extends datatype shortcuts to the full XML datatype URIs)
  168. // ----------------------------------------------------------------------------------
  169. $GLOBALS['_RDF_default_datatype'= array(
  170.     'STRING'   => RDF_DATATYPE_SCHEMA_URI . '#string',
  171.     'DECIMAL'  => RDF_DATATYPE_SCHEMA_URI . '#decimal',
  172.     'INTEGER'  => RDF_DATATYPE_SCHEMA_URI . '#integer',
  173.     'INT'      => RDF_DATATYPE_SCHEMA_URI . '#int',
  174.     'SHORT'    => RDF_DATATYPE_SCHEMA_URI . '#short',
  175.     'BYTE'     => RDF_DATATYPE_SCHEMA_URI . '#byte',
  176.     'LONG'     => RDF_DATATYPE_SCHEMA_URI . '#long',
  177.     'LANGUAGE' => RDF_DATATYPE_SCHEMA_URI . '#language',
  178.     'NAME'     => RDF_DATATYPE_SCHEMA_URI . '#name'
  179. );
  180.  
  181. class RDF
  182. {
  183.     function factory($class&$param)
  184.     {
  185.        $file 'RDF/'.str_replace('_''/'$class).'.php';
  186.        include_once $file;
  187.        $classname 'RDF_'.$class;
  188.        $obj =new $classname();
  189.        if (method_exists($obj'init')) {
  190.            call_user_func_array(array(&$obj'init')$param);
  191.        }
  192.        return $obj;
  193.     }
  194.  
  195.     // }}}
  196.     // {{{ raiseError()
  197.  
  198.     /**
  199.      * This method is used to communicate an error and invoke error
  200.      * callbacks etc.  Basically a wrapper for PEAR::raiseError
  201.      * without the message string.
  202.      *
  203.      * @param mixed    integer error code, or a PEAR error object (all
  204.      *                  other parameters are ignored if this parameter is
  205.      *                  an object
  206.      *
  207.      * @param int      error mode, see PEAR_Error docs
  208.      *
  209.      * @param mixed    If error mode is PEAR_ERROR_TRIGGER, this is the
  210.      *                  error level (E_USER_NOTICE etc).  If error mode is
  211.      *                  PEAR_ERROR_CALLBACK, this is the callback function,
  212.      *                  either as a function name, or as an array of an
  213.      *                  object and method name.  For other error modes this
  214.      *                  parameter is ignored.
  215.      *
  216.      * @param string   Extra debug information.  Defaults to the last
  217.      *                  query and native error code.
  218.      *
  219.      * @return object  PEAR error object
  220.      *
  221.      * @see PEAR_Error
  222.      */
  223.     function &raiseError($code = null$mode = null$options = null$userinfo = null)
  224.     {
  225.         // The error is yet a MDB error object
  226.         if (is_object($code)) {
  227.             // because we the static PEAR::raiseError, our global
  228.             // handler should be used if it is set
  229.             if ($mode === null && !empty($this->_default_error_mode)) {
  230.                 $mode    $this->_default_error_mode;
  231.                 $options $this->_default_error_options;
  232.             }
  233.             return PEAR::raiseError($codenull$mode$optionsnullnulltrue);
  234.         }
  235.  
  236.         return PEAR::raiseError(null$code$mode$options$userinfo'RDF_Error'true);
  237.     }
  238.     /**
  239.      * Return a textual error message for a RAP error code.
  240.      *
  241.      * @access  public
  242.      * @param   int     error code
  243.      * @return  string  error message
  244.      */
  245.     function errorMessage($value)
  246.     {
  247.         // make the variable static so that it only has to do the defining on the first call
  248.         static $errorMessages;
  249.  
  250.         // define the varies error messages
  251.         if (!isset($errorMessages)) {
  252.             $errorMessages = array(
  253.                 RDF_ERROR                   => 'Unknown error',
  254.                 RDF_ERROR_NOT_SUPPORTED     => 'Feature not supported',
  255.                 RDF_ERROR_CONFIG_ERROR      => 'Config file error',
  256.                 RDF_ERROR_MISSING_DEPS      => 'Missing package depedencies',
  257.                 RDF_ERROR_UNEXPECTED        => 'Unexpected',
  258.                 RDF_ERROR_MISMATCH          => 'Mismatch',
  259.             );
  260.         }
  261.  
  262.         // If this is an error object, then grab the corresponding error code
  263.         if (RDF::isError($value)) {
  264.             $value $value->getCode();
  265.         }
  266.  
  267.         // return the textual error message corresponding to the code
  268.         return isset($errorMessages[$value]$errorMessages[$value$errorMessages[RDF_ERROR];
  269.     // end func errorMessage
  270.  
  271.     function isError($value)
  272.     {
  273.         return is_a($value'RDF_Error');
  274.     }
  275. }
  276.  
  277. // ----------------------------------------------------------------------------------
  278. // Class: RDF_Object
  279. // ----------------------------------------------------------------------------------
  280. /**
  281.  * An abstract object.
  282.  * Root object with some general methods, that should be overloaded.
  283.  * 
  284.  * @version V0.7
  285.  * @author Chris Bizer <chris@bizer.de>
  286.  * @abstract
  287.  * @package util
  288.  */
  289. class RDF_Object
  290. {
  291.     function factory()
  292.     {
  293.         return RDF::raiseError(RDF_ERRORnullnull'Not implemented');
  294.     }
  295.  
  296.     /**
  297.      * Serializes a object into a string
  298.      * 
  299.      * @access public
  300.      * @return string 
  301.      */
  302.     function toString()
  303.     {
  304.         $objectvars get_object_vars($this);
  305.         foreach($objectvars as $key => $value{
  306.             $content.= $key "='" $value "'; ";
  307.         }
  308.         return 'Instance of ' get_class($this'; Properties: ' $content;
  309.     }
  310. }
  311.  
  312. /**
  313.  * RDF_Error implements a class for reporting RDF error
  314.  * messages.
  315.  *
  316.  * @package RDF
  317.  * @category RDF
  318.  * @author  Stig Bakken <ssb@fast.no>
  319.  */
  320. class RDF_Error extends PEAR_Error
  321. {
  322.     // }}}
  323.     // {{{ constructor
  324.  
  325.     /**
  326.      * RDF_Error constructor.
  327.      *
  328.      * @param mixed   $code      RDF error code, or string with error message.
  329.      * @param integer $mode      what 'error mode' to operate in
  330.      * @param integer $level     what error level to use for
  331.      *                            $mode & PEAR_ERROR_TRIGGER
  332.      * @param smixed  $debuginfo additional debug info, such as the last query
  333.      */
  334.     function RDF_Error($code = RDF_ERROR$mode = PEAR_ERROR_RETURN,
  335.               $level = E_USER_NOTICE$debuginfo = null)
  336.     {
  337.         if (is_int($code)) {
  338.             $this->PEAR_Error('RDF Error: '.RDF::errorMessage($code)$code,
  339.                 $mode$level$debuginfo);
  340.         else {
  341.             $this->PEAR_Error("RDF Error: $code"RDF_ERROR$mode$level,
  342.                 $debuginfo);
  343.         }
  344.     }
  345. }
  346.  
  347. require_once 'RDF/Util.php';
  348. require_once 'RDF/Literal.php';
  349. require_once 'RDF/Resource.php';
  350. require_once 'RDF/BlankNode.php';
  351. require_once 'RDF/Statement.php';
  352. require_once 'RDF/StatementIterator.php';
  353.  
  354. require_once 'RDF/Parser.php';
  355. require_once 'RDF/Serializer.php';
  356.  
  357. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:29 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.