コード例 #1
0
ファイル: Graph.php プロジェクト: johnulist/easyrdf
 /** Add one or more rdf:type properties to a resource
  *
  * @param  string  $resource The resource to add the type to
  * @param  string  $types    One or more types to add (e.g. foaf:Person)
  *
  * @return integer           The number of types added
  */
 public function addType($resource, $types)
 {
     $this->checkResourceParam($resource, true);
     if (!is_array($types)) {
         $types = array($types);
     }
     $count = 0;
     foreach ($types as $type) {
         $type = RdfNamespace::expand($type);
         $count += $this->add($resource, 'rdf:type', array('type' => 'uri', 'value' => $type));
     }
     return $count;
 }
コード例 #2
0
ファイル: Utils.php プロジェクト: johnulist/easyrdf
 /** 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;
     }
 }
コード例 #3
0
ファイル: Resource.php プロジェクト: johnulist/easyrdf
 /** 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);
 }
コード例 #4
0
 /**
  * Method called to associate a RdfNamespace object to this object
  * through the RdfNamespace foreign key attribute
  *
  * @param      RdfNamespace $l RdfNamespace
  * @return     void
  * @throws     PropelException
  */
 public function addRdfNamespace(RdfNamespace $l)
 {
     $this->collRdfNamespaces[] = $l;
     $l->setSchema($this);
 }
コード例 #5
0
ファイル: Literal.php プロジェクト: johnulist/easyrdf
 /** 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;
     }
 }
コード例 #6
0
ファイル: TypeMapper.php プロジェクト: johnulist/easyrdf
 /**
  * Delete an existing RDF type mapping.
  *
  * @param  string  $type   The RDF type (e.g. foaf:Person)
  *
  * @throws \InvalidArgumentException
  */
 public static function delete($type)
 {
     if (!is_string($type) or $type == null or $type == '') {
         throw new \InvalidArgumentException("\$type should be a string and cannot be null or empty");
     }
     $type = RdfNamespace::expand($type);
     if (isset(self::$map[$type])) {
         unset(self::$map[$type]);
     }
 }