eldpy 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. eldpy-0.0.6/PKG-INFO +70 -0
  2. eldpy-0.0.6/README.md +48 -0
  3. eldpy-0.0.6/eldpy/annotation.py +74 -0
  4. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/archive.py +233 -58
  5. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/bulk.py +32 -12
  6. eldpy-0.0.6/eldpy/cldf2gb4e.py +156 -0
  7. eldpy-0.0.6/eldpy/colexify.py +142 -0
  8. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/collection.py +26 -19
  9. eldpy-0.0.4/eldpy/lod.py → eldpy-0.0.6/eldpy/constants.py +40 -116
  10. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/delaman.py +39 -0
  11. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/download.py +71 -29
  12. eldpy-0.0.6/eldpy/elanfile.py +971 -0
  13. eldpy-0.0.6/eldpy/lod.py +104 -0
  14. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/transitiveclosure.py +38 -5
  15. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/wikidatagraph.py +6 -3
  16. eldpy-0.0.6/executables/analyze_eafs.py +92 -0
  17. eldpy-0.0.6/executables/annotation.py +1 -0
  18. eldpy-0.0.6/executables/constants.py +1 -0
  19. eldpy-0.0.6/executables/elanfile.py +1 -0
  20. eldpy-0.0.6/pyproject.toml +62 -0
  21. eldpy-0.0.6/tests/annotation.py +1 -0
  22. eldpy-0.0.6/tests/constants.py +1 -0
  23. eldpy-0.0.6/tests/elanfile.py +1 -0
  24. eldpy-0.0.6/tests/test_elan.py +215 -0
  25. eldpy-0.0.4/PKG-INFO +0 -27
  26. eldpy-0.0.4/README.md +0 -13
  27. eldpy-0.0.4/eldpy/elanfile.py +0 -610
  28. eldpy-0.0.4/eldpy/eldtfidf.py +0 -48
  29. eldpy-0.0.4/eldpy/run.py +0 -12
  30. eldpy-0.0.4/eldpy/wikidata_ids.py +0 -8457
  31. eldpy-0.0.4/eldpy.egg-info/PKG-INFO +0 -27
  32. eldpy-0.0.4/eldpy.egg-info/SOURCES.txt +0 -23
  33. eldpy-0.0.4/eldpy.egg-info/dependency_links.txt +0 -1
  34. eldpy-0.0.4/eldpy.egg-info/requires.txt +0 -8
  35. eldpy-0.0.4/eldpy.egg-info/top_level.txt +0 -1
  36. eldpy-0.0.4/setup.cfg +0 -4
  37. eldpy-0.0.4/setup.py +0 -33
  38. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/__init__.py +0 -0
  39. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/paradisecconverter.py +0 -0
  40. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/resolver.py +0 -0
  41. {eldpy-0.0.4 → eldpy-0.0.6}/eldpy/testing.py +0 -0
eldpy-0.0.6/PKG-INFO ADDED
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.1
2
+ Name: eldpy
3
+ Version: 0.0.6
4
+ Summary: A Python package to download and analyze data from endangered language archives
5
+ Project-URL: Homepage, https://github.com/ZAS-QUEST/eldpy
6
+ Project-URL: Bug Tracker, https://github.com/ZAS-QUEST/eldpy/issues
7
+ Author-email: Sebastian Nordhoff <sebastian.nordhoff@glottotopia.de>
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.7
12
+ Requires-Dist: langdetect
13
+ Requires-Dist: lxml
14
+ Requires-Dist: matplotlib
15
+ Requires-Dist: pycryptodome
16
+ Requires-Dist: random2
17
+ Requires-Dist: rdflib
18
+ Requires-Dist: requests
19
+ Requires-Dist: wptools
20
+ Provides-Extra: dev
21
+ Description-Content-Type: text/markdown
22
+
23
+ # LangSci
24
+
25
+ This package provides tools for interfacing with endangered language archives.
26
+
27
+ For the time being, only the download functionality is robust enough for general use.
28
+
29
+ The package contains script for the analysis of ELAN files. These analyses are quantitative (duration, tiers, tokens) as well as qualitative (vernacular language, tranlations, glosses, semantic domains).
30
+
31
+ The analyses are cached in JSON format and can be exported to RDF.
32
+
33
+ Sample usage:
34
+ - download all ELAN files from the AILLA archives:
35
+ ```
36
+ from eldpy import download
37
+ download.bulk_download(archive='AILLA', filetype=1, username='janedoe', password='mypassword')
38
+ ```
39
+ - analyze all downloaded ELAN files
40
+ ```
41
+ from eldpy.bulk import *
42
+ bulk_populate(cache=False)
43
+ ```
44
+ - cache for future usage: as above and add
45
+ ```
46
+ bulk_cache()
47
+ ```
48
+ - read cached information
49
+ ```
50
+ from eldpy.bulk import *
51
+ bulk_populate(cache=True)
52
+ ```
53
+ - compute tokens and durations
54
+ ```
55
+ from eldpy.bulk import *
56
+ bulk_populate()
57
+ bulk_statistics()
58
+ ```
59
+ - analyze ELAN tier hierarchies
60
+ ```
61
+ from eldpy.bulk import *
62
+ bulk_populate()
63
+ bulk_fingerprints()
64
+ ```
65
+ -export as rdf
66
+ ```
67
+ from eldpy.bulk import *
68
+ bulk_populate()
69
+ bulk_rdf()
70
+ ```
eldpy-0.0.6/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # LangSci
2
+
3
+ This package provides tools for interfacing with endangered language archives.
4
+
5
+ For the time being, only the download functionality is robust enough for general use.
6
+
7
+ The package contains script for the analysis of ELAN files. These analyses are quantitative (duration, tiers, tokens) as well as qualitative (vernacular language, tranlations, glosses, semantic domains).
8
+
9
+ The analyses are cached in JSON format and can be exported to RDF.
10
+
11
+ Sample usage:
12
+ - download all ELAN files from the AILLA archives:
13
+ ```
14
+ from eldpy import download
15
+ download.bulk_download(archive='AILLA', filetype=1, username='janedoe', password='mypassword')
16
+ ```
17
+ - analyze all downloaded ELAN files
18
+ ```
19
+ from eldpy.bulk import *
20
+ bulk_populate(cache=False)
21
+ ```
22
+ - cache for future usage: as above and add
23
+ ```
24
+ bulk_cache()
25
+ ```
26
+ - read cached information
27
+ ```
28
+ from eldpy.bulk import *
29
+ bulk_populate(cache=True)
30
+ ```
31
+ - compute tokens and durations
32
+ ```
33
+ from eldpy.bulk import *
34
+ bulk_populate()
35
+ bulk_statistics()
36
+ ```
37
+ - analyze ELAN tier hierarchies
38
+ ```
39
+ from eldpy.bulk import *
40
+ bulk_populate()
41
+ bulk_fingerprints()
42
+ ```
43
+ -export as rdf
44
+ ```
45
+ from eldpy.bulk import *
46
+ bulk_populate()
47
+ bulk_rdf()
48
+ ```
@@ -0,0 +1,74 @@
1
+
2
+ class Annotation:
3
+ def __init__(self, element, timeslots, ref_annotations, alignable_annotations):
4
+ """ """
5
+
6
+ if element is None:
7
+ raise ValueError("Annotation is None")
8
+ if element.tag not in ["ANNOTATION", "ALIGNABLE_ANNOTATION"]:
9
+ logger.warning(f"{element.tag} is not an <(ALIGNABLE_)ANNOTATION> element")
10
+ raise ValueError(
11
+ f"{element.tag} is not an <(ALIGNABLE_)ANNOTATION> element"
12
+ )
13
+ self.text = ""
14
+ self.starttime = 0
15
+ self.endtime = 0
16
+ self.ID = None
17
+ self.parentID = None
18
+ self.previous_annotation_ID = None
19
+ # ELAN stores the annotation information in two different types of elements.
20
+ # One is ANNOTATION, the other one is ALIGNABLE_ANNOTATION. We do not know which
21
+ # kind is submitted to the constructor. If it is ANNOTATION, we have to drill
22
+ # down the DOM to find ALIGNABLE_ANNOTATION
23
+ if element.tag == "ANNOTATION":
24
+ alignable_annotation = element.find(".//ALIGNABLE_ANNOTATION")
25
+ else:
26
+ alignable_annotation = element
27
+ annotation_value = element.find(".//ANNOTATION_VALUE")
28
+ ref_annotation = element.find(".//REF_ANNOTATION")
29
+ try:
30
+ self.text = annotation_value.text
31
+ except AttributeError:
32
+ pass
33
+ if alignable_annotation is None: # not time aligned
34
+ if ref_annotation is None:
35
+ print("Annotation without ID in", self.text)
36
+ print(element[0].text)
37
+ raise ValueError
38
+ self.ID = None
39
+ self.parentID = None
40
+ else:
41
+ self.ID = ref_annotation.attrib["ANNOTATION_ID"]
42
+ self.parentID = ref_annotation.attrib["ANNOTATION_REF"]
43
+ self.previous_annotation_ID = ref_annotation.attrib.get("PREVIOUS_ANNOTATION")
44
+ try:
45
+ parentAnnoID = ref_annotations[self.parentID]
46
+ parentAnno = alignable_annotations[parentAnnoID]
47
+ startslot = parentAnno[0]
48
+ endslot = parentAnno[1]
49
+ self.starttime = timeslots[startslot]
50
+ self.endtime = timeslots[endslot]
51
+ except KeyError:
52
+ pass
53
+ else: # time aligned
54
+ self.ID = alignable_annotation.attrib["ANNOTATION_ID"]
55
+ self.parentID = None
56
+ try:
57
+ self.starttime = int(
58
+ timeslots[alignable_annotation.attrib["TIME_SLOT_REF1"]]
59
+ )
60
+ self.endtime = int(
61
+ timeslots[alignable_annotation.attrib["TIME_SLOT_REF2"]]
62
+ )
63
+ except KeyError:
64
+ pass
65
+
66
+ def get_duration(self,include_void_annotations=True):
67
+ """
68
+ compute the duration by subtracting start times from end time
69
+ """
70
+ if include_void_annotations or self.text:
71
+ return int(self.endtime) - int(self.starttime)
72
+ else:
73
+ return 0
74
+
@@ -15,7 +15,7 @@ from lxml.html.soupparser import fromstring
15
15
  # from random import shuffle
16
16
  import matplotlib.pyplot as plt
17
17
  from matplotlib import cm
18
- import squarify
18
+ # import squarify
19
19
  from rdflib import Namespace, Graph, Literal, RDF, RDFS # , URIRef, BNode
20
20
 
21
21
  from .collection import Collection
@@ -140,19 +140,99 @@ class Archive:
140
140
  with open("cache/links/anla.json", "w") as json_out:
141
141
  json_out.write(json.dumps(cached_links, sort_keys=True, indent=4))
142
142
  else: # if not cache
143
- if self.name in ["PARADISEC"]: # to be extended
144
- paradisecpaths = {}
143
+ if self.name in ["PARADISEC","PARADISEC2"]: # to be extended
145
144
  collections = glob.glob("./%s/*" % self.name.lower())
145
+ print(collections)
146
146
  for collection in collections:
147
147
  collectionbasename = collection.split("/")[-1]
148
- print(collectionbasename)
149
- paradisecpaths[collectionbasename] = defaultdict(list)
148
+ #print(collectionbasename)
149
+ self.collections[collectionbasename] = Collection(
150
+ collectionbasename,
151
+ self.landingpage_template % collectionbasename,
152
+ archive=self.name.lower(),
153
+ urlprefix=self.collectionprefix,
154
+ url_template=self.collection_url_template,
155
+ )
156
+ paradisecpaths = defaultdict(list)
150
157
  filenames = glob.glob("%s/*eaf" % collection)
151
158
  for filename in filenames:
152
159
  basename = filename.split("/")[-1]
153
160
  collectionthrowaway, bundle, recordingthrowaway = basename.split("-")
