def makeAnswer(wordText, question, POSText, index):
    w = Word(question=question,
             word=wordText,
             part_of_speech=POSText,
             index=index)
    w.save()
    return w.pk
Ejemplo n.º 2
0
def save_word(word):
    word_objects = Word.objects.filter(title=word)
    if not word_objects:
        word_object = Word(title=word)
        word_object.save()
    else:
        word_object = word_objects[0]
    return word_object
Ejemplo n.º 3
0
def save_word(word):
	word_objects = Word.objects.filter(title=word)
	if not word_objects:
		word_object = Word(title=word)
		word_object.save()
	else:
		word_object = word_objects[0]
	return word_object
def makeWord(word, question, index):
    part_of_speech = getPartOfSpeech(word)
    word = getWord(word)
    w = Word(question=question,
             word=word,
             part_of_speech=part_of_speech,
             index=index)
    w.save()
    return w.pk
Ejemplo n.º 5
0
def makeComboItem(word1, word2):
    word = Word()
    while(word.id == None):
        print("Make an entry to combine the following words:")
        print(word1)
        print(word2)
        kana = input('kana>')
        kanji = input('kanji>')
        definition = input('definition>')
        
        word = Word(kana = kana, kanji = kanji, definition = definition)
        print(word)
        if 'y' == input("Is this correct? (y/n) "):
            word.save()
            word1.dupeOf(word)
            word2.dupeOf(word)
            
    return word
Ejemplo n.º 6
0
def get_definitions(request):
    word = request.GET.get('word')
    definitions = definition(word)
    response_data = {}

    new_word = Word(text=word)
    if len(definitions) >= 1:
        new_word.definition1 = definitions[0]
    if len(definitions) >= 2:
        new_word.definition2 = definitions[1]
    if len(definitions) >= 3:
        new_word.definition3 = definitions[2]
    new_word.save()

    for i in range(len(definitions)):
        response_data[i] = definitions[i]

    return HttpResponse(json.dumps(response_data), content_type='application/json')
Ejemplo n.º 7
0
	def add_synonyms(self, kSynonyms, sSpace = 'global'):
		
		try:
			oSpace = Space.objects.get(name=sSpace)
		except Space.DoesNotExist:
			oSpace = Space(name='global')
			oSpace.save()
			


		for sWord, kSyns in kSynonyms.iteritems():

			try:
				oWord = Word.objects.get(name=sWord, space=oSpace)
			except Word.DoesNotExist:
				oWord	= Word(name=sWord, space=oSpace)
				oWord.save()
				
			for sSyn, kProps in kSyns.iteritems():
				
				try:
					oSyn = Word.objects.get(name=sSyn, space=oSpace)
				except Word.DoesNotExist:
					oSyn = Word(name=sSyn, space=oSpace)
					oSyn.save()
					
				try:
					oRelation = Relation.objects.get(rel_one=oWord, rel_two=oSyn)
					oRelation.karma += kProps['weight']
					oRelation.save()
					
				except Relation.DoesNotExist:
					
					try:
						oRelation = Relation.objects.get(rel_two=oWord, rel_one=oSyn)
						oRelation.karma += kProps['weight']
						oRelation.save()
						
					except Relation.DoesNotExist:
						oRelation = Relation(rel_one=oWord, rel_two=oSyn, karma=kProps['weight'], space=oSpace)
						oRelation.save()
Ejemplo n.º 8
0
    def create(self, validated_data):
        # this word is definitely not duplicated and is already forced to lower
        word = validated_data['word']
        charList = list(word)
        charList.sort()
        palindrome = isPalindrome(word)
        letters = ''.join(charList)
        hasAna = False
        anas = Word.objects.filter(letters=letters)
        numAnas = len(anas)
        if numAnas > 0:
            hasAna = True
            if numAnas == 1:
                anas[0].hasAnagram = True
                anas[0].save()

        w = Word(word=word,
                 letters=letters,
                 isPalindrome=isPalindrome(word),
                 hasAnagram=hasAna)
        w.save()
        return w
Ejemplo n.º 9
0
def wordlist(request, project_name):
    project = Project.objects.get(project_name=project_name)
    if request.method == 'POST':
        if 'single' in request.POST:
            form = WordForm(request.POST)
            if form.is_valid():
                word = form.cleaned_data['word']
                word_cn = form.cleaned_data['word_cn']
                source = form.cleaned_data['source']
                introduce = form.cleaned_data['introduce']
                try:
                    w = Word.objects.get(word = word)
                    w.project.add(project)
                    w.save()
                except:
                    w = Word(word = word,
                             word_cn = word_cn,
                             source = source,
                             introduce = introduce,
                             add_time = add_time,
                             )
                    w.save()
                    w.project.add(project)
                    w.save()
                return HttpResponseRedirect('.')
        elif 'macro' in request.POST:
            lines = request.POST['wordtable'].split('\r\n')
            for line in lines:
                if '|' not in line:
                    continue
                elif line.count('|') != 3:
                    continue
                else:
                    l = line.split('|')
                    try:
                        w = Word.objects.get(word = l[0])
                        w.project.add(project)
                        w.save()
                    except:
                        w = Word(word = l[0],
                                 word_cn = l[1],
                                 source = l[2],
                                 introduce = l[3],
                                 add_time = add_time,
                                 )
                        w.save()
                        w.project.add(project)
                        w.save()
            return HttpResponseRedirect('.')
        elif 'del' in request.POST:
            wids = request.POST.getlist('wid')
            wids = [int(wid) for wid in wids]
            Word.objects.filter(id__in=wids).delete()
            return HttpResponseRedirect('.')
    else:
        if request.user.has_perm('projects.%s_member'%project_name):
            perm_project_member = True
        else:
            perm_project_member = False
        wordlist = Word.objects.filter(project=project)
        form = WordForm()
    return render_to_response("wordlist.html",{'wordlist': wordlist, 'form': form, \
                                               'project': project, \
                                               'perm_project_member': perm_project_member},\
                        context_instance=RequestContext(request))