コード例 #1
0
ファイル: Literal.php プロジェクト: johnulist/easyrdf
 /** Constructor for creating a new literal
  *
  * @param  string $value     The value of the literal
  * @param  string $lang      The natural language of the literal or null (e.g. 'en')
  * @param  string $datatype  The datatype of the literal or null (e.g. 'xsd:string')
  *
  * @return Literal
  */
 public function __construct($value, $lang = null, $datatype = null)
 {
     $this->value = $value;
     $this->lang = $lang ? $lang : null;
     $this->datatype = $datatype ? $datatype : null;
     if ($this->datatype) {
         if (is_object($this->datatype)) {
             // Convert objects to strings
             $this->datatype = strval($this->datatype);
         } else {
             // Expand shortened URIs (CURIEs)
             $this->datatype = RdfNamespace::expand($this->datatype);
         }
         // Literals can not have both a language and a datatype
         $this->lang = null;
     } else {
         // Set the datatype based on the subclass
         $class = get_class($this);
         if (isset(self::$classMap[$class])) {
             $this->datatype = self::$classMap[$class];
             $this->lang = null;
         }
     }
     if (is_float($this->value)) {
         // special handling of floats, as they suffer from locale [mis]configuration
         $this->value = rtrim(sprintf('%F', $this->value), '0');
     } else {
         // Cast value to string
         settype($this->value, 'string');
     }
 }
コード例 #2
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;
 }
コード例 #3
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]);
     }
 }