public function getDocument($input)
    {
        $nodeMap = new JsonObject();
        $nodeMap->{'-' . JsonLD::DEFAULT_GRAPH} = new JsonObject();
        $this->generateNodeMap($nodeMap, $input);

        // We need to keep track of blank nodes as they are renamed when
        // inserted into the Document
        $nodes = array();

        if (null === $this->documentFactory) {
            $this->documentFactory = new DefaultDocumentFactory();
        }

        $document = $this->documentFactory->createDocument($this->baseIri);

        foreach ($nodeMap as $graphName => &$nodes) {
            $graphName = substr($graphName, 1);
            if (JsonLD::DEFAULT_GRAPH === $graphName) {
                $graph = $document->getGraph();
            } else {
                $graph = $document->createGraph($graphName);
            }

            foreach ($nodes as $id => &$item) {
                $node = $graph->createNode($item->{'@id'}, true);
                unset($item->{'@id'});

                // Process node type as it needs to be handled differently than
                // other properties
                // TODO Could this be avoided by enforcing rdf:type instead of @type?
                if (property_exists($item, '@type')) {
                    foreach ($item->{'@type'} as $type) {
                        $node->addType($graph->createNode($type), true);
                    }
                    unset($item->{'@type'});
                }

                foreach ($item as $property => $values) {
                    foreach ($values as $value) {
                        if (property_exists($value, '@value')) {
                            $node->addPropertyValue($property, Value::fromJsonLd($value));
                        } elseif (property_exists($value, '@id')) {
                            $node->addPropertyValue(
                                $property,
                                $graph->createNode($value->{'@id'}, true)
                            );
                        } else {
                            // TODO Handle lists
                            throw new \Exception('Lists are not supported by getDocument() yet');
                        }
                    }
                }
            }
        }


        unset($nodeMap);

        return $document;
    }
public function getDocument($input)
    {
        $nodeMap = new JsonObject();
        $nodeMap->{'-' . JsonLD::DEFAULT_GRAPH} = new JsonObject();
        $this->generateNodeMap($nodeMap, $input);

        // We need to keep track of blank nodes as they are renamed when
        // inserted into the Document
        $nodes = array();

        if (null === $this->documentFactory) {
            $this->documentFactory = new DefaultDocumentFactory();
        }

        $document = $this->documentFactory->createDocument($this->baseIri);

        foreach ($nodeMap as $graphName => &$nodes) {
            $graphName = substr($graphName, 1);
            if (JsonLD::DEFAULT_GRAPH === $graphName) {
                $graph = $document->getGraph();
            } else {
                $graph = $document->createGraph($graphName);
            }

            foreach ($nodes as $id => &$item) {
                $node = $graph->createNode($item->{'@id'}, true);
                unset($item->{'@id'});

                // Process node type as it needs to be handled differently than
                // other properties
                // TODO Could this be avoided by enforcing rdf:type instead of @type?
                if (property_exists($item, '@type')) {
                    foreach ($item->{'@type'} as $type) {
                        $node->addType($graph->createNode($type), true);
                    }
                    unset($item->{'@type'});
                }

                foreach ($item as $property => $values) {
                    foreach ($values as $value) {
                        if (property_exists($value, '@value')) {
                            $node->addPropertyValue($property, Value::fromJsonLd($value));
                        } elseif (property_exists($value, '@id')) {
                            $node->addPropertyValue(
                                $property,
                                $graph->createNode($value->{'@id'}, true)
                            );
                        } else {
                            // TODO Handle lists
                            throw new \Exception('Lists are not supported by getDocument() yet');
                        }
                    }
                }
            }
        }


        unset($nodeMap);

        return $document;
    }
public function getDocument ( $ input ) { $ nodeMap = new JsonObject ( ) ; $ nodeMap -> { '-' . JsonLD :: DEFAULT_GRAPH } = new JsonObject ( ) ; $ this -> generateNodeMap ( $ nodeMap , $ input ) ; // We need to keep track of blank nodes as they are renamed when // inserted into the Document $ nodes = array ( ) ; if ( null === $ this -> documentFactory ) { $ this -> documentFactory = new DefaultDocumentFactory ( ) ; } $ document = $ this -> documentFactory -> createDocument ( $ this -> baseIri ) ; foreach ( $ nodeMap as $ graphName => & $ nodes ) { $ graphName = substr ( $ graphName , 1 ) ; if ( JsonLD :: DEFAULT_GRAPH === $ graphName ) { $ graph = $ document -> getGraph ( ) ; } else { $ graph = $ document -> createGraph ( $ graphName ) ; } foreach ( $ nodes as $ id => & $ item ) { $ node = $ graph -> createNode ( $ item -> { '@id' } , true ) ; unset ( $ item -> { '@id' } ) ; // Process node type as it needs to be handled differently than // other properties // TODO Could this be avoided by enforcing rdf:type instead of @type? if ( property_exists ( $ item , '@type' ) ) { foreach ( $ item -> { '@type' } as $ type ) { $ node -> addType ( $ graph -> createNode ( $ type ) , true ) ; } unset ( $ item -> { '@type' } ) ; } foreach ( $ item as $ property => $ values ) { foreach ( $ values as $ value ) { if ( property_exists ( $ value , '@value' ) ) { $ node -> addPropertyValue ( $ property , Value :: fromJsonLd ( $ value ) ) ; } elseif ( property_exists ( $ value , '@id' ) ) { $ node -> addPropertyValue ( $ property , $ graph -> createNode ( $ value -> { '@id' } , true ) ) ; } else { // TODO Handle lists throw new \ Exception ( 'Lists are not supported by getDocument() yet' ) ; } } } } } unset ( $ nodeMap ) ; return $ document ; }
Parses a JSON-LD document and returns it as a Document

@param array|JsonObject $input The JSON-LD document to process.

@return Document The parsed JSON-LD document.

@throws JsonLdException If the JSON-LD input document is invalid.
Parses a JSON - LD document and returns it as a Document