Spaces:
Sleeping
Sleeping
File size: 6,187 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 a5a2167 bc1cd44 a5a2167 bc1cd44 a5a2167 f7ef7d3 a5a2167 f7ef7d3 1ef4e10 bc1cd44 1ef4e10 f7ef7d3 a5a2167 1ef4e10 a5a2167 f7ef7d3 a5a2167 bc1cd44 1ef4e10 c6fc32c 1ef4e10 bc1cd44 1ef4e10 bc1cd44 a5a2167 5dc5cb8 |
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 160 161 |
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)
tts_data_id = Column(Integer, ForeignKey("tts_data.id"), nullable=False)
annotator_id = Column(Integer, ForeignKey("annotators.id"), nullable=False)
annotated_sentence = Column(Text)
validated = Column(Boolean, default=False)
annotated_at = Column(DateTime)
tts_data = relationship("TTSData", back_populates="annotations")
annotator = relationship("Annotator", back_populates="annotations")
# Relationship to AudioTrim (one-to-MANY)
audio_trims = relationship( # Renamed from audio_trim
"AudioTrim",
back_populates="annotation",
uselist=True, # Important for one-to-many
cascade="all, delete-orphan" # If annotation is deleted, delete its trims too
)
# --------------------------------------------------------------------------- #
# AudioTrim #
# --------------------------------------------------------------------------- #
class AudioTrim(Base):
__tablename__ = "audio_trims"
id = Column(Integer, primary_key=True)
annotation_id = Column(Integer, ForeignKey("annotations.id"), nullable=False) # Removed unique=True
original_tts_data_id = Column(Integer, ForeignKey("tts_data.id"), nullable=False) # Link to original audio
start = Column(Float, nullable=False)
end = Column(Float, nullable=False)
# Relationship back to Annotation
annotation = relationship("Annotation", back_populates="audio_trims") # Renamed from audio_trim
original_tts_data = relationship("TTSData") # Optional: if you want to navigate from trim to original TTSData directly
# --------------------------------------------------------------------------- #
# Validation #
# --------------------------------------------------------------------------- #
class Validation(Base):
__tablename__ = "validations"
id = Column(Integer, primary_key=True)
annotation_id = Column(Integer, ForeignKey("annotations.id"))
validator_id = Column(Integer, ForeignKey("annotators.id")) # Fixed: should reference annotators.id
validated = Column(Boolean, nullable=False)
description = Column(Text, nullable=True)
validated_at = Column(DateTime, nullable=False)
annotation = relationship("Annotation")
validator = relationship("Annotator", foreign_keys=[validator_id]) # Fixed: should reference Annotator |