class Text(db.Model): __tablename__ = "Texts" id = db.Column(db.Integer, primary_key=True) text = db.Column(db.Text, nullable=False, unique=True) user_id = db.Column(db.Integer, db.ForeignKey('Users.id')) annotate = db.relationship('Annotation', backref='text', uselist=False, cascade="all, delete") clusters = db.relationship('ClusterAnalysis', backref='text', cascade="all, delete") def __init__(self, text, user_id): self.text = text self.user_id = user_id
class SystemOfConclusions(db.Model): __tablename__ = "SystemsOfConclusions" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(1024)) description = db.Column(db.Text) user_id = db.Column(db.Integer, db.ForeignKey('Users.id')) requests = db.relationship('HistoryOfConclusions', backref='SystemOfConclusions', cascade="all, delete") rules = db.relationship('Rule', backref='SystemOfConclusions', cascade="all, delete") linguistic_vars = db.relationship('LinguisticVariable', backref='SystemOfConclusions', cascade="all, delete") def __init__(self, name, description, user_id): self.name = name self.description = description self.user_id = user_id
class LinguisticVariable(db.Model): __tablename__ = "LinguisticVariable" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(1024)) lower = db.Column(db.Float, nullable=False) upper = db.Column(db.Float, nullable=False) type_output = db.Column(db.Boolean) system_id = db.Column(db.Integer, db.ForeignKey('SystemsOfConclusions.id')) terms = db.relationship('Term', backref='LinguisticVariable', cascade="all, delete") input_output = db.relationship('HistoryInputOutput', backref='LinguisticVariable', cascade="all, delete") def __init__(self, name, lower, upper, system_id, type_output=False): self.name = name self.lower = lower self.upper = upper self.system_id = system_id self.type_output = type_output
class User(db.Model, UserMixin): __tablename__ = "Users" id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(32), nullable=False, unique=True) password_hash = db.Column(db.String(1024), nullable=False) email = db.Column(db.String(32), nullable=True) texts = db.relationship('Text', backref='user', cascade="all, delete") systems = db.relationship('SystemOfConclusions', backref='user', cascade="all, delete") requests = db.relationship('HistoryOfConclusions', backref='user', cascade="all, delete") models = db.relationship('AnnotationModel', backref='user', cascade="all, delete") clusters = db.relationship('RequestClustering', backref='user', cascade="all, delete") roles = db.relationship('Role', secondary=user_role, backref=db.backref('users', lazy='dynamic')) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def __init__(self, login, password, email=""): self.login = login self.email = email self.set_password(password)
class HistoryOfConclusions(db.Model): __tablename__ = "HistoryOfConclusions" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('Users.id')) system_id = db.Column(db.Integer, db.ForeignKey('SystemsOfConclusions.id')) date = db.Column(db.DateTime) input_output = db.relationship('HistoryInputOutput', backref='HistoryOfConclusions', cascade="all, delete") def __init__(self, user_id, system_id): self.user_id = user_id self.system_id = system_id self.date = datetime.utcnow()
class RequestClustering(db.Model): __tablename__ = "RequestsClustering" id = db.Column(db.Integer, primary_key=True) count_clusters = db.Column(db.Integer) words = db.Column(db.Text) topic_modeling = db.Column(db.Text) bool_word = db.Column(db.Boolean) bool_fcm = db.Column(db.Boolean) analysis = db.relationship('ClusterAnalysis', backref='request', cascade="all, delete") user_id = db.Column(db.Integer, db.ForeignKey('Users.id')) def __init__(self, count_clusters, user_id, bool_word=True, bool_fcm=True): self.count_clusters = count_clusters self.user_id = user_id self.bool_fcm = bool_fcm self.bool_word = bool_word
class AnnotationModel(db.Model): __tablename__ = "AnnotationModels" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('Users.id')) quality = db.Column(db.Float) alltexts = db.relationship('Annotation', backref='model')