File size: 5,706 Bytes
bc1cd44
 
 
 
 
 
 
 
 
 
1ef4e10
 
 
 
bc1cd44
 
 
1ef4e10
 
 
 
bc1cd44
 
1ef4e10
e1df50c
 
 
 
 
1ef4e10
bc1cd44
 
 
1ef4e10
 
 
 
bc1cd44
 
1ef4e10
 
bc1cd44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ef4e10
 
bc1cd44
 
 
1ef4e10
 
 
 
bc1cd44
 
 
 
 
 
 
 
 
 
 
 
 
1ef4e10
 
bc1cd44
 
 
1ef4e10
 
 
 
 
 
 
 
bc1cd44
 
1ef4e10
bc1cd44
 
 
1ef4e10
 
 
 
bc1cd44
1ef4e10
 
 
e1df50c
 
bc1cd44
 
e1df50c
 
bc1cd44
 
 
1ef4e10
bc1cd44
1ef4e10
 
 
bc1cd44
 
 
1ef4e10
 
 
 
 
 
 
 
bc1cd44
1ef4e10
bc1cd44
 
 
 
1ef4e10
 
 
 
 
 
 
bc1cd44
1ef4e10
bc1cd44
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from sqlalchemy import (
    Column,
    Integer,
    String,
    Float,
    Boolean,
    DateTime,
    ForeignKey,
    Text,
)
from sqlalchemy.orm import relationship, declarative_base

Base = declarative_base()

# --------------------------------------------------------------------------- #
#                                   TTSData                                   #
# --------------------------------------------------------------------------- #
class TTSData(Base):
    __tablename__ = "tts_data"

    id = Column(Integer, primary_key=True)
    filename = Column(String(255), nullable=False, unique=True)
    sentence = Column(Text, nullable=False)

    annotations = relationship(
        "Annotation",
        back_populates="tts_data",
        cascade="all, delete-orphan",
    )

# --------------------------------------------------------------------------- #
#                                  Annotator                                  #
# --------------------------------------------------------------------------- #
class Annotator(Base):
    __tablename__ = "annotators"

    id = Column(Integer, primary_key=True)
    name = Column(String(100), nullable=False, unique=True)
    password = Column(String(255), nullable=False)
    last_login = Column(DateTime)
    is_active = Column(Boolean, default=True)

    annotations = relationship(
        "Annotation",
        back_populates="annotator",
        cascade="all, delete-orphan",
    )

    validation_records = relationship(
        "Validator",
        back_populates="annotated_annotator",
        foreign_keys="Validator.annotator_id",
        cascade="all, delete-orphan",
    )

    validations_done = relationship(
        "Validator",
        back_populates="validator_user",
        foreign_keys="Validator.validator_id",
        cascade="all, delete-orphan",
    )

    annotation_intervals = relationship(
        "AnnotationInterval",
        back_populates="annotator",
        cascade="all, delete-orphan",
    )


# --------------------------------------------------------------------------- #
#                                   Validator                                 #
# --------------------------------------------------------------------------- #
class Validator(Base):
    __tablename__ = "validators"

    id = Column(Integer, primary_key=True)
    annotator_id = Column(Integer, ForeignKey("annotators.id"), nullable=False)
    validator_id = Column(Integer, ForeignKey("annotators.id"), nullable=False)

    annotated_annotator = relationship(
        "Annotator",
        foreign_keys=[annotator_id],
        back_populates="validation_records",
    )
    validator_user = relationship(
        "Annotator",
        foreign_keys=[validator_id],
        back_populates="validations_done",
    )


# --------------------------------------------------------------------------- #
#                              AnnotationInterval                             #
# --------------------------------------------------------------------------- #
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)

    annotator = relationship("Annotator", back_populates="annotation_intervals")


# --------------------------------------------------------------------------- #
#                                  Annotation                                 #
# --------------------------------------------------------------------------- #
class Annotation(Base):
    __tablename__ = "annotations"

    id = Column(Integer, primary_key=True)
    annotated_sentence = Column(Text, nullable=False)
    validated = Column(Boolean, nullable=False)
    annotated_at = Column(DateTime, nullable=False)
    annotator_id = Column(Integer, ForeignKey("annotators.id"))
    tts_data_id = Column(Integer, ForeignKey("tts_data.id"))
    

    annotator = relationship("Annotator", back_populates="annotations")
    tts_data = relationship("TTSData", back_populates="annotations") 

    audio_trims = relationship(
        "AudioTrim", cascade="all, delete-orphan", back_populates="annotation"
    )
    validations = relationship(
        "Validation", cascade="all, delete-orphan", back_populates="annotation"
    )


# --------------------------------------------------------------------------- #
#                                  AudioTrim                                  #
# --------------------------------------------------------------------------- #
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"))

    annotation = relationship("Annotation", back_populates="audio_trims")


# --------------------------------------------------------------------------- #
#                                  Validation                                 #
# --------------------------------------------------------------------------- #
class Validation(Base):
    __tablename__ = "validations"

    id = Column(Integer, primary_key=True)
    annotation_id = Column(Integer, ForeignKey("annotations.id"))
    validator_id = Column(Integer, ForeignKey("validators.id"))
    validated = Column(Boolean, nullable=False)
    description = Column(Text, nullable=True)
    validated_at = Column(DateTime, nullable=False)

    annotation = relationship("Annotation", back_populates="validations")
    validator = relationship("Validator")