Skip to content

Commit

Permalink
from & to ts of a ref anno is derived from referenced annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
letuananh committed Apr 29, 2021
1 parent c240617 commit 6e339a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions speach/elan.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def ts(self):

@property
def sec(self):
""" Get TimeSlot value in seconds instead of milliseconds """
return self.value / 1000 if self.value is not None else None

def __lt__(self, other):
Expand Down Expand Up @@ -84,6 +85,9 @@ def __sub__(self, other):
def __hash__(self):
return id(self)

def __repr__(self):
return f"TimeSlot(value={repr(self.value)})"

def __str__(self):
val = self.ts
return val if val else self.ID
Expand Down Expand Up @@ -166,6 +170,14 @@ def __init__(self, ID, ref_id, previous, value, xml_node=None, **kwargs):
def ref(self):
return self.__ref

@property
def from_ts(self):
return self.__ref.from_ts if self.__ref is not None else None

@property
def to_ts(self):
return self.__ref.to_ts if self.__ref is not None else None

def resolve(self, elan_doc):
_ref_ann = elan_doc.annotation(self.__ref_id)
if _ref_ann is None:
Expand Down
9 changes: 9 additions & 0 deletions test/test_elan.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def test_write_elan(self):
eaf = read_eaf()
self.assertTrue(eaf.to_xml_bin())

def test_ref_ann(self):
eaf = read_eaf()
ann = eaf['Person1 (Language)'][0]
self.assertIsNotNone(ann.ref)
self.assertEqual(ann.from_ts, 1040)
self.assertEqual(ann.to_ts, 2330)
self.assertEqual(ann.from_ts.sec, 1.04)
self.assertEqual(ann.to_ts.sec, 2.33)


# -------------------------------------------------------------------------------
# MAIN
Expand Down

0 comments on commit 6e339a1

Please sign in to comment.