代码之家  ›  专栏  ›  技术社区  ›  Anatoly Scherbakov

RDFLib+JSON-LD+命名图:使用@graph时如何重写图名?

  •  1
  • Anatoly Scherbakov  · 技术社区  · 5 年前

    Gist .

    Robot 班级和a Rover 作为它的子类,使用 @graph

    {
        "@context": {
            "schema": "https://schema.org/",
            "blog": "https://blog.me/",
            "ex": "https://example.org/",
            "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
        },
        "@id": "blog:JSONLD-and-named-graphs",
        "@type": "schema:blogPost",
        "rdfs:label": "JSON-LD and Named Graphs",
        "@graph": [
            {
                "@id": "ex:Robot",
                "@type": "rdfs:Class"
            },
            {
                "@id": "ex:Rover",
                "rdfs:subClassOf": {
                    "@id": "ex:Robot"
                }
            }
        ]
    }
    

    使用Python rdflib ,我们希望将所有这些导入指定为 https://myblog.net/rdf/ 这样地:

        ...
        graph = ConjunctiveGraph()
    
        serialized_document = json.dumps(JSONLD_DOCUMENT)
    
        graph.parse(
            data=serialized_document,
            format='json-ld',
            # All the semantic data about my blog is stored in a particular
            # named graph.
            publicID='https://myblog.net/rdf/',
        )
    

    所有数据都应该在命名图下导入 https://myblog.net/rdf/ 基于 publicID

    实际结果

    prescribes . {"@id": "badoom", "@graph": {...}} 意思是我们描述了一个 并提供其名称为 @id .

    问题

    公共ID 争论?

    软件版本:

    Python 3.8.1
    rdflib==5.0.0
    rdflib-jsonld==0.5.0
    PyLD==2.0.3
    
    0 回复  |  直到 5 年前
        1
  •  1
  •   Anatoly Scherbakov    5 年前

    看来适合这项工作的工具是 @included @graph . 看到了吗 the JSON-LD 1.1 spec . 这对我有用。

    ( P、 美国。 在使用RDFLib之前,我必须将文档展平;看到了吗 the GitHub issue .)