154
- paradisecpaths[collectionbasename][bundle].append(basename)
155
- self.collections[collection].elanpaths = paradisecpaths
161
+ #print(collectionbasename, bundle, basename)
162
+ paradisecpaths[bundle].append(basename)
163
+ self.collections[collectionbasename].elanpaths = paradisecpaths
164
+ if self.name in ["TLA","TLA2"]: # to be extended
165
+ collections = glob.glob("./%s/*" % self.name.lower())
166
+ #print(collections)
167
+ for collection in collections:
168
+ collectionbasename = collection.split("/")[-1]
169
+ #print(collectionbasename)
170
+ self.collections[collectionbasename] = Collection(
171
+ collectionbasename,
172
+ self.landingpage_template % collectionbasename,
173
+ archive=self.name.lower(),
174
+ urlprefix=self.collectionprefix,
175
+ url_template=self.collection_url_template,
176
+ )
177
+ filenames = glob.glob("%s/*eaf" % collection)
178
+ tlapaths = defaultdict(list)
179
+ for filename in filenames:
180
+ basename = filename.split("/")[-1]
181
+ bundle = collectionbasename #we treat TLA as having collections with exactly 1 member for the time being.
182
+ #print(collectionbasename, bundle, basename)
183
+ #print(basename, basename)
184
+ tlapaths[bundle].append(basename)
185
+ #pprint.pprint(tlapaths)
186
+ #pprint.pprint(self.collections[collectionbasename].__dict__)
187
+ #print(6)
188
+ self.collections[collectionbasename].elanpaths = tlapaths
189
+ #pprint.pprint(self.collections[collectionbasename].elanpaths)
190
+ if self.name in ["ELAR","ELAR2"]: # to be extended
191
+ collections = glob.glob("./%s/*" % self.name.lower())
192
+ #print(collections)
193
+ for collection in collections:
194
+ collectionbasename = collection.split("/")[-1]
195
+ #print(collectionbasename)
196
+ self.collections[collectionbasename] = Collection(
197
+ collectionbasename,
198
+ self.landingpage_template % collectionbasename,
199
+ archive=self.name.lower(),
200
+ urlprefix=self.collectionprefix,
201
+ url_template=self.collection_url_template,
202
+ )
203
+ filenames = glob.glob("%s/*eaf" % collection)
204
+ tlapaths = defaultdict(list)
205
+ for filename in filenames:
206
+ basename = filename.split("/")[-1]
207
+ bundle = collectionbasename #we treat ELAR as having collections with exactly 1 member for the time being.
208
+ #print(collectionbasename, bundle, basename)
209
+ #print(basename, basename)
210
+ tlapaths[bundle].append(basename)
211
+ #pprint.pprint(tlapaths)
212
+ #pprint.pprint(self.collections[collectionbasename].__dict__)
213
+ #print(6)
214
+ self.collections[collectionbasename].elanpaths = tlapaths
215
+ #pprint.pprint(self.collections[collectionbasename].elanpaths)
216
+ if self.name in ["AILLA","AILLA2"]: # to be extended
217
+ collections = glob.glob("./%s/*" % self.name.lower())
218
+ for collection in collections:
219
+ collectionbasename = collection.split("/")[-1]
220
+ #print(collectionbasename)
221
+ self.collections[collectionbasename] = Collection(
222
+ collectionbasename,
223
+ self.landingpage_template % collectionbasename,
224
+ archive=self.name.lower(),
225
+ urlprefix=self.collectionprefix,
226
+ url_template=self.collection_url_template,
227
+ )
228
+ filenames = glob.glob("%s/*eaf" % collection)
229
+ aillapaths = defaultdict(list)
230
+ for filename in filenames:
231
+ basename = filename.split("/")[-1]
232
+ bundle = collectionbasename
233
+ #print(collectionbasename, bundle, basename)
234
+ aillapaths[bundle].append(basename)
235
+ self.collections[collectionbasename].elanpaths = aillapaths
156
236
 
157
237
  def get_fingerprints(self):
158
238
  """map filenames to fingerprints"""
@@ -300,11 +380,13 @@ class Archive:
300
380
  lod.QUESTRESOLVER[collection],
301
381
  )
302
382
  )
383
+ print(len(g), "metadata triples")
303
384
  lod.write_graph(g, "rdf/%s-metadata.n3" % self.name)
304
385
 
305
386
  def get_eaf_hash(self, eafname):
306
387
  eafbasename = eafname.split("/")[-1]
307
- hashed_eaf = hash(eafbasename)
388
+ hashed_eaf = str(hash(eafbasename))[-7:]
389
+
308
390
  return hashed_eaf
309
391
 
310
392
  def write_transcriptions_rdf(self):
@@ -347,6 +429,7 @@ class Archive:
347
429
  lod.QUESTRESOLVER[tier_id],
348
430
  )
349
431
  )
432
+ print(len(g), "transcription triples")
350
433
  lod.write_graph(g, "rdf/%s-transcriptions.n3" % self.name)
351
434
 
352
435
  def write_translations_rdf(self):
@@ -386,13 +469,27 @@ class Archive:
386
469
  lod.ARCHIVE_NAMESPACES[self.name.lower()][eaf_id],
387
470
  )
388
471
  )
472
+ print(len(g), "translation triples")
389
473
  lod.write_graph(g, "rdf/%s-translations.n3" % self.name)
390
474
 
391
475
  def write_glosses_rdf(self):
392
- ID_template = "%s-%s-%s"
393
- gloss_template = "%s-%s-%s-%s"
476
+ #https://github.com/acoli-repo/ligt/blob/master/samples/nordhoff-1.ttl
477
+ example_ID_template = "%s-%s-%s_u"
478
+ word_tier_ID_template = "%s-%s-%s_wt"
479
+ morph_tier_ID_template = "%s-%s-%s_mt"
480
+ word_template = "%s-%s-%s-%s_w"
481
+ morph_ID_template = "%s-%s-%s-%s_m"
482
+ gloss_template = "%s-%s-%s-%s_g"
394
483
  eaf_template = "%s-%s"
395
484
  g = lod.create_graph()
485
+ g.add((lod.QUEST.morph2,#TODO needs better label
486
+ lod.RDFS.subPropertyOf,
487
+ lod.LIGT.annotation
488
+ ))
489
+ g.add((lod.QUEST.gloss2, #TODO needs better label
490
+ lod.RDFS.subPropertyOf,
491
+ lod.LIGT.annotation
492
+ ))
396
493
  for collection in self.collections:
397
494
  for eafname in self.collections[collection].glosses:
398
495
  hashed_eaf = self.get_eaf_hash(eafname)
@@ -401,53 +498,91 @@ class Archive:
401
498
  for tierID in self.collections[collection].glosses[eafname][tiertype]:
402
499
  for dictionary in self.collections[collection].glosses[eafname][tiertype][tierID]:
403
500
  for sentenceID in dictionary:
404
- sentence_lod_ID = ID_template % (collection, hashed_eaf, sentenceID)
405
- g.add((lod.QUESTRESOLVER[sentence_lod_ID],
501
+ example_block_ID = example_ID_template % (collection, hashed_eaf, sentenceID)
502
+ sentence_word_tier_lod_ID = word_tier_ID_template % (collection, hashed_eaf, sentenceID)
503
+ sentence_morph_tier_lod_ID = word_tier_ID_template % (collection, hashed_eaf, sentenceID)
504
+ wordstring = " ".join(['' if t[0] is None else t[0] for t in dictionary[sentenceID]])
505
+ glossstring = " ".join(['' if t[1] is None else t[1] for t in dictionary[sentenceID]])
506
+ example_block_nif_label = wordstring
507
+ words_nif_label = wordstring
508
+ vernacular_language_id = "und"
509
+ gloss_language_id = "en-x-lgr"
510
+ g.add((lod.ARCHIVE_NAMESPACES[self.name.lower()][eaf_id],
511
+ lod.LIGT.hasTier,
512
+ lod.QUESTRESOLVER[example_block_ID],
513
+ ))
514
+ #example block (=utterance in LIGT lingo)
515
+ g.add((lod.QUESTRESOLVER[example_block_ID],
406
516
  # TODO better use archive specific resolvers
407
517
  RDF.type,
408
- # lod.QUEST.Transcripton_tier
518
+ lod.LIGT.InterlinearText
519
+ ))
520
+ g.add((lod.QUESTRESOLVER[example_block_ID],
521
+ RDF.type,
522
+ lod.LIGT.Utterance
523
+ ))
524
+ g.add((lod.QUESTRESOLVER[example_block_ID],
525
+ lod.NIF.anchorOf,
526
+ Literal(example_block_nif_label, lang=vernacular_language_id),
527
+ ))
528
+ g.add((lod.QUESTRESOLVER[example_block_ID],
529
+ lod.LIGT.hasTier,
530
+ lod.QUESTRESOLVER[sentence_word_tier_lod_ID],
531
+ ))
532
+ g.add((lod.QUESTRESOLVER[example_block_ID],
533
+ lod.LIGT.hasTier,
534
+ lod.QUESTRESOLVER[sentence_morph_tier_lod_ID],
535
+ ))
536
+ #words
537
+ g.add((lod.QUESTRESOLVER[sentence_word_tier_lod_ID],
538
+ RDF.type,
409
539
  lod.LIGT.WordTier,
410
540
  ))
411
- # wordstring = " ".join([t[0] for t in dictionary[sentenceID]])
412
- # glossstring = " ".join([t[1] for t in dictionary[sentenceID]])
413
- g.add((lod.ARCHIVE_NAMESPACES[self.name.lower()][eaf_id],
414
- lod.LIGT.hasTier,
415
- lod.QUESTRESOLVER[sentence_lod_ID],
416
- ))
417
- vernaculars = [t[0] if t[0] else "" for t in dictionary[sentenceID]]
541
+ g.add((lod.QUESTRESOLVER[sentence_word_tier_lod_ID],
542
+ lod.NIF.anchorOf,
543
+ Literal(example_block_ID, lang=vernacular_language_id),
544
+ ))
545
+ #morphs
546
+ g.add((lod.QUESTRESOLVER[sentence_morph_tier_lod_ID],
547
+ RDF.type,
548
+ lod.LIGT.MorphTier,
549
+ ))
550
+ g.add((lod.QUESTRESOLVER[sentence_morph_tier_lod_ID],
551
+ lod.NIF.anchorOf,
552
+ Literal(example_block_ID, lang=vernacular_language_id),
553
+ ))
554
+ #subelements of word, morph and gloss tier
555
+ #TODO unclear whether we need word tier
556
+ morphs = [t[0] if t[0] else "" for t in dictionary[sentenceID]]
418
557
  glosses = [t[1] if t[1] else "" for t in dictionary[sentenceID]]
419
- for i, gloss in enumerate(glosses):
420
- vernacular = vernaculars[i]
558
+ for i in range(len(morphs)):
559
+ morph = morphs[i]
560
+ morph_id = morph_ID_template % (
561
+ collection,
562
+ hashed_eaf,
563
+ sentenceID,
564
+ i,
565
+ )
566
+ gloss = glosses[i]
421
567
  try:
422
568
  gloss = gloss.strip()
423
569
  except TypeError:
424
570
  gloss = ""
425
- gloss_id = urllib.parse.quote(
426
- gloss_template % (collection, hashed_eaf, sentenceID, i)
427
- )
428
- g.add((lod.QUESTRESOLVER[gloss_id],
429
- RDF.type,
430
- # lod.QUEST.gloss
431
- lod.LIGT.Word,
432
- ))
433
- g.add((lod.QUESTRESOLVER[gloss_id],
434
- RDFS.label,
435
- Literal(gloss, lang="qqq"),
436
- # we use qqq since glossed text is not natural language
437
- ))
438
- g.add((lod.QUESTRESOLVER[gloss_id],
439
- RDFS.label,
440
- Literal(vernacular, lang="und"),
441
- # we use "und" until we can retrieve the proper metadata
442
- ))
443
- g.add((lod.QUESTRESOLVER[sentence_lod_ID],
444
- lod.LIGT.hasWord,
445
- lod.QUESTRESOLVER[gloss_id],
446
- ))
571
+ #add items to tier
572
+ g.add((lod.QUESTRESOLVER[sentence_morph_tier_lod_ID],
573
+ lod.LIGT.item,
574
+ lod.QUESTRESOLVER[morph_id]
575
+ ))
576
+ #anchor in superstring about items
577
+ g.add((lod.QUESTRESOLVER[morph_id],
578
+ lod.NIF.anchorOf,
579
+ lod.QUESTRESOLVER[sentence_word_tier_lod_ID] #TODO this should probably sentence_word_id, but we have no notion of "word" right now, hence resorting to a larger substring
580
+ ))
581
+ #forward link to create linked list
447
582
  try:
448
- nextgloss = glosses[i + 1]
449
- nextgloss_id = urllib.parse.quote(
450
- gloss_template
583
+ nextmorph = morphs[i + 1]
584
+ nextmorph_id = urllib.parse.quote(
585
+ morph_ID_template
451
586
  % (
452
587
  collection,
453
588
  hashed_eaf,
@@ -455,16 +590,24 @@ class Archive:
455
590
  i + 1,
456
591
  )
457
592
  )
458
- g.add((lod.QUESTRESOLVER[gloss_id],
593
+ g.add((lod.QUESTRESOLVER[morph_id],
459
594
  lod.LIGT.nextWord,
460
- lod.QUESTRESOLVER[nextgloss_id],
595
+ lod.QUESTRESOLVER[nextmorph_id]
461
596
  ))
462
597
  except IndexError: # we have reached the end of the list
463
- g.add((lod.QUESTRESOLVER[gloss_id],
598
+ g.add((lod.QUESTRESOLVER[morph_id],
464
599
  lod.LIGT.nextWord,
465
600
  lod.RDF.nil,
466
601
  ))
467
-
602
+ #give labels for morphs
603
+ g.add((lod.QUESTRESOLVER[morph_id],
604
+ lod.QUEST.morph2, #TODO probably use not "morph2" here
605
+ Literal(morph, lang=vernacular_language_id),
606
+ ))
607
+ g.add((lod.QUESTRESOLVER[morph_id],
608
+ lod.QUEST.gloss2, #TODO probably use not "gloss2" here
609
+ Literal(gloss, lang=gloss_language_id)
610
+ ))
468
611
  for subgloss in re.split("[-=.:]", gloss):
469
612
  subgloss = (
470
613
  subgloss.replace("1", "")
@@ -472,10 +615,42 @@ class Archive:
472
615
  .replace("3", "")
473
616
  )
474
617
  if subgloss in lod.LGRLIST:
475
- g.add((lod.QUESTRESOLVER[gloss_id],
618
+ g.add((lod.QUESTRESOLVER[morph_id],
476
619
  lod.QUEST.has_lgr_value,
477
- lod.LGR[subgloss],
478
- ))
620
+ lod.LGR[subgloss]
621
+ ))
622
+
623
+
624
+ #TODO not sure in how far the specific ligt modeling from 2019 is needed anymore
625
+ #for i, gloss in enumerate(glosses):
626
+ #vernacular = vernaculars[i]
627
+ #try:
628
+ #gloss = gloss.strip()
629
+ #except TypeError:
630
+ #gloss = ""
631
+ #gloss_id = urllib.parse.quote(
632
+ #gloss_template % (collection, hashed_eaf, sentenceID, i)
633
+ #)
634
+ #g.add((lod.QUESTRESOLVER[gloss_id],
635
+ #RDF.type,
636
+ ## lod.QUEST.gloss
637
+ #lod.LIGT.Word,
638
+ #))
639
+ #g.add((lod.QUESTRESOLVER[gloss_id],
640
+ #lod.FLEX.gls,
641
+ #Literal(gloss, lang="eng"),
642
+ ## we use qqq since glossed text is not natural language
643
+ #))
644
+ #g.add((lod.QUESTRESOLVER[gloss_id],
645
+ #lod.FLEX.txt,
646
+ #Literal(vernacular, lang="und"),
647
+ ## we use "und" until we can retrieve the proper metadata
648
+ #))
649
+ #g.add((lod.QUESTRESOLVER[sentence_lod_ID],
650
+ #lod.LIGT.hasWord,
651
+ #lod.QUESTRESOLVER[gloss_id],
652
+ #))
653
+ print(len(g), "gloss triples")
479
654
  lod.write_graph(g, "rdf/%s-glosses.n3" % self.name)
480
655
 
481
656
  def write_entities_rdf(self):
@@ -495,15 +670,15 @@ class Archive:
495
670
  ))
496
671
  for q_value in tier:
497
672
  g.add((
498
- lod.QUESTRESOLVER[tier_id],
499
- # TODO better use archive specific resolvers
500
- lod.DC.topic,
673
+ lod.QUESTRESOLVER[tier_id], # TODO better use archive specific resolvers
674
+ lod.DC.subject,
501
675
  lod.WIKIDATA[q_value],
502
676
  ))
677
+ print(len(g), "entity triples")
503
678
  lod.write_graph(g, "rdf/%s-entities.n3" % self.name)
504
679
 
505
680
  def write_rdf(self):
506
- print("writing rdf")
681
+ print("writing rdf for", self.name)
507
682
  print(" meta")
508
683
  self.write_metadata_rdf()
509
684
  print(" transcriptions")
@@ -2,26 +2,45 @@ import json
2
2
  from .archive import Archive
3
3
  from .delaman import archives
4
4
 
5
- def bulk_populate(archives_to_populate=archives, cache=True):
5
+ def bulk_populate(archives_to_populate=archives, cache=True, exclude=[]):
6
6
  def load_cache(type_):
7
7
  return json.loads(open("cache/%s/%s.json" % (type_, archivename)).read())
8
8
 
9
9
  for archivename in archives_to_populate:
10
10
  print("processing", archivename)
11
11
  archive = archives_to_populate[archivename]
12
+ #print(archive)
12
13
  archive.populate_collections(cache=cache)
13
14
  print("processing data")
14
- transcriptioncache = load_cache('transcriptions')
15
- translationschache = load_cache('translations')
16
- glosseschache = load_cache('glosses')
17
- entitieschache = load_cache('entities')
15
+ transcriptioncache, translationschache, glosseschache, entitieschache = None, None, None, None
16
+ if cache:
17
+ transcriptioncache = load_cache('transcriptions')
18
+ translationschache = load_cache('translations')
19
+ glosseschache = load_cache('glosses')
20
+ entitieschache = load_cache('entities')
18
21
  for c in archive.collections:
22
+ print(c)
19
23
  archive.collections[c].acquire_elans(cache=cache)
20
- archive.collections[c].populate_transcriptions(jsoncache=transcriptioncache)
21
- archive.collections[c].populate_translations(jsoncache=translationschache)
22
- archive.collections[c].populate_glosses(jsoncache=glosseschache)
23
- archive.collections[c].populate_entities(jsoncache=entitieschache)
24
- archive.get_metadata()
24
+ if 'transcriptions' in exclude:
25
+ print('transcriptions excluded')
26
+ else:
27
+ archive.collections[c].populate_transcriptions(jsoncache=transcriptioncache)
28
+ if 'translations' in exclude:
29
+ print('translations excluded')
30
+ else:
31
+ archive.collections[c].populate_translations(jsoncache=translationschache)
32
+ if 'glosses' in exclude:
33
+ print('glosses excluded')
34
+ else:
35
+ archive.collections[c].populate_glosses(jsoncache=glosseschache)
36
+ if 'entities' in exclude:
37
+ print('entities excluded')
38
+ else:
39
+ archive.collections[c].populate_entities(jsoncache=entitieschache)
40
+ if 'metadata' in exclude:
41
+ print('metadata excluded')
42
+ else:
43
+ archive.get_metadata()
25
44
 
26
45
 
27
46
  def bulk_cache(cachearchives=archives, exclude=[]):
@@ -36,11 +55,12 @@ def bulk_cache(cachearchives=archives, exclude=[]):
36
55
  out.write(json.dumps(d_for_json, indent=4, sort_keys=True))
37
56
 
38
57
  print("caching json")
39
- types = ["translations", "transcriptions", "glosses", "entities"]
58
+ types = ["elanpaths", "translations", "transcriptions", "glosses", "entities"]
40
59
  for type_ in types:
41
60
  if type_ in exclude:
61
+ print(type_, "excluded")
42
62
  continue
43
- print(type_)
63
+ print('',type_)
44
64
  write_jsons(type_)
45
65
 
46
66