MCPcopy Create free account
hub / github.com/alephdata/aleph / export_entity

Function export_entity

contrib/play/tripler.py:19–62  ·  view source on GitHub ↗
(ctx, entity)

Source from the content-addressed store, hash-verified

17
18
19def export_entity(ctx, entity):
20 g = ConjunctiveGraph()
21 if "Document" in entity["schemata"]:
22 uri = URIRef("%s/documents/%s" % (HOST, entity["id"]))
23 if entity.get("title"):
24 g.add((uri, DC.title, Literal(entity.get("title")), ctx))
25 g.add((uri, ALEPH.fileName, Literal(entity.get("file_name")), ctx))
26 g.add((uri, ALEPH.mimeType, Literal(entity.get("mime_type")), ctx))
27 # TODO DC dates, author etc.
28 # parent
29 else:
30 uri = URIRef("%s/entities/%s" % (HOST, entity["id"]))
31 if entity.get("name"):
32 g.add((uri, SKOS.prefLabel, Literal(entity.get("name")), ctx))
33 for name in entity.get("names", []):
34 g.add((uri, RDFS.label, Literal(name), ctx))
35
36 for schema in entity["schemata"]:
37 g.add((uri, RDF.type, FTM[schema], ctx))
38
39 for country in entity.get("countries", []):
40 if len(country) != 2:
41 continue
42 country = URIRef("iso-3166-1:%s" % country)
43 g.add((uri, ALEPH.country, country, ctx))
44
45 for phone in entity.get("phones", []):
46 phone = URIRef("tel:%s" % phone)
47 g.add((uri, ALEPH.phone, phone, ctx))
48
49 for email in entity.get("emails", []):
50 email = URIRef("mailto:%s" % email)
51 g.add((uri, ALEPH.email, email, ctx))
52
53 schema = model[entity["schema"]]
54 properties = entity.get("properties", {})
55 for name, values in properties.items():
56 prop = schema.get(name)
57 pred = "%s#%s" % (prop.schema.name, name)
58 pred = FTM[pred]
59 for value in ensure_list(values):
60 g.add((uri, pred, Literal(value), ctx))
61
62 print(g.serialize(format="nquads"))
63
64
65def export_collection(collection):

Callers 1

export_collectionFunction · 0.85

Calls 4

addMethod · 0.80
serializeMethod · 0.80
getMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected