<commit_before>import json
import requests
from django.db import models, transaction
from pynaco.naco import normalizeSimplified
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse

BIOGRAPHICAL_HISTORICAL = 0
DELETION_INFORMATION = 1
NONPUBLIC = 2
SOURCE = 3
NOTE_TYPE_OTHER = 4

NOTE_TYPE_CHOICES = (
    (BIOGRAPHICAL_HISTORICAL, 'Biographical/Historical'),
    (DELETION_INFORMATION, 'Deletion Information'),
    (NONPUBLIC, 'Nonpublic'),
    (SOURCE, 'Source'),
    (NOTE_TYPE_OTHER, 'Other'),
)

ACTIVE = 0
DELETED = 1
SUPPRESSED = 2

RECORD_STATUS_CHOICES = (
    (ACTIVE, 'Active'),
    (DELETED, 'Deleted'),
    (SUPPRESSED, 'Suppressed'),
)

PERSONAL = 0
ORGANIZATION = 1
EVENT = 2
SOFTWARE = 3
BUILDING = 4

NAME_TYPE_CHOICES = (
    (PERSONAL, 'Personal'),
    (ORGANIZATION, 'Organization'),
    (EVENT, 'Event'),
    (SOFTWARE, 'Software'),
    (BUILDING, 'Building'),
)

DATE_DISPLAY_LABELS = {
    PERSONAL: {
        'type': 'Personal',
        'begin': 'Date of Birth',
        'end': 'Date of Death'
    },
    ORGANIZATION: {
        'type': 'Organization',
        'begin': 'Founded Date',
        'end': 'Defunct'
    },
    EVENT: {
        'type': 'Event',
        'begin': 'Begin Date',
        'end': 'End Date'
    },
    SOFTWARE: {
        'type': 'Software',
        'begin': 'Begin Date',
        'end': 'End Date'
    },
    BUILDING: {
        'type': 'Building',
        'begin': 'Erected Date',
        'end': 'Demolished Date',
    },
    None: {
        'type': None,
        'begin': 'Born/Founded Date',
        'end': 'Died/Defunct Date'
    },
}


ACRONYM = 0
ABBREVIATION = 1
TRANSLATION = 2
EXPANSION = 3
VARIANT_TYPE_OTHER = 4

VARIANT_TYPE_CHOICES = (
    (ACRONYM, 'Acronym'),
    (ABBREVIATION, 'Abbreviation'),
    (TRANSLATION, 'Translation'),
    (EXPANSION, 'Expansion'),
    (VARIANT_TYPE_OTHER, 'Other'),
)

CURRENT = 0
FORMER = 1

LOCATION_STATUS_CHOICES = (
    (CURRENT, "current"),
    (FORMER, "former"),
)

NAME_TYPE_SCHEMAS = {
    PERSONAL: 'http://schema.org/Person',
    ORGANIZATION: 'http://schema.org/Organization',
    BUILDING: 'http://schema.org/Place',
}


class Identifier_Type(models.Model):
    label = models.CharField(
        max_length=255,
        help_text="What kind of data is this? Personal website? Twitter?",
    )
    icon_path = models.CharField(
        max_length=255,
        blank=True,
        help_text="Path to icon image?",
    )
    homepage = models.URLField(
        blank=True,
        help_text="Homepage of label. Twitter.com, Facebook.com, etc",
    )

    class Meta:
        ordering = ["label"]
        verbose_name = "Identifier Type"

    def __unicode__(self):
        return self.label


class Identifier(models.Model):
    type = models.ForeignKey(
        "Identifier_Type",
        help_text="Catagorize this record's identifiers here",
    )
    belong_to_name = models.ForeignKey("Name")
    value = models.CharField(max_length=500)
    visible = models.BooleanField(default=True)
    order = models.IntegerField(default=0)

    class Meta:
        ordering = ["order", "type"]

    def __unicode__(self):
        return self.value


class Note(models.Model):
    note = models.TextField(help_text="Enter notes about this record here")
    note_type = models.IntegerField(choices=NOTE_TYPE_CHOICES)
    belong_to_name = models.ForeignKey("Name")

    def __unicode__(self):
        return self.note


