# Path: conceptnet/corpus/models.py
# class Sentence(models.Model, ScoredModel):
#     """
#     A statement entered by a contributor, in unparsed natural language.
#     """
#     text = models.TextField(blank=False)
#     creator = models.ForeignKey(User)
#     created_on = models.DateTimeField(default=datetime.now)
#     language = models.ForeignKey(Language)
#     activity = models.ForeignKey(Activity)
#     score = models.IntegerField(default=0)
#     votes = generic.GenericRelation(Vote)
# 
#     def __unicode__(self):
#         return  u'<' + self.language.id + u': ' + \
#                 u'"' + self.text + u'"' + \
#                 u'(by:' + unicode(self.creator_id) + \
#                 u' activity:' + self.activity.name + \
#                 u')>'
#     
# 
#     def update_consistency(self):
#         """
#         Assume that the creator of this sentence voted for it, and calculate
#         the score.
#         """
#         try:
#             if self.creator is not None and self.get_rating(self.creator) is None:
#                 if self.creator.username != 'verbosity':
#                     Vote.objects.record_vote(self, self.creator, 1)
#             self.update_score()
#         except User.DoesNotExist:
#             self.creator = User.objects.get(username='_ghost')
#             Vote.objects.record_vote(self, self.creator, 1)
#             self.update_score()
# 
# class TaggedSentence(models.Model):
#     """
#     The results of running a sentence through a tagger such as MXPOST.
# 
#     We could use this as a step in parsing ConceptNet, but we currently don't.
#     """
#     text = models.TextField()
#     language = models.ForeignKey(Language)
#     sentence = models.ForeignKey(Sentence, primary_key=True)
#     
#     def tagged_words(self):
#         for part in self.text.split(" "):
#             word, tag = part.rsplit("/", 1)
#             yield word, tag
#     
#     def __unicode__(self):
#         return self.text


from pymeta.grammar import OMeta, ParseError
from conceptnet.corpus.models import Sentence, TaggedSentence
from itertools import chain
import sys
wordchar ::= ~'_' ~' ' <letter>:c  => c
aword ::= <wordchar>+:cs           => ''.join(cs)
tag ::= '_' (<letter> | '$')+ <space>
tag1 ::= '_' (<letter> | '$')+:t   => ''.join(t)
tags ::= <tag1>+:ts <space>        => ts

CD ::= <hastag "CD">
DT ::= <hastag "DT">
IN ::= <hastag "IN">
JJ ::= <hastag "JJ">
JJR ::= <hastag "DT">
JJS ::= <hastag "JJS">
MD ::= <hastag "MD">
NN ::= <hastag "NN">
NNS ::= <hastag "NNS">
NNP ::= <hastag "NNP">
POS ::= <hastag "POS">
PRP ::= <hastag "PRP">
PRPp ::= <hastag "PRP$">
RB ::= <hastag "RB">
RP ::= <hastag "RP">
RPR ::= <hastag "RPR">
TO ::= <hastag "TO">
VB ::= <hastag "VB">
VBG ::= <hastag "VBG">
VBN ::= <hastag "VBN">
VBP ::= <hastag "VBP">
VBZ ::= <hastag "VBZ">
WDT ::= <hastag "WDT">


# Path: conceptnet/corpus/models.py
# class Sentence(models.Model, ScoredModel):
#     """
#     A statement entered by a contributor, in unparsed natural language.
#     """
#     text = models.TextField(blank=False)
#     creator = models.ForeignKey(User)
#     created_on = models.DateTimeField(default=datetime.now)
#     language = models.ForeignKey(Language)
#     activity = models.ForeignKey(Activity)
#     score = models.IntegerField(default=0)
#     votes = generic.GenericRelation(Vote)
# 
#     def __unicode__(self):
#         return  u'<' + self.language.id + u': ' + \
#                 u'"' + self.text + u'"' + \
#                 u'(by:' + unicode(self.creator_id) + \
#                 u' activity:' + self.activity.name + \
#                 u')>'
#     
# 
#     def update_consistency(self):
#         """
#         Assume that the creator of this sentence voted for it, and calculate
#         the score.
#         """
#         try:
#             if self.creator is not None and self.get_rating(self.creator) is None:
#                 if self.creator.username != 'verbosity':
#                     Vote.objects.record_vote(self, self.creator, 1)
#             self.update_score()
#         except User.DoesNotExist:
#             self.creator = User.objects.get(username='_ghost')
#             Vote.objects.record_vote(self, self.creator, 1)
#             self.update_score()
# 
# class TaggedSentence(models.Model):
#     """
#     The results of running a sentence through a tagger such as MXPOST.
# 
#     We could use this as a step in parsing ConceptNet, but we currently don't.
#     """
#     text = models.TextField()
#     language = models.ForeignKey(Language)
#     sentence = models.ForeignKey(Sentence, primary_key=True)
#     
#     def tagged_words(self):
#         for part in self.text.split(" "):
#             word, tag = part.rsplit("/", 1)
#             yield word, tag
#     
#     def __unicode__(self):
#         return self.text


# Path: conceptnet/corpus/parse/metapattern.py
from pymeta.grammar import OMeta, ParseError
from conceptnet.corpus.models import Sentence, TaggedSentence
from itertools import chain
import sys

wordchar ::= ~'_' ~' ' <letter>:c  => c
aword ::= <wordchar>+:cs           => ''.join(cs)
tag ::= '_' (<letter> | '$')+ <space>
tag1 ::= '_' (<letter> | '$')+:t   => ''.join(t)
tags ::= <tag1>+:ts <space>        => ts

CD ::= <hastag "CD">
DT ::= <hastag "DT">
IN ::= <hastag "IN">
JJ ::= <hastag "JJ">
JJR ::= <hastag "DT">
JJS ::= <hastag "JJS">
MD ::= <hastag "MD">
NN ::= <hastag "NN">
NNS ::= <hastag "NNS">
NNP ::= <hastag "NNP">
POS ::= <hastag "POS">
PRP ::= <hastag "PRP">
PRPp ::= <hastag "PRP$">
RB ::= <hastag "RB">
RP ::= <hastag "RP">
RPR ::= <hastag "RPR">
TO ::= <hastag "TO">
VB ::= <hastag "VB">
VBG ::= <hastag "VBG">
VBN ::= <hastag "VBN">
VBP ::= <hastag "VBP">
VBZ ::= <hastag "VBZ">
WDT ::= <hastag "WDT">


N1  ::= (<NN> | <NNS>)+:ns                      => ' '.join(ns)