# Path: conceptnet/models.py
# DEFAULT_LANGUAGE = en = Language(id='en', name='English') 
# class TimestampedModel(models.Model):
#     class Meta:
# class UserData(TimestampedModel):
#     class Meta:
# class Batch(TimestampedModel):
# class Relation(models.Model):
# class Frame(models.Model):
# class Feature(object):
# class LeftFeature(Feature):
# class RightFeature(Feature):
# class Proposition(object):
# class Concept(models.Model):
#     class Meta:
# class UsefulAssertionManager(models.Manager):
# class SurfaceForm(models.Model):
#     class Meta:
# class Assertion(models.Model, ScoredModel):
#     class Meta:
# class RawAssertion(TimestampedModel, ScoredModel):
#     class Meta:
#     class Meta:
#     def save(self, **kwargs):
#     def __unicode__(self):
#     def __unicode__(self):
#     def get(cls, name):
#     def preferred(self):
#     def fill_in(self, a, b):
#     def __unicode__(self):
#     def re_pattern(self):
#     def match(self, text):
#     def display(self):
#     def match_sentence(text, language):
#     def __init__(self, relation, concept):
#     def to_tuple(self):
#     def language(self):
#     def __hash__(self): # Features should be immutable.
#     def __cmp__(self, other):
#     def from_tuple(tup, lang=DEFAULT_LANGUAGE, lemmatize=False):
#     def from_obj_tuple(typ, relation, concept):
#     def frame(self):
#     def fill_in(self, newconcept):
#     def matching_assertions(self):
#     def matching_raw(self):
#     def nl_frame(self, gap=None):
#     def nl_statement(self, gap='...'):
#     def _matching_assertions(self):
#     def _matching_raw(self):
#     def nl_parts(self, gap='...'):
#     def direction(self):
#     def __repr__(self):
#     def __unicode__(self):
#     def fill_in(self, newconcept):
#     def matching_assertions(self):
#     def matching_raw(self):
#     def __unicode__(self):
#     def fill_in(self, newconcept):
#     def matching_assertions(self):
#     def matching_raw(self):
# def ensure_concept(concept):
#     def __init__(self, concept1, rel, concept2, lang):
#     def __unicode__(self):
#     def nl_question_bad(self):
#     def right_feature(self):
#     def left_feature(self):
#     def nl_parts(self):
#     def nl_parts_topdown(self):
#     def save(self, *a, **kw):
#     def canonical_name(self):
#     def __unicode__(self):
#     def get_assertions(self, useful_only=True):
#     def get_assertions_forward(self, useful_only=True):
#     def get_assertions_reverse(self, useful_only=True):
#     def raw_assertions(self):
#     def raw_assertions_no_dupes(self, n=10, related=None):
#     def get_my_right_features(self, useful_only=True):
#     def get_my_left_features(self, useful_only=True):
#     def has_feature(self, feature):
#     def score_for_feature(self, feature):
#     def group_assertions_by_feature(self, useful_only=True):
#     def top_assertions_by_feature(self, limit=50, useful_only=True):
#     def some_surface(self):
#     def get(cls, text, language, auto_create=False):
#     def get_raw(cls, normalized_text, language, auto_create=False):
#     def exists(cls, text, language, is_raw=False):
#     def exists_raw(cls, normalized_text, language):
#     def get_by_id(cls, id):
#     def update_num_assertions(self):
#     def get_absolute_url(self):
#     def get_query_set(self):
#     def get(text, lang, auto_create=False):
#     def update_raw(self):
#     def update(self, stem, residue):
#     def urltext(self):
#     def __unicode__(self):
#     def best_raw(self):
#     def nl_repr(self, wrap_text=lambda assertion, text: text):
#     def update_raw_cache(self):
#     def update_score(self):
#     def creator(self):
#     def polarity(self):
#     def __unicode__(self):
#     def get_filtered(cls, *a, **kw):
#     def get_absolute_url(self):
# def denormalize_num_assertions(sender, instance, created=False, **kwargs):
#     def relation(self): return self.frame.relation
#     def text1(self): return self.surface1.text
#     def text2(self): return self.surface2.text
#     def __unicode__(self):
#     def nl_repr(self, wrap_text=lambda assertion, text: text):
#     def main_sentence(self):
#     def surface(self, idx):
#     def correct_assertion(self, frame, surf1, surf2):
#     def update_assertion(self):
#     def make(user, frame, text1, text2, activity, vote=1):
#     def update_score(self):
#     def get_absolute_url(self):


from csc_utils.batch import queryset_foreach
from conceptnet.models import Sentence, Assertion, RawAssertion


def update_scores():
    queryset_foreach(Assertion, lambda x: x.update_score(),
    batch_size=100)
    queryset_foreach(RawAssertion, lambda x: x.update_score(),
    batch_size=100)
    # queryset_foreach(Sentence.objects.exclude(language__id='en'), lambda x: x.update_score(), batch_size=100)

def fix_raw_assertion_vote(raw):
    for vote in raw.votes.all():
        raw.assertion.set_rating(vote.user, vote.vote)

def update_votes():

