# Path: conceptnet/corpus/models.py
# class Language(models.Model):
#     """
#     A database object representing a language.
# 
#     Instances of Language can be used in filter expressions to select only
#     objects that apply to a particular language. For example:
#     
#     >>> en = Language.get('en')
#     >>> english_sentences = Sentence.objects.filter(language=en)
#     """
#     id = models.CharField(max_length=16,primary_key=True)
#     name = models.TextField(blank=True)
#     sentence_count = models.IntegerField(default=0)
# 
#     def __str__(self):
#         return "%s (%s)" % (self.name, self.id)
# 
#     @staticmethod
#     def get(id):
#         """
#         Get a language from its ISO language code.
# 
#         Some relevant language codes::
# 
#             en = English
#             pt = Portuguese
#             ko = Korean
#             ja = Japanese
#             nl = Dutch
#             es = Spanish
#             fr = French
#             ar = Arabic
#             zh = Chinese
#         """
#         if isinstance(id,Language): return id
#         return get_lang(id)
# 
#     @property
#     def nl(self):
#         """
#         A collection of natural language tools for a language.
# 
#         See :mod:`simplenlp` for more information on using these tools.
#         """
#         return get_nl(self.id)
# 
# Path: conceptnet/models.py
# class Relation(models.Model):
#     name = models.CharField(max_length=128,unique=True)
#     description = models.CharField(max_length=255, null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     @classmethod
#     def get(cls, name):
#         # Check if the parameter is already a Relation. We don't use
#         # isinstance in case of accidental multiple imports (e.g.,
#         # conceptnet.models vs conceptnet4.models).
#         if hasattr(name, 'id'):
#             return name
#         return cls.objects.get(name=name)


from django.db import models
from conceptnet.corpus.models import Language
from conceptnet.models import Relation
    family = models.TextField()
    f_word = models.ForeignKey(FunctionWord)
    unique_together = (('family', 'f_word'),)

    def __str__(self):
        return self.family + ": " + str(self.f_word)

    class Meta:
        db_table = 'functionfamilies'

    @staticmethod
    def build_function_detector(language, family):
        # Prepare the kb
        words = list(FunctionFamily.objects.filter(family=family,f_word__language=language).values_list('f_word__word', flat=True))

        return FunctionFamilyDetector(words,language,family)

class ParsingPattern(models.Model):
    pattern = models.TextField(blank=False)
    predtype = models.ForeignKey(Relation)
    polarity = models.IntegerField()
    sort_order = models.IntegerField()
    language = models.ForeignKey(Language)

    class Meta:
        db_table = 'parsing_patterns'


class SecondOrderPattern(models.Model):
    regex = models.TextField()

# Path: conceptnet/corpus/models.py
# class Language(models.Model):
#     """
#     A database object representing a language.
# 
#     Instances of Language can be used in filter expressions to select only
#     objects that apply to a particular language. For example:
#     
#     >>> en = Language.get('en')
#     >>> english_sentences = Sentence.objects.filter(language=en)
#     """
#     id = models.CharField(max_length=16,primary_key=True)
#     name = models.TextField(blank=True)
#     sentence_count = models.IntegerField(default=0)
# 
#     def __str__(self):
#         return "%s (%s)" % (self.name, self.id)
# 
#     @staticmethod
#     def get(id):
#         """
#         Get a language from its ISO language code.
# 
#         Some relevant language codes::
# 
#             en = English
#             pt = Portuguese
#             ko = Korean
#             ja = Japanese
#             nl = Dutch
#             es = Spanish
#             fr = French
#             ar = Arabic
#             zh = Chinese
#         """
#         if isinstance(id,Language): return id
#         return get_lang(id)
# 
#     @property
#     def nl(self):
#         """
#         A collection of natural language tools for a language.
# 
#         See :mod:`simplenlp` for more information on using these tools.
#         """
#         return get_nl(self.id)
# 
# Path: conceptnet/models.py
# class Relation(models.Model):
#     name = models.CharField(max_length=128,unique=True)
#     description = models.CharField(max_length=255, null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     @classmethod
#     def get(cls, name):
#         # Check if the parameter is already a Relation. We don't use
#         # isinstance in case of accidental multiple imports (e.g.,
#         # conceptnet.models vs conceptnet4.models).
#         if hasattr(name, 'id'):
#             return name
#         return cls.objects.get(name=name)


# Path: conceptnet/corpus/parse/models.py
from django.db import models
from conceptnet.corpus.models import Language
from conceptnet.models import Relation

    family = models.TextField()
    f_word = models.ForeignKey(FunctionWord)
    unique_together = (('family', 'f_word'),)

    def __str__(self):
        return self.family + ": " + str(self.f_word)

    class Meta:
        db_table = 'functionfamilies'

    @staticmethod
    def build_function_detector(language, family):
        # Prepare the kb
        words = list(FunctionFamily.objects.filter(family=family,f_word__language=language).values_list('f_word__word', flat=True))

        return FunctionFamilyDetector(words,language,family)

class ParsingPattern(models.Model):
    pattern = models.TextField(blank=False)
    predtype = models.ForeignKey(Relation)
    polarity = models.IntegerField()
    sort_order = models.IntegerField()
    language = models.ForeignKey(Language)

    class Meta:
        db_table = 'parsing_patterns'


class SecondOrderPattern(models.Model):
    regex = models.TextField()

    language = models.ForeignKey(Language)