Ejemplo n.º 1
0
 /**
  * Convert a list of L10nResources in a JSON-LD file
  * @param array(L10nResources) $l10nResourceList
  * @return string : JSON-LD document
  */
 public function convertL10nResourceList(array $l10nResourceList)
 {
     $quadList = array();
     $c = 0;
     if (count($l10nResourceList)) {
         foreach ($l10nResourceList as $l10nResource) {
             $bNode = new IRI('_' . $c);
             $quadList[] = new Quad($bNode, new IRI(self::NS . 'key'), new IRI($l10nResource->getIdResource()));
             $quadList[] = new Quad($bNode, new IRI(self::NS . 'localization'), new IRI($l10nResource->getIdLocalization()));
             $valueList = $l10nResource->getValueList();
             foreach ($valueList as $locale => $value) {
                 if (!is_int($locale)) {
                     $value .= '@' . $locale;
                 }
                 $quadList[] = new Quad($bNode, new IRI(self::NS . 'value'), new TypedValue($value, RdfConstants::XSD_STRING));
             }
             $c++;
         }
     }
     $jsonLd = JsonLD::fromRdf($quadList);
     $compacted = JsonLD::compact($jsonLd, '{"@context": {"l10n" : "' . self::NS . '"}}', array('compactArrays' => false));
     return JsonLD::toString($compacted, true);
 }
Ejemplo n.º 2
0
 /**
  * Tests conversion from quads.
  *
  * @param string $name    The test name.
  * @param object $test    The test definition.
  * @param object $options The options to configure the algorithms.
  *
  * @group fromRdf
  * @dataProvider fromRdfProvider
  */
 public function testFromRdf($name, $test, $options)
 {
     $expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
     $parser = new NQuads();
     $quads = $parser->parse(file_get_contents($this->basedir . $test->{'input'}));
     $result = JsonLD::fromRdf($quads, $options);
     $this->assertEquals($expected, $result);
 }