class SegmentComment(db.Model): columns = ['id', 'entity_mention_id', 'segment_id', 'user_id', 'comment'] __tablename__ = 'segment_comment' id = db.Column(db.String(64), primary_key=True) entity_mention_id = db.Column(db.String(64), db.ForeignKey('entity_mention.id'), nullable=False) segment_id = db.Column(db.String(64), db.ForeignKey('segment.id'), nullable=False) user_id = db.Column(db.String(64), unique=False, nullable=False) comment = db.Column(db.Text(1024, convert_unicode=True), unique=False, nullable=True) record_time = db.Column(db.DateTime(), unique=False, nullable=False) entity_mention = relationship("EntityMention", backref='segment_comments', foreign_keys=[entity_mention_id]) segment = relationship("Segment", foreign_keys=[segment_id]) def __json__(self): return self.columns
class SegmentObjectMatch(db.Model): columns = ['id', 'to_obj', 'from_obj', 'measure'] __tablename__ = 'segment_object_matches' id = db.Column(db.String(64), primary_key=True) to_obj = db.Column(db.String(64), db.ForeignKey('segment_object.id'), nullable=False) from_obj = db.Column(db.String(64), db.ForeignKey('segment_object.id'), nullable=False) measure = db.Column(db.Float(), unique=False, nullable=False)
class EntityMention(db.Model): columns = [ 'id', 'tree_id', 'entity_id', 'provenance', 'textoffset_startchar', 'textoffset_endchar', 'justification', 'text_string', 'mention_type', 'level', 'kb_id', 'status', 'media', 'segment_comments' ] __tablename__ = 'entity_mention' id = db.Column(db.String(64), primary_key=True) tree_id = db.Column(db.Integer(), unique=False, nullable=False) entity_id = db.Column(db.String(40), db.ForeignKey('entity.id'), unique=False, nullable=False) provenance = db.Column(db.String(10), db.ForeignKey('media.id'), unique=False, nullable=False) textoffset_startchar = db.Column(db.Integer(), unique=False, nullable=True) textoffset_endchar = db.Column(db.Integer(), unique=False, nullable=True) text_string = db.Column(db.String(256), unique=False, nullable=True) justification = db.Column(db.String(256), unique=False, nullable=True) mention_type = db.Column(db.String(40), unique=False, nullable=False) level = db.Column(db.String(40), unique=False, nullable=True) kb_id = db.Column(db.String(64), db.ForeignKey('kb.id'), nullable=False) status = db.Column(db.String(16), default="Approved") media = relationship("Media", foreign_keys=[provenance]) entity = relationship("Entity", foreign_keys=[ entity_id ]) #,primaryjoin='foreign(EntityMention.provenance) == remote(Media.id)') @hybrid_property def description(self): if self.justification is not None: return self.justification else: return self.text_string @description.expression def description(cls): return case([ (cls.justification != None, cls.justification), ], else_=cls.text_string) def __json__(self): return self.columns
class CanonicalMention(db.Model): columns = [ 'id', 'entity_mention_id', 'child_file', 'frame_number', 'frame_time', 'page_number', 'bounding_box', 'is_text', 'user_id', 'record_time' ] __tablename__ = 'canonical_mention' id = db.Column(db.String(64), primary_key=True) entity_mention_id = db.Column(db.String(64), db.ForeignKey('entity_mention.id'), nullable=False) child_file = db.Column(db.String(64), unique=False, nullable=False) # depending on media type, video and audio frame_number = db.Column(db.Integer(), unique=False, nullable=True) # depending on media type, video and audio frame_time = db.Column(db.Float(), unique=False, nullable=True) # depending on media type of pdf page_number = db.Column(db.Integer(), unique=False, nullable=True) # bounding box on media type of image, video bounding_box = db.Column(db.String(256), unique=False, nullable=True) #is text is_text = db.Column(db.Boolean(), unique=False) #user user_id = db.Column(db.String(64), unique=False, nullable=True) record_time = db.Column(db.DateTime(), unique=False, nullable=False) entity = relationship("EntityMention", foreign_keys=[entity_mention_id]) # @hybrid_property def bounding_box_list(self): return [m.strip() for m in self.bounding_box.strip('[]').split(',')] def __json__(self): return self.columns
class RelativeMention(db.Model): __tablename__ = 'relative_mention' id = db.Column(db.String(64), primary_key=True) tree_id = db.Column(db.Integer(), unique=False, nullable=False) relation_id = db.Column(db.String(40), unique=False, nullable=False) provenance = db.Column(db.String(40), unique=False, nullable=False) textoffset_startchar = db.Column(db.Integer(), unique=False, nullable=True) textoffset_endchar = db.Column(db.Integer(), unique=False, nullable=True) text_string = db.Column(db.String(256), unique=False, nullable=True) justification = db.Column(db.String(256), unique=False, nullable=True) mention_type = db.Column(db.String(40), unique=False, nullable=False) subtype = db.Column(db.String(40), unique=False, nullable=False) attribute = db.Column(db.String(40), unique=False, nullable=False) start_date_type = db.Column(db.String(40), unique=False, nullable=False) end_date_type = db.Column(db.String(40), unique=False, nullable=False) start_date = db.Column(db.DateTime(), unique=False, nullable=False) end_date = db.Column(db.DateTime(), unique=False, nullable=False) kb_id = db.Column(db.String(64), db.ForeignKey('kb.id'), nullable=False) def __json__(self): return [ 'id', 'tree_id', 'relation_id', 'provenance', 'textoffset_startchar', 'textoffset_endchar', 'text_string', 'justification', 'mention_type', 'subtype', 'start_date_type', 'end_date_type', 'start_date', 'end_date', 'kb_id' ]
class Entity(db.Model): __tablename__ = 'entity' id = db.Column(db.String(64), primary_key=True) tree_id = db.Column(db.Integer(), unique=False, nullable=False) description = db.Column(db.String(512), unique=False, nullable=True) entity_type = db.Column(db.String(40), unique=False, nullable=False) kb_id = db.Column(db.String(64), db.ForeignKey('kb.id'), nullable=False) def __json__(self): return ['id', 'tree_id', 'description', 'entity_type', 'kb_id']
class SegmentObject(db.Model): #object type is 'fac','mm_','nat', etc. columns = ['id', 'segment_id', 'object_type', 'bounding_box'] __tablename__ = 'segment_object' id = db.Column(db.String(64), primary_key=True) segment_id = db.Column(db.String(64), db.ForeignKey('segment.id'), nullable=False) bounding_box = db.Column(db.String(256), unique=False, nullable=True) object_type = db.Column(db.String(3), unique=False, nullable=False) segment_object = relationship("Segment", backref='segment_objects', foreign_keys=[segment_id]) def __json__(self): return self.columns
class SegmentText(db.Model): columns = ['id', 'language', 'text', 'text_type'] __tablename__ = 'segment_text' id = db.Column(db.String(64), primary_key=True) segment_id = db.Column(db.String(64), db.ForeignKey('segment.id'), nullable=False) language = db.Column(db.String(3), unique=False, nullable=False) text = db.Column(db.Text(1024, convert_unicode=True), unique=False, nullable=False) text_type = db.Column(db.String(3), unique=False, nullable=False) segment_text = relationship("Segment", backref='segment_texts', foreign_keys=[segment_id]) def __json__(self): return self.columns