Last active
December 19, 2015 01:38
-
-
Save maowug/5876903 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in most cases, less than 3 documents | |
es= list(jp.find({'title':t})) | |
if es: | |
flagNotFound=False | |
# init the correct_e | |
the_e=None | |
# if len(es)==1 | |
if len(es)==1: | |
e=es[0] | |
the_e = e if e['pt']==0 else jp.find_one({'_id':e['pt']}) | |
flagNotOnly=False | |
else: | |
###note: local e, I should use `for ie in es: ...` , not the same e as jp.update(e,{...}) | |
for e in es: | |
e_title= e['pt_title'] if e.has_key('pt_title') else e['title'] | |
# if the title return from getWord equals e['title] (should be hiragana) | |
if e_title in titles_fromWord: | |
title=e_title | |
the_e = e if e['pt']==0 else jp.find_one({'_id':e['pt']}) | |
flagNotOnly=False | |
break | |
else: | |
continue | |
e=the_e | |
if e: | |
forms_to_push = list(set(titles+titles_fromWord) - set(e.get('forms', [])+[e['title']])) | |
# some have forms==[]: | |
# so check if len_forms=(e.get('forms',[])) equals 0 won't make sense | |
len_forms=0 | |
if e.has_key('forms'): | |
len_forms=len(e['forms']) | |
############# didn't get updated here | |
jp.update(e,{'$set':{'sensesJa':sensesJa,'last':'#pushForms'}, | |
'$push':{'forms':{'$each':forms_to_push}} | |
}) | |
else: | |
jp.update(e,{'$set':{'sensesJa':sensesJa,'forms':forms_to_push,'last':'#setForms'}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment