Python - rdflib - json-ld - why does it not parse the nested triples

34 Views Asked by At

I have the following code, parsing the JSON-ld file below. However, it only outputs the top-level triples and not the other, such as the name of the WebPage

from rdflib import Dataset
from rdflib.namespace import Namespace, NamespaceManager

local_input="""
[
    {
        "@context": "https://schema.org/"
    },
    {
        "@type": "WebPage",
        "@id": "https://example.com/glossary/term/",
        "name": "My Glossary Term",
        "abstract": "Just my glossary Term.",
        "datePublished": "2024-03-08T07:52:13+02:00",
        "dateModified": "2024-03-08T14:54:13+02:00",
        "url": "https://example.com/glossary/term/",
        "author": {
            "@type": "Person",
            "@id": "https://example.com/",
            "name": "John Doe"
        },
        "about": [
            {
                "@type": "DefinedTerm",
                "@id": "https://example.com/glossary/term/#definedTerm"
            }
        ]
    },
    {
        "@type": "DefinedTerm",
        "@id": "https://example.com/glossary/term/#definedTerm",
        "name": "My Term",
        "description": "Just my Term",
        "inDefinedTermSet": {
            "@type": "DefinedTermSet",
            "@id": "https://example.com/glossary/#definedTermSet"
        }
    }
]
"""

SCH = Namespace('https://schema.org/')
namespace_manager = NamespaceManager(Dataset(), bind_namespaces='none')
namespace_manager.bind('', SCH, override=True)
g = Dataset()
g.namespace_manager = namespace_manager
g.parse(data=local_input, format='json-ld', publicID="http://schema.org/")

print(len(g))

import pprint
for stmt in g:
    pprint.pprint(stmt)

OUTPUT:

2
(rdflib.term.URIRef('https://example.com/glossary/term/'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
 rdflib.term.URIRef('http://schema.org/WebPage'),
 rdflib.term.URIRef('urn:x-rdflib:default'))
(rdflib.term.URIRef('https://example.com/glossary/term/#definedTerm'),
 rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
 rdflib.term.URIRef('http://schema.org/DefinedTerm'),
 rdflib.term.URIRef('urn:x-rdflib:default'))
0

There are 0 best solutions below