class Variant(models.Model):
    belong_to_name = models.ForeignKey("Name")
    variant_type = models.IntegerField(<commit_msg>Add a custom model manager for the Note model.<commit_after>import json
import requests
from django.db import models, transaction
from pynaco.naco import normalizeSimplified
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse

BIOGRAPHICAL_HISTORICAL = 0
DELETION_INFORMATION = 1
NONPUBLIC = 2
SOURCE = 3
NOTE_TYPE_OTHER = 4

NOTE_TYPE_CHOICES = (
    (BIOGRAPHICAL_HISTORICAL, 'Biographical/Historical'),
    (DELETION_INFORMATION, 'Deletion Information'),
    (NONPUBLIC, 'Nonpublic'),
    (SOURCE, 'Source'),
    (NOTE_TYPE_OTHER, 'Other'),
)

ACTIVE = 0
DELETED = 1
SUPPRESSED = 2

RECORD_STATUS_CHOICES = (
    (ACTIVE, 'Active'),
    (DELETED, 'Deleted'),
    (SUPPRESSED, 'Suppressed'),
)

PERSONAL = 0
ORGANIZATION = 1
EVENT = 2
SOFTWARE = 3
BUILDING = 4

NAME_TYPE_CHOICES = (
    (PERSONAL, 'Personal'),
    (ORGANIZATION, 'Organization'),
    (EVENT, 'Event'),
    (SOFTWARE, 'Software'),
    (BUILDING, 'Building'),
)

DATE_DISPLAY_LABELS = {
    PERSONAL: {
        'type': 'Personal',
        'begin': 'Date of Birth',
        'end': 'Date of Death'
    },
    ORGANIZATION: {
        'type': 'Organization',
        'begin': 'Founded Date',
        'end': 'Defunct'
    },
    EVENT: {
        'type': 'Event',
        'begin': 'Begin Date',
        'end': 'End Date'
    },
    SOFTWARE: {
        'type': 'Software',
        'begin': 'Begin Date',
        'end': 'End Date'
    },
    BUILDING: {
        'type': 'Building',
        'begin': 'Erected Date',
        'end': 'Demolished Date',
    },
    None: {
        'type': None,
        'begin': 'Born/Founded Date',
        'end': 'Died/Defunct Date'
    },
}


ACRONYM = 0
ABBREVIATION = 1
TRANSLATION = 2
EXPANSION = 3
VARIANT_TYPE_OTHER = 4

VARIANT_TYPE_CHOICES = (
    (ACRONYM, 'Acronym'),
    (ABBREVIATION, 'Abbreviation'),
    (TRANSLATION, 'Translation'),
    (EXPANSION, 'Expansion'),
    (VARIANT_TYPE_OTHER, 'Other'),
)

CURRENT = 0
FORMER = 1

LOCATION_STATUS_CHOICES = (
    (CURRENT, "current"),
    (FORMER, "former"),
)

NAME_TYPE_SCHEMAS = {
    PERSONAL: 'http://schema.org/Person',
    ORGANIZATION: 'http://schema.org/Organization',
    BUILDING: 'http://schema.org/Place',
}


class Identifier_Type(models.Model):
    label = models.CharField(
        max_length=255,
        help_text="What kind of data is this? Personal website? Twitter?",
    )
    icon_path = models.CharField(
        max_length=255,
        blank=True,
        help_text="Path to icon image?",
    )
    homepage = models.URLField(
        blank=True,
        help_text="Homepage of label. Twitter.com, Facebook.com, etc",
    )

    class Meta:
        ordering = ["label"]
        verbose_name = "Identifier Type"

    def __unicode__(self):
        return self.label


class Identifier(models.Model):
    type = models.ForeignKey(
        "Identifier_Type",
        help_text="Catagorize this record's identifiers here",
    )
    belong_to_name = models.ForeignKey("Name")
    value = models.CharField(max_length=500)
    visible = models.BooleanField(default=True)
    order = models.IntegerField(default=0)

    class Meta:
        ordering = ["order", "type"]

    def __unicode__(self):
        return self.value


class NoteManager(models.Manager):
    use_for_related_fields = True

    def public_notes(self):
        return self.get_queryset().exclude(note_type=NONPUBLIC)


class Note(models.Model):
    note = models.TextField(help_text="Enter notes about this record here")
    note_type = models.IntegerField(choices=NOTE_TYPE_CHOICES)
    belong_to_name = models.ForeignKey("Name")

    objects = NoteManager()

    def __unicode__(self):
        return self.note


class Variant(models.Model):
    belong_to_name = models.ForeignKey("Name")
    variant_type = models.IntegerField(
{'fraction_non_alphanumeric': 0.13047593293672255, 'fraction_numerical': 0.008112493239588967, 'mean_word_length': 3.017925040738729, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1623773', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2442, 'n_words': 541}