Changeset 35


Ignore:
Timestamp:
Jul 15, 2011, 2:51:52 PM (14 years ago)
Author:
ktk
Message:

rdfint

  • implemented set method
Location:
php/trunk/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • php/trunk/classes/rdfa_Data.php

    r30 r35  
    794794   * Sets a property value for a subject.
    795795   *
    796    * \param subject   Subject to get the property set
    797    * \param property  Property to be added
    798    * \param value     Value to be set for the property
     796   * \param subject   Subject to get the property set as URI or CURIE
     797   * \param property  Property to be added as URI or CURIE
     798   * \param value     Value to be set for the property as URI, CURIE or literal value
    799799   * \param type      The type of the value, either 'uri', 'literal' or 'bnode'
    800800   *                  (case-insensitive). Specifying the first character is sufficient.
    801801   *                  If not specified, strings starting with 'http://' are taken as a URI,
    802    *                  otherwise as a literal
     802   *                  strings starting with '_:' as a blank node, otherwise as a literal
    803803   * \retval boolean  true: property value set \n
    804804   *                  false: subject not found or invalid value type specified
     
    813813    $predicate = $property;
    814814    $object = $value;
    815 
    816     // insert code here
    817815   
    818     return $result;
     816    // resolve namespace prefixes
     817    $uriSubject   = $this->_resolve( $subject);
     818    $uriPredicate = $this->_resolve( $predicate);
     819    $uriObject    = $this->_resolve( $object);
     820
     821    // resolve method may return NULL, then use original value
     822    $uriSubject   = ($uriSubject   === NULL) ? $subject   : $uriSubject;
     823    $uriPredicate = ($uriPredicate === NULL) ? $predicate : $uriPredicate;
     824    $uriObject    = ($uriObject    === NULL) ? $object    : $uriObject;
     825   
     826    // check what type we have
     827    // This is not clear in the API. It could be interpreted that the only acceptable value is a literal
     828    // We have to check what the intention is and adjust it accordingly or enhance the specs
     829    if ($type == null) {
     830      if (preg_match('#^http://.?#', $value))
     831        $type = 'uri';
     832      elseif (preg_match('#/^_:.?/#', $value))
     833        $type = 'bnode';
     834      else
     835        $type = 'literal';
     836    }
     837
     838    if (!preg_match('#^(uri|bnode|literal)$#', strtolower($type)))
     839      return false;
     840   
     841    // construct the aTriple array
     842    $aTriple = array();
     843    $aTriple['type'] = 'triple';
     844    $aTriple['s'] = $uriSubject;
     845    $aTriple['p'] = $uriPredicate;
     846    $aTriple['o'] = $uriObject;
     847    $aTriple['s_type'] = 'uri';
     848    $aTriple['p_type'] = 'uri';
     849    $aTriple['o_type'] = strtolower($type);
     850   
     851    $aTriple['o_datatype'] = ''; // data types, currently not supported by the API
     852    $aTriple['o_lang'] = ''; // language, same same
     853
     854   
     855    $this->_addTriple( $aTriple);
     856   
     857    return true;
    819858
    820859  } // public function _setValue
     
    10891128
    10901129  } // public function _serialize
     1130 
    10911131
    10921132} // class Data
  • php/trunk/classes/rdfa_Projection.php

    r30 r35  
    177177   * \retval boolean   false: invalid value type specified
    178178   *
    179    * \see rdfa::Data::setValue
     179   * \see rdfa::Data::_setValue
    180180   *
    181181   * \note
     
    185185
    186186  public function set( $property, $value, $type = NULL) {
    187 
    188     // insert code here
     187   
     188    $ret = $this->rdfaData->_setValue($this->subject, $property, $value, $type );   
     189   
     190    if($ret)
     191      return $this;
     192    else
     193      return false;
    189194  }
    190195
Note: See TracChangeset for help on using the changeset viewer.