File size: 2,660 Bytes
ac40033
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey
from sqlalchemy.orm import relationship, declarative_base
from pydantic import BaseModel, ConfigDict
from typing import List
from datetime import datetime

Base = declarative_base()

class Annotator(Base):
    __tablename__ = 'annotators'

    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False, unique=True)
    password = Column(String, nullable=False)
    last_login = Column(DateTime)
    is_active = Column(Boolean, default=True)
    annotations = relationship('Annotation', backref='annotator')
    validators = relationship('Validator', backref='annotator') 
    annotation_intervals = relationship('AnnotationInterval', backref='annotator') 


class Validator(Base):
    __tablename__ = 'validators'

    id = Column(Integer, primary_key=True)
    annotator_id = Column(Integer, ForeignKey('annotators.id'))
    validator_id = Column(Integer, ForeignKey('annotators.id'))


class AnnotationInterval(Base):
    __tablename__ = 'annotation_intervals'

    id = Column(Integer, primary_key=True)
    annotator_id = Column(Integer, ForeignKey('annotators.id'))
    start_index = Column(Integer, nullable=True)
    end_index = Column(Integer, nullable=True)


class AudioTrim(Base):
    __tablename__ = 'audio_trims'

    id = Column(Integer, primary_key=True)
    start = Column(Float, nullable=False)
    end = Column(Float, nullable=False)
    annotation_id = Column(Integer, ForeignKey('annotations.id'))

class Annotation(Base):
    __tablename__ = 'annotations'

    id = Column(Integer, primary_key=True)
    annotated_subtitle = Column(String, nullable=False)
    validated = Column(Boolean, nullable=False)
    create_at = Column(DateTime, nullable=False)
    update_at = Column(DateTime, nullable=False)
    audio_trims = relationship('AudioTrim', cascade='all, delete', backref='annotation')
    json_data_id = Column(Integer, ForeignKey('json_data.id'))
    annotator_id = Column(Integer, ForeignKey('annotators.id'))


class AudioTrimModel(BaseModel):
    start: float
    end: float
    model_config = ConfigDict(from_attributes=True)

class AnnotationModel(BaseModel):
    annotator: str
    annotated_subtitle: str
    is_first_phase_accepted: bool
    create_at: datetime
    update_at: datetime
    audio_trims: List[AudioTrimModel]
    model_config = ConfigDict(from_attributes=True)

class JsonDataModel(BaseModel):
    id: int
    voice_name: str
    original_subtitle: str
    ignore_it: bool
    is_approved_in_second_phase: bool
    annotations: List[AnnotationModel]
    model_config = ConfigDict(from_attributes=True)