class ArgumentEntity(db.Model): __tablename__ = 'arguments_entity' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) role = db.Column(db.Integer, db.ForeignKey(ArgumentRole.id), nullable=False) event = db.Column(db.Integer, db.ForeignKey(Event.id), nullable=False) argument = db.Column(db.Integer, db.ForeignKey(Entity.id), nullable=False) version = db.Column(db.Integer, db.ForeignKey(Version.id)) def __repr__(self): return "<Entity(category='%s', start='%s', end='%s', text='%s')>" % ( self.category, self.start, self.end, self.text)
class Event(db.Model): __tablename__ = 'events' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) document = db.Column(db.Integer, db.ForeignKey(Document.id)) category = db.Column(db.Integer, db.ForeignKey(EventCategory.id)) arguments_entity = db.relationship('ArgumentEntity') arguments_event = db.relationship('ArgumentEvent', foreign_keys="ArgumentEvent.event") properties = db.relationship('EventProperty') version = db.Column(db.Integer, db.ForeignKey(Version.id)) def __repr__(self): return "<Entity(category='%s', start='%s', end='%s', text='%s')>" % ( self.category, self.start, self.end, self.text)
class Entity(db.Model): __tablename__ = 'entities' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) document = db.Column(db.Integer, db.ForeignKey(Document.id)) category = db.Column(db.Integer, db.ForeignKey(EntityCategory.id)) start = db.Column(db.Integer) end = db.Column(db.Integer) text = db.Column(db.Text) properties = db.relationship('EntityProperty') version = db.Column(db.Integer, db.ForeignKey(Version.id)) def __repr__(self): return "<Entity(category='%s', start='%s', end='%s', text='%s')>" % ( self.category, self.start, self.end, self.text)
class ArgumentRole(db.Model): __tablename__ = 'argument_roles' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) role = db.Column(db.String(32)) version = db.Column(db.Integer, db.ForeignKey(Version.id)) def __repr__(self): return "<Argument Role(role='%s', start='%s', end='%s', text='%s')>" % self.role
class EventCategory(db.Model): __tablename__ = 'event_category' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) category = db.Column(db.String(32)) version = db.Column(db.Integer, db.ForeignKey(Version.id)) def __repr__(self): return "<Event Category(category='%s')>" % self.category
class EntityProperty(db.Model): """key-value property pairs for entity or event """ __tablename__ = 'entity_properties' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) label = db.Column(db.String(64)) value = db.Column(db.String(64)) entity = db.Column(db.ForeignKey(Entity.id), nullable=False) def __repr__(self): return "<Entity Property(key='%s', value='%s')>" % self.key, self.value
class Version(db.Model): __tablename__ = 'versions' __table_args__ = {'mysql_engine': 'InnoDB'} id = db.Column(db.Integer, primary_key=True) # TODO: how to get the user from a version object, currently it is just user id not user object user = db.Column(db.Integer, db.ForeignKey(User.id)) datetime = db.Column(db.DateTime, default=datetime.datetime.utcnow()) version = db.Column(db.String(64)) entities = db.relationship('Entity') events = db.relationship('Event') entity_categories = db.relationship('EntityCategory') event_categories = db.relationship('EventCategory') def __init__(self, user, version): self.user = user self.version = version def __repr__(self): return "<Version(user='******', version='%s')>" % self.user.username, self.version