Exemplo n.º 1
0
def iter_proxies(**kw):
    document = model.get(Document.SCHEMA)
    includes = ['schema', 'properties']
    for data in iter_entities(includes=includes, **kw):
        schema = model.get(data.get('schema'))
        if schema is None:
            continue
        if 'properties' not in data and schema.is_a(document):
            data.update(Document.doc_data_to_schema(data))
        yield model.get_proxy(data)
Exemplo n.º 2
0
def export_entity(entity, collection_uri):
    g = Graph()
    uri = registry.entity.rdf(entity.get('id'))
    g.add((uri, DCTERMS.isPartOf, collection_uri))
    g.add((collection_uri, DCTERMS.hasPart, uri))

    if 'properties' not in entity:
        entity.update(Document.doc_data_to_schema(entity))
    schema = model.get(entity.get('schema'))
    for schema_ in schema.schemata:
        g.add((uri, RDF.type, schema_.uri))

    properties = entity.get('properties', {})
    for name, prop in schema.properties.items():
        for value in ensure_list(properties.get(name)):
            obj = prop.type.rdf(value)
            g.add((uri, prop.uri, obj))

    if entity.get('name'):
        g.add((uri, SKOS.prefLabel, Literal(entity.get('name'))))
    return g