views.py 2.79 KB
Newer Older
Sylvain Coulange's avatar
Sylvain Coulange committed
1
2
3
4
from django.shortcuts import render, HttpResponseRedirect
from static.scripts import textPhonographer as txtphono
from .models import Phonograph, Data, Entree
import spacy
Sylvain Coulange's avatar
Sylvain Coulange committed
5
import os
Sylvain Coulange's avatar
Sylvain Coulange committed
6
7
8
9
10
11
12
13
14
15
nlp = spacy.load('fr')

def redirApp(request):
    return HttpResponseRedirect('/app/')

def main(request):
    if request.POST.get('inText'):
        text = request.POST['inText']
        nlpText = nlp(text)
        data = Data()
Sylvain Coulange's avatar
Sylvain Coulange committed
16
        data.update = os.system('git log -1 --format=%cd')
Sylvain Coulange's avatar
Sylvain Coulange committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
        data.text = text
        data.pphh = []

        for token in nlpText:
            print("Mot en entrée :",token.text)
            result = txtphono.mimi(token.text)
            print(result)
        
            phonographie = []
            for i in result:
                ph = Phonograph()
                ph.phon = i[0]
                ph.graph = i[1]
                phonographie.append(ph)
            data.pphh.append(phonographie)
    else:
        data = Data()
        data.text = ''
        data.pphh = []
Sylvain Coulange's avatar
Sylvain Coulange committed
36
        data.update = os.system('git log -1 --format=%cd')
Sylvain Coulange's avatar
Sylvain Coulange committed
37
38
39
    return render(request, 'coloriseur.html', {'data': data})


40
41
42
43
def main0(request):
    data = Data()
    data.text = ''
    data.pphh = []
Sylvain Coulange's avatar
Sylvain Coulange committed
44
    data.update = os.system('git log -1 --format=%cd')
45
46
47
    return render(request, 'coloriseur.html', {'data': data})


Sylvain Coulange's avatar
Sylvain Coulange committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def dicoView(request):
    data = Entree()
    if request.POST.get('inMot') or request.POST.get('inTrans'):
        data.mot = request.POST['inMot'] if request.POST.get('inMot') else ''
        data.motcond = request.POST['condition-mot'] if request.POST.get('condition-mot') else 'contient'
        data.trans = request.POST['inTrans'] if request.POST.get('inTrans') else ''
        data.transcond = request.POST['condition-trans'] if request.POST.get('condition-trans') else 'contient'
        data.result = txtphono.getEntryByWord(m=data.mot, mc=data.motcond, t=data.trans, tc=data.transcond)
        data.nb = len(data.result)
    else:
        data.mot = ''
    return render(request, 'editDico.html', {'data': data})

def editEntry(request):
    mot = request.POST['entreeMot']
    trans = request.POST['entreeTrans']
    motOrigin = request.POST['motOrigin']
    searchMot = request.POST['inMot']
    searchTrans = request.POST['inTrans']
    condition_mot = request.POST['condition-mot'] if request.POST.get('inMot') else 'contient'
    condition_trans = request.POST['condition-trans'] if request.POST.get('inTrans') else 'contient'

    txtphono.modifEntry(motOrigin,mot,trans)
    
    data = Entree()
    data.mot = searchMot
    data.trans = searchTrans
    data.motcond = condition_mot
    data.transcond = condition_trans
    data.result = txtphono.getEntryByWord(m=data.mot, mc=data.motcond, t=data.trans, tc=data.transcond)
    data.nb = len(data.result)
    
    return render(request, 'editDico.html', {'data': data})