<commit_before>"""Entity profile types"""

from flask import url_for
from sqlalchemy import (
    Column, Integer, String, Text, ForeignKey, UniqueConstraint)
from sqlalchemy.orm import backref

from tentd import __tent_version__ as tent_version
from tentd.models import db
from tentd.utils import json_attributes
from tentd.utils.types import JSONDict

class Profile(db.Model):
    """A profile information type belonging to an entity

    The Profile class is an abstract type, defining the relationship between
    an entity and it's profiles, and holding the schema url for the type.

    An entity cannot have multiple profiles with the same schema.

    See: https://tent.io/docs/info-types
    """
    
    id = Column(Integer, primary_key=True)
    
    #: The entity the profile belongs to
    entity = db.relationship('Entity', back_populates='profiles')
    entity_id = Column(Integer, ForeignKey('entity.id'), nullable=False)

    #: The info type schema
    schema = Column(String(256), nullable=False)

    __table_args__ = (
        UniqueConstraint("entity_id", "schema"),
    )

    #: The discriminator for the object type
    type = Column(String(50))
    
    __mapper_args__ = {
        'polymorphic_on': type,
    }

    def __init__(self, **kwargs):
        if self.__class__ == Profile:
            raise NotImplementedError(
                "Don't create instances of Profile! "
                "Use profiles.Generic instead")
        
        super(Profile, self).__init__(**kwargs)
        
        # Set the schema if the class has one defined
        if hasattr(self.__class__, '__schema__'):
            self.schema = self.__class__.__schema__

class CoreProfile(Profile):
    """This model provides the Core profile info type.

    Documentation on this profile type can be found here:
    https://tent.io/docs/info-types#core

    TODO: Add licence and server relationships
    """
    __schema__ = 'https://tent.io/types/info/core/v0.1.0'
    __mapper_args__ = {'polymorphic_identity': 'core'}

    id = Column(Integer, ForeignKey('profile.id'), primary_key=True)
<commit_msg>Allow profile schema to be overridden - Closes #33<commit_after>"""Entity profile types"""

from flask import url_for
from sqlalchemy import (
    Column, Integer, String, Text, ForeignKey, UniqueConstraint)
from sqlalchemy.orm import backref

from tentd import __tent_version__ as tent_version
from tentd.models import db
from tentd.utils import json_attributes
from tentd.utils.types import JSONDict

class Profile(db.Model):
    """A profile information type belonging to an entity

    The Profile class is an abstract type, defining the relationship between
    an entity and it's profiles, and holding the schema url for the type.

    An entity cannot have multiple profiles with the same schema.

    See: https://tent.io/docs/info-types
    """
    
    id = Column(Integer, primary_key=True)
    
    #: The entity the profile belongs to
    entity = db.relationship('Entity', back_populates='profiles')
    entity_id = Column(Integer, ForeignKey('entity.id'), nullable=False)

    #: The info type schema
    schema = Column(String(256), nullable=False)

    __table_args__ = (
        UniqueConstraint("entity_id", "schema"),
    )

    #: The discriminator for the object type
    type = Column(String(50))
    
    __mapper_args__ = {
        'polymorphic_on': type,
    }

    def __init__(self, **kwargs):
        if self.__class__ == Profile:
            raise NotImplementedError(
                "Don't create instances of Profile! "
                "Use profiles.Generic instead")
        
        super(Profile, self).__init__(**kwargs)
        
        # Set the schema if it is blank and the class has one defined
        if not self.schema and hasattr(self.__class__, '__schema__'):
            self.schema = self.__class__.__schema__

class CoreProfile(Profile):
    """This model provides the Core profile info type.

    Documentation on this profile type can be found here:
    https://tent.io/docs/info-types#core

    TODO: Add licence and server relationships
    """
    __schema__ = 'https://tent.io/types/info/core/v0.1.0'
    __mapper_args__ = {'polymorphic_identity': 'core'}

    id = Column(Integer, ForeignKey('profile.id'), primary_key=True)

{'fraction_non_alphanumeric': 0.09251922628757865, 'fraction_numerical': 0.004194826380797017, 'mean_word_length': 3.095419847328244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3067750', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1178, 'n_words': 392}