eldpy 0.0.12__tar.gz → 0.2.0__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.
- eldpy-0.2.0/.gitignore +24 -0
- eldpy-0.2.0/LICENSE +21 -0
- eldpy-0.2.0/PKG-INFO +61 -0
- eldpy-0.2.0/README.md +39 -0
- eldpy-0.2.0/pyproject.toml +37 -0
- eldpy-0.2.0/src/eldpy/__init__.py +36 -0
- eldpy-0.0.12/PKG-INFO +0 -70
- eldpy-0.0.12/README.md +0 -48
- eldpy-0.0.12/eldpy/__init__.py +0 -0
- eldpy-0.0.12/eldpy/annotation.py +0 -74
- eldpy-0.0.12/eldpy/archive.py +0 -692
- eldpy-0.0.12/eldpy/bulk.py +0 -91
- eldpy-0.0.12/eldpy/cldf2gb4e.py +0 -190
- eldpy-0.0.12/eldpy/colexify.py +0 -142
- eldpy-0.0.12/eldpy/collection.py +0 -224
- eldpy-0.0.12/eldpy/constants.py +0 -307
- eldpy-0.0.12/eldpy/delaman.py +0 -77
- eldpy-0.0.12/eldpy/download.py +0 -521
- eldpy-0.0.12/eldpy/elanfile.py +0 -1121
- eldpy-0.0.12/eldpy/lod.py +0 -104
- eldpy-0.0.12/eldpy/paradisecconverter.py +0 -26
- eldpy-0.0.12/eldpy/resolver.py +0 -66
- eldpy-0.0.12/eldpy/testing.py +0 -106
- eldpy-0.0.12/eldpy/transitiveclosure.py +0 -83
- eldpy-0.0.12/eldpy/wikidatagraph.py +0 -82
- eldpy-0.0.12/executables/analyze_eafs.py +0 -92
- eldpy-0.0.12/executables/annotation.py +0 -1
- eldpy-0.0.12/executables/constants.py +0 -1
- eldpy-0.0.12/executables/elanfile.py +0 -1
- eldpy-0.0.12/pyproject.toml +0 -62
- eldpy-0.0.12/tests/annotation.py +0 -1
- eldpy-0.0.12/tests/constants.py +0 -1
- eldpy-0.0.12/tests/elanfile.py +0 -1
- eldpy-0.0.12/tests/test_elan.py +0 -326
eldpy-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.pyc
|
|
3
|
+
.venv/
|
|
4
|
+
.omp/
|
|
5
|
+
# dangling symlink in history/old/ (target does not exist); replaced by the editable install
|
|
6
|
+
history/old/textools/langsci
|
|
7
|
+
test_input/
|
|
8
|
+
.venv-old/
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
# data in history/old/wrapperscripts (INEL corpus, distributor exports); the old press code itself stays untracked on purpose
|
|
12
|
+
history/old/wrapperscripts/imports/inel/
|
|
13
|
+
history/old/wrapperscripts/exports/proquest*/
|
|
14
|
+
history/old/wrapperscripts/exports/scopus/
|
|
15
|
+
history/old/wrapperscripts/exports/ebscopdfs/
|
|
16
|
+
history/old/wrapperscripts/exports/langscijson/
|
|
17
|
+
history/old/wrapperscripts/**/*.xlsx
|
|
18
|
+
history/old/wrapperscripts/**/*.xslx
|
|
19
|
+
history/old/wrapperscripts/**/*.ods
|
|
20
|
+
# build output of the eldpy distribution (build/ and every dist/ are ignored above)
|
|
21
|
+
eldpy/build/
|
|
22
|
+
eldpy/src/*.egg-info/
|
|
23
|
+
*.token
|
|
24
|
+
bibstringcache/
|
eldpy-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2026 Sebastian Nordhoff and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
eldpy-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: eldpy
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Glossed examples from ELAN and FLEx files of endangered-language documentation, as CLDF rows, CSV and LaTeX (langsci-gb4e)
|
|
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
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: CLDF,ELAN,FLEx,endangered languages,interlinear glossed text,linguistics
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: langsci[elan,flex]<0.2,>=0.1.0
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# eldpy
|
|
24
|
+
|
|
25
|
+
Glossed examples from ELAN (`.eaf`) and FLEx (`.flextext`) files of language documentation: the sentences with their words, glosses and
|
|
26
|
+
translation, as the rows of a CLDF `examples.csv`, as CSV, or as LaTeX for `langsci-gb4e`.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
pip install eldpy # installs langsci[elan,flex]: lxml, langdetect
|
|
30
|
+
eaf2cldf text.eaf --out out/ --latex examples # the commands come with langsci
|
|
31
|
+
flex2cldf texts.flextext --out out/
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from eldpy import ElanFile, to_csv, to_tex
|
|
36
|
+
|
|
37
|
+
eaf = ElanFile("text.eaf")
|
|
38
|
+
eaf.populate(major_languages=("en",)) # the language(s) of the translation tier
|
|
39
|
+
rows = eaf.examples()
|
|
40
|
+
open("examples.csv", "w", encoding="utf-8").write(to_csv(rows))
|
|
41
|
+
open("examples.tex", "w", encoding="utf-8").write(to_tex(rows, output_type="examples"))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Python 3.11 or newer. The documentation of the options (tier types, sentence tier, sentences without glosses, languages) is in the
|
|
45
|
+
user guide of `langsci`.
|
|
46
|
+
|
|
47
|
+
## Relation to langsci and to eldpy 0.0.x
|
|
48
|
+
|
|
49
|
+
Version 0.2 is a new start. The code is part of [`langsci`](https://pypi.org/project/langsci/) (Language Science Press): `langsci.elan`,
|
|
50
|
+
`langsci.flex`, `langsci.igt`. It was rewritten from eldpy 0.0.x (see "Derived from" below); `eldpy` depends on it and gives it the name
|
|
51
|
+
that it had.
|
|
52
|
+
|
|
53
|
+
**Not included any more:** the download of files from the archives of the DELAMAN network (AILLA, ELAR, PARADISEC, TLA), the archive
|
|
54
|
+
reports and the corpus analysis of eldpy 0.0.x. Whoever needs them installs `eldpy<0.1`; that code is not maintained (the archives
|
|
55
|
+
changed their sites and protect them against crawlers).
|
|
56
|
+
|
|
57
|
+
Derived from eldpy 0.0.x (S. Nordhoff, MIT).
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT, see `LICENSE`.
|
eldpy-0.2.0/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# eldpy
|
|
2
|
+
|
|
3
|
+
Glossed examples from ELAN (`.eaf`) and FLEx (`.flextext`) files of language documentation: the sentences with their words, glosses and
|
|
4
|
+
translation, as the rows of a CLDF `examples.csv`, as CSV, or as LaTeX for `langsci-gb4e`.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
pip install eldpy # installs langsci[elan,flex]: lxml, langdetect
|
|
8
|
+
eaf2cldf text.eaf --out out/ --latex examples # the commands come with langsci
|
|
9
|
+
flex2cldf texts.flextext --out out/
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from eldpy import ElanFile, to_csv, to_tex
|
|
14
|
+
|
|
15
|
+
eaf = ElanFile("text.eaf")
|
|
16
|
+
eaf.populate(major_languages=("en",)) # the language(s) of the translation tier
|
|
17
|
+
rows = eaf.examples()
|
|
18
|
+
open("examples.csv", "w", encoding="utf-8").write(to_csv(rows))
|
|
19
|
+
open("examples.tex", "w", encoding="utf-8").write(to_tex(rows, output_type="examples"))
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Python 3.11 or newer. The documentation of the options (tier types, sentence tier, sentences without glosses, languages) is in the
|
|
23
|
+
user guide of `langsci`.
|
|
24
|
+
|
|
25
|
+
## Relation to langsci and to eldpy 0.0.x
|
|
26
|
+
|
|
27
|
+
Version 0.2 is a new start. The code is part of [`langsci`](https://pypi.org/project/langsci/) (Language Science Press): `langsci.elan`,
|
|
28
|
+
`langsci.flex`, `langsci.igt`. It was rewritten from eldpy 0.0.x (see "Derived from" below); `eldpy` depends on it and gives it the name
|
|
29
|
+
that it had.
|
|
30
|
+
|
|
31
|
+
**Not included any more:** the download of files from the archives of the DELAMAN network (AILLA, ELAR, PARADISEC, TLA), the archive
|
|
32
|
+
reports and the corpus analysis of eldpy 0.0.x. Whoever needs them installs `eldpy<0.1`; that code is not maintained (the archives
|
|
33
|
+
changed their sites and protect them against crawlers).
|
|
34
|
+
|
|
35
|
+
Derived from eldpy 0.0.x (S. Nordhoff, MIT).
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
MIT, see `LICENSE`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "eldpy"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Glossed examples from ELAN and FLEx files of endangered-language documentation, as CLDF rows, CSV and LaTeX (langsci-gb4e)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name = "Sebastian Nordhoff", email = "sebastian.nordhoff@glottotopia.de" }]
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
keywords = ["linguistics", "ELAN", "FLEx", "interlinear glossed text", "CLDF", "endangered languages"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Text Processing :: Linguistic",
|
|
23
|
+
]
|
|
24
|
+
requires-python = ">=3.11"
|
|
25
|
+
# the code lives in langsci.elan, langsci.flex and langsci.igt; eldpy is its name and entry point for the researchers who know it
|
|
26
|
+
dependencies = ["langsci[elan,flex]>=0.1.0,<0.2"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/ZAS-QUEST/eldpy"
|
|
30
|
+
"Bug Tracker" = "https://github.com/ZAS-QUEST/eldpy/issues"
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["src/eldpy"]
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.sdist]
|
|
36
|
+
include = ["src", "README.md", "LICENSE", "pyproject.toml"]
|
|
37
|
+
exclude = ["*.egg-info", "__pycache__", "*.pyc"]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Glossed examples from ELAN (`.eaf`) and FLEx (`.flextext`) files.
|
|
2
|
+
|
|
3
|
+
from eldpy import ElanFile, to_csv, to_tex
|
|
4
|
+
|
|
5
|
+
eaf = ElanFile("text.eaf")
|
|
6
|
+
eaf.populate(major_languages=("en",))
|
|
7
|
+
rows = eaf.examples() # a list of Example, the columns of the CLDF table examples.csv
|
|
8
|
+
open("examples.csv", "w", encoding="utf-8").write(to_csv(rows))
|
|
9
|
+
open("examples.tex", "w", encoding="utf-8").write(to_tex(rows, output_type="examples"))
|
|
10
|
+
|
|
11
|
+
from eldpy import read_examples # FLEx text export
|
|
12
|
+
rows = read_examples("texts.flextext")
|
|
13
|
+
|
|
14
|
+
The code is the one of the press package `langsci` (`langsci.elan`, `langsci.flex`, `langsci.igt`); this package is
|
|
15
|
+
the name under which it is published for people who know eldpy. The commands `eaf2cldf` and `flex2cldf` come with `langsci`.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from langsci.elan import ADDITIONAL_LANGUAGES, ElanError, ElanFile, languages_from_text
|
|
19
|
+
from langsci.flex import FlexError, analyze_word, read_examples, surface_text
|
|
20
|
+
from langsci.igt import OUTPUT_TYPES, Example, lgr_conformance, to_csv, to_tex
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"ADDITIONAL_LANGUAGES",
|
|
24
|
+
"OUTPUT_TYPES",
|
|
25
|
+
"ElanError",
|
|
26
|
+
"ElanFile",
|
|
27
|
+
"Example",
|
|
28
|
+
"FlexError",
|
|
29
|
+
"analyze_word",
|
|
30
|
+
"languages_from_text",
|
|
31
|
+
"lgr_conformance",
|
|
32
|
+
"read_examples",
|
|
33
|
+
"surface_text",
|
|
34
|
+
"to_csv",
|
|
35
|
+
"to_tex",
|
|
36
|
+
]
|
eldpy-0.0.12/PKG-INFO
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: eldpy
|
|
3
|
-
Version: 0.0.12
|
|
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.12/README.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
```
|
eldpy-0.0.12/eldpy/__init__.py
DELETED
|
File without changes
|
eldpy-0.0.12/eldpy/annotation.py
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
|