def _create_dwords(self, chunk, words): dwords = [] vwords = [] for item in chunk: value = item['word'] dwords.append(Word_Description(dictionary=self.dictionary, word=words[unify(value)], value=value, description=item['desc'], source=item['source'])) vwords.append(Word_Value(dictionary=self.dictionary, word=words[unify(value)], value=value)) Word_Description.objects.bulk_create(dwords) Word_Value.objects.bulk_create(vwords)
def _find_words(self, chunk): self.values = set([unify(item['word']) for item in chunk]) not_found = list(self.values) words = dict() for word in Word.objects.filter(value__in=self.values): words[word.value] = word not_found.remove(word.value) return words, not_found
def _create_mystems(self, chunk, words): mystems = [] for item in chunk: value = item['word'] data = item['data'] result = data['result'] short = data['short'] noun = data['noun'] unknown = data['unknown'] freq = data['freq'] wrong = data['wrong'] word = words[unify(value)] mystems.append(MyStem(word=word, value=value, result=result, short=short, noun=noun, unknown=unknown, freq=freq, wrong=wrong)) MyStem.objects.bulk_create(mystems)
def db_add_word(dictionary, value, desc=''): # remove! word, created = Word.objects.get_or_create(value=unify(value)) Word_Description.objects.create(word=word, dictionary=dictionary, value=value, description=desc) Word_Value.objects.create(word=word, dictionary=dictionary, value=value)