Skip to content

Commit

Permalink
importation code factorization
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgautheron committed Jun 7, 2021
1 parent e90a12e commit 4cb7394
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
26 changes: 4 additions & 22 deletions ChildProject/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AnnotationManager:
IndexColumn(name = 'range_onset', description = 'covered range start time in milliseconds, measured since `time_seek`', regex = r"([0-9]+)", required = True),
IndexColumn(name = 'range_offset', description = 'covered range end time in milliseconds, measured since `time_seek`', regex = r"([0-9]+)", required = True),
IndexColumn(name = 'raw_filename', description = 'annotation input filename location, relative to `annotations/<set>/raw`', filename = True, required = True),
IndexColumn(name = 'format', description = 'input annotation format', choices = ['TextGrid', 'eaf', 'vtc_rttm', 'vcm_rttm', 'alice', 'its', 'cha', 'NA'], required = False),
IndexColumn(name = 'format', description = 'input annotation format', choices = converters.keys() + ['NA'], required = False),
IndexColumn(name = 'filter', description = 'source file to filter in (for rttm and alice only)', required = False),
IndexColumn(name = 'annotation_filename', description = 'output formatted annotation location, relative to `annotations/<set>/converted (automatic column, don\'t specify)', filename = True, required = False, generated = True),
IndexColumn(name = 'imported_at', description = 'importation date (automatic column, don\'t specify)', datetime = "%Y-%m-%d %H:%M:%S", required = False, generated = True),
Expand Down Expand Up @@ -195,27 +195,9 @@ def _import_annotation(self, import_function: Callable[[str], pd.DataFrame], ann
try:
if callable(import_function):
df = import_function(path)
elif annotation_format == 'TextGrid':
from .converters import TextGridConverter
df = TextGridConverter.convert(path)
elif annotation_format == 'eaf':
from .converters import EafConverter
df = EafConverter.convert(path)
elif annotation_format == 'vtc_rttm':
from .converters import VtcConverter
df = VtcConverter.convert(path, source_file = filter)
elif annotation_format == 'vcm_rttm':
from .converters import VcmConverter
df = VcmConverter.convert(path, source_file = filter)
elif annotation_format == 'its':
from .converters import ItsConverter
df = ItsConverter.convert(path, recording_num = filter)
elif annotation_format == 'alice':
from .converters import AliceConverter
df = AliceConverter.convert(path, source_file = filter)
elif annotation_format == 'cha':
from .converters import ChatConverter
df = ChatConverter.convert(path)
elif annotation_format in converters:
converter = converters[annotation_format]
df = converter.convert(path, filter)
else:
raise ValueError("file format '{}' unknown for '{}'".format(annotation_format, path))
except:
Expand Down
10 changes: 5 additions & 5 deletions ChildProject/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def convert(filename: str, source_file: str = '') -> pd.DataFrame:

class AliceConverter(AnnotationConverter):
FORMAT = 'alice'

@staticmethod
def convert(filename: str, source_file: str = '') -> pd.DataFrame:
df = pd.read_csv(
Expand Down Expand Up @@ -287,10 +287,10 @@ def extract_from_regex(pattern, subject):
return df

class TextGridConverter(AnnotationConverter):
FORMAT = 'textgrid'
FORMAT = 'TextGrid'

@staticmethod
def convert(filename: str) -> pd.DataFrame:
def convert(filename: str, filter = None) -> pd.DataFrame:
import pympi
textgrid = pympi.Praat.TextGrid(filename)

Expand Down Expand Up @@ -330,7 +330,7 @@ class EafConverter(AnnotationConverter):
FORMAT = 'eaf'

@staticmethod
def convert(filename: str) -> pd.DataFrame:
def convert(filename: str, filter = None) -> pd.DataFrame:
import pympi
eaf = pympi.Elan.Eaf(filename)

Expand Down Expand Up @@ -463,7 +463,7 @@ def role_to_addressee(role):
return ChatConverter.ADDRESSEE_TABLE[ChatConverter.SPEAKER_ROLE_TO_TYPE[role]]

@staticmethod
def convert(filename: str) -> pd.DataFrame:
def convert(filename: str, filter = None) -> pd.DataFrame:

import pylangacq

Expand Down

0 comments on commit 4cb7394

Please sign in to comment.