示例#1
0
/**
 * Convert an RDF/JSON string into the MarmottaClient metadata representation. Returns an array of the form
 *
 * array(
 *    "http://xmlns.com/foaf/0.1/name" => array(new Literal("Sepp Huber"))
 * )
 *
 * @param $rdfjson_string
 */
function decode_metadata($uri, $rdfjson_string)
{
    $result = array();
    $json_array = json_decode($rdfjson_string, true);
    foreach ($json_array as $subject => $properties) {
        if ($uri == $subject) {
            foreach ($properties as $property => $objects) {
                $result[$property] = array();
                foreach ($objects as $object) {
                    $result[$property][] = decode_node($object);
                }
            }
        }
    }
    return $result;
}
示例#2
0
 /**
  * Evaluate the LDPath program passed as second argument starting at the resource identified by the uri given as first argument.
  * Returns a map from field names to lists of RDFNode objects, representing the results of the evaluation.
  *
  * @param $uri
  * @param $program
  */
 public function evaluateProgram($uri, $program)
 {
     $serviceUrl = $this->config->getBaseUrl() . LDPathClient::$URL_PROGRAM_SERVICE . urlencode($program) . "&uri=" . urlencode($uri);
     try {
         $client = new Client();
         $request = $client->get($serviceUrl, array("User-Agent" => "Marmotta Client Library (PHP)", "Accept" => "application/json"));
         // set authentication if given in configuration
         if (!is_null($this->config->getUsername())) {
             $request->setAuth($this->config->getUsername(), $this->config->getPassword());
         }
         $response = $request->send();
         $query_result = json_decode($response->getBody(true), true);
         $result = array();
         foreach ($query_result as $field => $value) {
             $result[$field] = array();
             foreach ($value as $node) {
                 $result[$field][] = decode_node($node);
             }
         }
         return $result;
     } catch (BadResponseException $ex) {
         throw new MarmottaClientException("error evaluating LDPath Query {$path}; " . $ex->getResponse()->getReasonPhrase());
     }
 }