/** * Outputs the RDF statements found in the given JSON-LD object. * * @param mixed $input the JSON-LD object. * @param assoc [$options] the options to use: * [base] the base IRI to use. * [format] the format to use to output a string: * 'application/nquads' for N-Quads (default). * [resolver(url)] the URL resolver to use. * * @return array all RDF statements in the JSON-LD object. */ function jsonld_to_rdf($input, $options = array()) { $p = new JsonLdProcessor(); return $p->toRDF($input, $options); }
public function __construct($manifest, $data, $filename) { $this->manifest = $manifest; $this->data = $data; $this->filename = $filename; $this->dirname = dirname($filename); $this->isPositive = JsonLdProcessor::hasValue($data, '@type', 'jld:PositiveEvaluationTest'); $this->isNegative = JsonLdProcessor::hasValue($data, '@type', 'jld:NegativeEvaluationTest'); // generate test name $this->name = $manifest->data->name . ' ' . substr($data->{'@id'}, 2) . ' - ' . $this->data->name; // expand @id and input base $data->{'@id'} = $manifest->data->baseIri . basename($manifest->filename) . $data->{'@id'}; $this->base = $manifest->data->baseIri . $data->input; }
/** * Normalizes a JSON-LD object. * * @param input the JSON-LD object to normalize. * * @return the normalized JSON-LD object. */ function jsonld_normalize($input) { $p = new JsonLdProcessor(); return $p->normalize($input); }
/** * Relabels all blank nodes in the given JSON-LD input. * * @param mixed input the JSON-LD input. */ function jsonld_relabel_blank_nodes($input) { $p = new JsonLdProcessor(); return $p->_labelBlankNodes(new UniqueNamer('_:b'), $input); }
/** * Appends an RDF statement to the given array of statements if it is unique. * * @param array $statements the array to add to. * @param stdClass $statement the statement to add. */ protected static function _appendUniqueRdfStatement(&$statements, $statement) { foreach ($statements as $s) { if (JsonLdProcessor::_compareRdfStatements($s, $statement)) { return; } } $statements[] = $statement; }
/** * Sets an active context in the cache based on the previous active * context and the just-processed local context. * * @param stdClass $active_ctx the previous active context. * @param stdClass $local_ctx the just-processed local context. * @param stdClass $result the resulting active context. */ public function set($active_ctx, $local_ctx, $result) { if (count($this->order) === $this->size) { $entry = array_shift($this->order); unset($this->cache->{$entry->activeCtx}->{$entry->localCtx}); } $key1 = serialize($active_ctx); $key2 = serialize($local_ctx); $this->order[] = (object) array('activeCtx' => $key1, 'localCtx' => $key2); if (!property_exists($this->cache, $key1)) { $this->cache->{$key1} = new stdClass(); } $this->cache->{$key1}->{$key2} = JsonLdProcessor::copy($result); }
public function check($test, $expect, $result) { global $eol; if (in_array('jld:NormalizeTest', $test->{'@type'}) !== false) { $pass = JsonLdProcessor::compareNormalized($expect, $result); } else { $pass = deep_compare($expect, $result); } if ($pass) { $this->passed += 1; echo "PASS{$eol}"; } else { $this->failed += 1; echo "FAIL{$eol}"; echo 'Expect: ' . print_r($expect, true) . $eol; echo 'Result: ' . print_r($result, true) . $eol; /* $flags = JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT; echo 'JSON Expect: ' . json_encode(json_decode(expect, $flags)) . $eol; echo 'JSON Result: ' . json_encode(json_decode(result, $flags)) . $eol; */ } }