Skip to content

Commit

Permalink
Merge pull request #126 from acdh-oeaw/get-tei-refs
Browse files Browse the repository at this point in the history
New management command to get unique TEI refs
  • Loading branch information
gythaogg authored Sep 12, 2024
2 parents 4cb835a + 9e8d8dd commit 6a290e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions apis_ontology/management/commands/get_tei_refs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.core.management.base import BaseCommand
from apis_ontology.models import TibScholRelationMixin
from tqdm.auto import tqdm
import re
from pprint import pprint


class Command(BaseCommand):
help = "Get a list of TEI Refs in use in APIS"

def handle(self, *args, **options):
def get_tei_id(xml_id):
true_id = xml_id.replace('"', "").replace("xml:id=", "").strip().rstrip(".")
return true_id

def get_all_tei_ids(value):
lines = value.split("\n")
tei_ids = []
for l in lines:
words = l.split()
for w in words:
if w.startswith("xml:id=") or bool(re.search(r"\bex\d\w*", w)):
tei_ids.append(get_tei_id(w))
return tei_ids

models = TibScholRelationMixin.__subclasses__()
unique_refs = []
for m in tqdm(models):
if not hasattr(m, "tei_refs"):
break
for obj in m.objects.all():
if obj.tei_refs:
unique_refs.extend(get_all_tei_ids(obj.tei_refs))

unique_refs = set(list(unique_refs))
pprint(unique_refs)

self.stdout.write(self.style.SUCCESS("Done."))
2 changes: 1 addition & 1 deletion apis_ontology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def render_zotero_refs(self, record):

def render_tei_refs(self, value):
def linkify_excerpt_id(xml_id):
true_id = xml_id.replace('"', "").replace("xml:id=", "").strip()
true_id = xml_id.replace('"', "").replace("xml:id=", "").strip().rstrip(".")
return f"""<a href="#" onclick="showPopup('{true_id}'); return false;">
{true_id}
</a>"""
Expand Down

0 comments on commit 6a290e2

Please sign in to comment.