# Path: conceptnet/models.py
# DEFAULT_LANGUAGE = en = Language(id='en', name='English') 
# class TimestampedModel(models.Model):
#     class Meta:
# class UserData(TimestampedModel):
#     class Meta:
# class Batch(TimestampedModel):
# class Relation(models.Model):
# class Frame(models.Model):
# class Feature(object):
# class LeftFeature(Feature):
# class RightFeature(Feature):
# class Proposition(object):
# class Concept(models.Model):
#     class Meta:
# class UsefulAssertionManager(models.Manager):
# class SurfaceForm(models.Model):
#     class Meta:
# class Assertion(models.Model, ScoredModel):
#     class Meta:
# class RawAssertion(TimestampedModel, ScoredModel):
#     class Meta:
#     class Meta:
#     def save(self, **kwargs):
#     def __unicode__(self):
#     def __unicode__(self):
#     def get(cls, name):
#     def preferred(self):
#     def fill_in(self, a, b):
#     def __unicode__(self):
#     def re_pattern(self):
#     def match(self, text):
#     def display(self):
#     def match_sentence(text, language):
#     def __init__(self, relation, concept):
#     def to_tuple(self):
#     def language(self):
#     def __hash__(self): # Features should be immutable.
#     def __cmp__(self, other):
#     def from_tuple(tup, lang=DEFAULT_LANGUAGE, lemmatize=False):
#     def from_obj_tuple(typ, relation, concept):
#     def frame(self):
#     def fill_in(self, newconcept):
#     def matching_assertions(self):
#     def matching_raw(self):
#     def nl_frame(self, gap=None):
#     def nl_statement(self, gap='...'):
#     def _matching_assertions(self):
#     def _matching_raw(self):
#     def nl_parts(self, gap='...'):
#     def direction(self):
#     def __repr__(self):
#     def __unicode__(self):
#     def fill_in(self, newconcept):
#     def matching_assertions(self):
#     def matching_raw(self):
#     def __unicode__(self):
#     def fill_in(self, newconcept):
#     def matching_assertions(self):
#     def matching_raw(self):
# def ensure_concept(concept):
#     def __init__(self, concept1, rel, concept2, lang):
#     def __unicode__(self):
#     def nl_question_bad(self):
#     def right_feature(self):
#     def left_feature(self):
#     def nl_parts(self):
#     def nl_parts_topdown(self):
#     def save(self, *a, **kw):
#     def canonical_name(self):
#     def __unicode__(self):
#     def get_assertions(self, useful_only=True):
#     def get_assertions_forward(self, useful_only=True):
#     def get_assertions_reverse(self, useful_only=True):
#     def raw_assertions(self):
#     def raw_assertions_no_dupes(self, n=10, related=None):
#     def get_my_right_features(self, useful_only=True):
#     def get_my_left_features(self, useful_only=True):
#     def has_feature(self, feature):
#     def score_for_feature(self, feature):
#     def group_assertions_by_feature(self, useful_only=True):
#     def top_assertions_by_feature(self, limit=50, useful_only=True):
#     def some_surface(self):
#     def get(cls, text, language, auto_create=False):
#     def get_raw(cls, normalized_text, language, auto_create=False):
#     def exists(cls, text, language, is_raw=False):
#     def exists_raw(cls, normalized_text, language):
#     def get_by_id(cls, id):
#     def update_num_assertions(self):
#     def get_absolute_url(self):
#     def get_query_set(self):
#     def get(text, lang, auto_create=False):
#     def update_raw(self):
#     def update(self, stem, residue):
#     def urltext(self):
#     def __unicode__(self):
#     def best_raw(self):
#     def nl_repr(self, wrap_text=lambda assertion, text: text):
#     def update_raw_cache(self):
#     def update_score(self):
#     def creator(self):
#     def polarity(self):
#     def __unicode__(self):
#     def get_filtered(cls, *a, **kw):
#     def get_absolute_url(self):
# def denormalize_num_assertions(sender, instance, created=False, **kwargs):
#     def relation(self): return self.frame.relation
#     def text1(self): return self.surface1.text
#     def text2(self): return self.surface2.text
#     def __unicode__(self):
#     def nl_repr(self, wrap_text=lambda assertion, text: text):
#     def main_sentence(self):
#     def surface(self, idx):
#     def correct_assertion(self, frame, surf1, surf2):
#     def update_assertion(self):
#     def make(user, frame, text1, text2, activity, vote=1):
#     def update_score(self):
#     def get_absolute_url(self):


# Path: maint/update_scores.py
from csc_utils.batch import queryset_foreach
from conceptnet.models import Sentence, Assertion, RawAssertion



def update_scores():
    queryset_foreach(Assertion, lambda x: x.update_score(),
    batch_size=100)
    queryset_foreach(RawAssertion, lambda x: x.update_score(),
    batch_size=100)
    # queryset_foreach(Sentence.objects.exclude(language__id='en'), lambda x: x.update_score(), batch_size=100)

def fix_raw_assertion_vote(raw):
    for vote in raw.votes.all():
        raw.assertion.set_rating(vote.user, vote.vote)

def update_votes():

    queryset_foreach(RawAssertion, lambda x: fix_raw_assertion_vote(x), batch_size=100)