Skip to content

Commit

Permalink
refactor!: drop EntityToProsopogrAPhI API endpoint
Browse files Browse the repository at this point in the history
This was a custom API endpoint which was aligned with the default
ontology of legacy APIS
  • Loading branch information
b1rger committed Dec 18, 2023
1 parent 7c3edd8 commit 0448fec
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 171 deletions.
169 changes: 0 additions & 169 deletions apis_core/apis_entities/api_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,172 +148,3 @@ class EntityToCIDOCNQUADS(EntityToCIDOC):
class EntityToCIDOCTURTLE(EntityToCIDOC):

format = "rdf+turtle"


class EntityToProsopogrAPhI(renderers.BaseRenderer):

media_type = "text/json+prosop"
format = "json+prosop"

def render(self, data, media_type=None, renderer_context=None):
factoids = []
fact_settings = getattr(settings, "PROSOPOGRAPHI_API", None)
stmt_temp = "Stmt{}_{}"
f = {"@id": "apis_{}_{}".format(data["entity_type"].lower(), data["id"])}
f[data["entity_type"].lower()] = {"@id": str(data["id"])}
f["source"] = {
"@id": PROJECT_METADATA["title"],
"label": "{} export".format(PROJECT_METADATA["title"]),
}
f["createdBy"] = "{} export".format(PROJECT_METADATA["title"])
f["createdWhen"] = timezone.now()
stmt_count = 1
stmts = []
f[data["entity_type"].lower()]["uris"] = []
for u in data["uris"]:
f[data["entity_type"].lower()]["uris"].append(u["uri"])
if data["entity_type"].lower() == "person":
s = {
"@id": stmt_temp.format(data["id"], stmt_count),
"name": "{}, {}".format(data["name"], data["first_name"]),
}
stmts.append(s)
stmt_count += 1
if "end_date" in data.keys():
if data["end_date"] is not None and data["end_date"] != "":
s = {
"@id": stmt_temp.format(data["id"], stmt_count),
"date": {
"sortdate": data["end_date"],
"label": data["end_date_written"],
},
"role": {"label": "stirbt"},
}
stmts.append(s)
stmt_count += 1
if "start_date" in data.keys():
if data["start_date"] is not None and data["start_date"] != "":
s = {
"@id": stmt_temp.format(data["id"], stmt_count),
"date": {
"sortdate": data["start_date"],
"label": data["start_date_written"],
},
"role": {"label": "geboren"},
}
stmts.append(s)
stmt_count += 1
if "gender" in data.keys():
if data["gender"] is not None and data["gender"] != "":
s = {
"@id": stmt_temp.format(data["id"], stmt_count),
"statmentType": [{"label": data["gender"]}],
"role": {"uri": "bio-crm:gender", "label": "gender"},
}
stmts.append(s)
stmt_count += 1
if "profession" in data.keys():
if len(data["profession"]) > 0:
s = {
"@id": stmt_temp.format(data["id"], stmt_count),
"role": {"label": "profession"},
"statementType": [],
}
for p in data["profession"]:
s2 = {
"uri": "apis_profession_type:{}".format(p["id"]),
"label": p["label"],
}
s["statementType"].append(s2)
stmts.append(s)
stmt_count += 1
f["statements"] = stmts
factoids.append(f)
facts = []
facts_ind = {}
if "relations" in data.keys():
for ent in data["relations"].keys():
for rel_1 in data["relations"][ent]:
s = {
"@id": "Stmt{}_rel_{}".format(data["id"], rel_1["id"]),
"role": {
"label": rel_1["relation_type"]["label"],
"url": rel_1["relation_type"]["url"],
},
}
if "start_date" in rel_1.keys():
if rel_1["start_date"] != "":
s["date"] = {
"sortdate": rel_1["start_date"],
"label": rel_1["start_date_written"],
}
if rel_1["end_date_written"] != "":
s["date"]["label"] += "-{}".format(
rel_1["end_date_written"]
)
ext_stc = False
t1 = {
"uri": "{}/api2/entity/{}".format(
base_uri, rel_1["target"]["id"]
),
"label": rel_1["target"]["name"],
}
if fact_settings is not None:
if ent in fact_settings.keys():
if (
rel_1["relation_type"]["label"]
in fact_settings[ent].keys()
):
s[
fact_settings[ent][rel_1["relation_type"]["label"]]
] = t1
ext_stc = True
if not ext_stc:
s["statementType"] = [t1]
try:
if len(rel_1["annotation"]) > 0:
s["statementContent"] = rel_1["annotation"][0]["text"]
except TypeError:
pass
# stct = {
# "@id": "Annotation_{}".format(rel_1["annotation"][0]["id"]),
# "label": rel_1["annotation"][0]["text"]
# }
# if "statementContent" in s.keys():
# s["statementContent"].append(stct)
# else:
# s["statementContent"] = [stct,]
if len(rel_1["revisions"]) > 0:
user_1 = rel_1["revisions"][0]["user_created"]
date_1 = rel_1["revisions"][0]["date_created"].strftime(
"%Y-%m-%d"
)
rev_id = rel_1["revisions"][0]["id"]
if "{}_{}".format(user_1, date_1) not in facts_ind.keys():
facts_ind["{}_{}".format(user_1, date_1)] = len(factoids)
s3 = {
"person": factoids[0]["person"],
"@id": "{}_{}".format(factoids[0]["@id"], len(stmts)),
"source": {
"@id": "APIS",
"label": "APIS highlighter annotations rev. {}".format(
rev_id
),
},
"createdBy": user_1,
"createdWhen": date_1,
"statements": [s],
}
factoids.append(s3)
else:
factoids[facts_ind["{}_{}".format(user_1, date_1)]][
"statements"
].append(s)
factoids[facts_ind["{}_{}".format(user_1, date_1)]][
"source"
]["label"] += " / {}".format(rev_id)
else:
factoids[0]["statements"].append(s)
return json.dumps(
{"factoids": factoids}, sort_keys=True, indent=1, cls=DjangoJSONEncoder
)
2 changes: 0 additions & 2 deletions apis_core/apis_entities/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .api_renderers import (
EntityToTEI,
EntityToCIDOCXML,
EntityToProsopogrAPhI,
EntityToCIDOCN3,
EntityToCIDOCNQUADS,
EntityToCIDOCTURTLE,
Expand All @@ -42,7 +41,6 @@ class GetEntityGeneric(GenericAPIView):
renderer_classes = tuple(api_settings.DEFAULT_RENDERER_CLASSES) + (
EntityToTEI,
EntityToCIDOCXML,
EntityToProsopogrAPhI,
EntityToCIDOCN3,
EntityToCIDOCNQUADS,
EntityToCIDOCTURTLE,
Expand Down

0 comments on commit 0448fec

Please sign in to comment.