跳转到主要内容

cubicweb的jsonld视图

项目描述

摘要

jsonld为cubicweb提供视图

视图

此立方体提供了两种不同实现的jsonld视图。

jsonld for CWEType

对于CWEType实体的jsonld视图可通过显式方式或通过BASE_URL/.jsonld URL访问。它使用jsonld规范提供模式信息。

假设你有以下模式声明

class Person(EntityType):
    name = String()
    age = Int()
    birthdate = Date()

相应的jsonld输出将是

{
    "@context": {
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "creation_date": {
          "@id": "https://my-app.org/CWRType/creation_date",
          "@type": "xsd:dateTime"
        },
        "modification_date": {
          "@id": "https://my-app.org/CWRType/modification_date",
          "@type": "xsd:dateTime"
        },
        "cwuri": {
          "@id": "https://my-app.org/CWRType/cwuri",
          "@type": "@id"
        },
        "eid": {
          "@id": "https://my-app.org/CWRType/eid",
          "@type": "xsd:integer"
        },
        "name": {
          "@id": "https://my-app.org/CWAttribute/278",
          "@type": "xsd:string"
        },
        "age": {
          "@id": "https://my-app.org/CWAttribute/281",
          "@type": "xsd:string"
        },
        "birthdate": {
          "@id": "https://my-app.org/CWAttribute/301",
          "@type": "xsd:date"
        }
    }
}

jsonld for any rset

此视图与标准jsonexport视图有些相似,主要有两个不同点

  • 它提供结果集元数据与实际数据一起,并尽可能接近sparql-results-json格式的总体形状,

  • 每个单元格都作为一个“jsonld”对象公开。实体公开所有属性和dc属性,“最终”值公开其类型和值。

考虑RQL查询Any P,N LIMIT 2 WHERE P is Person, P name N,jsonld输出将如下所示

{
    "@context": {
        "cw": "http://ns.cubicweb.org/cubicweb/0.0/",
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "dcterms": "http://purl.org/dc/terms/",
        "myapp": "https://my-app.org/CWEType/"
    },
    "cw:head": {
        "rql": "Any P,N LIMIT 2 WHERE P is Person, P name N",
        "vars": ["P", "N"],
        "limit": 2
    },
    "cw:results": [
        [{
            "@context": "https://my-app.org/Person.jsonld",
            "@type": "myapp:Person",
            "cwuri": "https://my-app.org/1234",
            "name": "John",
            "age": 42,
            "birthdate": "2013/01/01",
            "creation_date": "2009/08/07 15:20:30",
            "modification_date": "2009/08/05 11:12:24",
            "eid": 1234,
            "dcterms:title": "the result of p.dc_title() on John",
            "dcterms:description": null
        },
        {
            "@type": "xsd:string",
            "@value": "John"
        }],
       [{
            "@context": "https://my-app.org/Person.jsonld",
            "@type": "myapp:Person",
            "cwuri": "https://my-app.org/4321",
            "name": "Mary",
            "age": 40,
            "birthdate": "2015/02/02",
            "creation_date": "2014/01/02 11:30:20",
            "modification_date": "2015/01/05 12:24:11",
            "eid": 4321,
            "dcterms:title": "the result of p.dc_title() on Mary",
            "dcterms:description": null
       },
        {
            "@type": "xsd:string",
            "@value": "Mary"
        }]
    ]
}

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分布

cubicweb-jsonld-0.1.0.tar.gz (9.6 kB 查看哈希值)

上传时间 源码

支持