Commit fe58d129 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

modification structure dictionnaire et page editDico

parent 32e92c35
......@@ -22,6 +22,10 @@ class Entree:
message: str
update: str
class DicEntry:
mot: str
trans: str
class commitData:
update: str
listCommits: str
\ No newline at end of file
from django.shortcuts import render, HttpResponseRedirect
from static.scripts import textPhonographer as txtphono
from .models import Phonograph, Data, Entree, commitData
from django.http import JsonResponse
import json
import spacy
import subprocess
import re
nlp = spacy.load('fr')
def redirApp(request):
......@@ -73,17 +77,19 @@ def main0(request):
def dicoView(request):
data = Entree()
data.update = updateTime()
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 dicoReq(request):
listeEntrees = []
mot = request.GET.get('mot', None)
trans = request.GET.get('trans', None)
motCond = request.GET.get('motCond', None)
transCond = request.GET.get('transCond', None)
listeEntrees = txtphono.getEntryByWord(m=mot,mc=motCond,t=trans,tc=transCond)
return JsonResponse(listeEntrees, safe=False)
def editEntry(request,Type):
mot = request.POST['entreeMot']# if request.POST.get('mot') else ''
trans = request.POST['entreeTrans']# if request.POST.get('trans') else ''
......
......@@ -16,7 +16,7 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from hello.views import loginView, signinView, addUser
from colorapp.views import main, dicoView, editEntry, redirApp, main0
from colorapp.views import main, dicoView, editEntry, redirApp, main0, dicoReq
urlpatterns = [
path('admin/', admin.site.urls),
......@@ -26,5 +26,6 @@ urlpatterns = [
path('app/', main),
path('app/0', main0),
path('app/dico/', dicoView),
path('dicoSearch/', dicoReq),
path('app/dico/edit/<str:Type>/', editEntry)
]
$(document).ready(function(){
console.log('Ready.');
$("#rechercher").click(function(){
var mot = document.getElementById('inMot').value;
var trans = document.getElementById('inTrans').value;
var motCond = document.getElementById('condition-mot').value;
var transCond = document.getElementById('condition-trans').value;
if (mot.length > 0 || trans.length > 0) {
document.getElementById('resultTable').innerHTML = '<colgroup><col width="40%"><col width="40%"><col width="20%"></colgroup><tr><th>Mot</th><th>Transcription (API)</th><th>Actions</th></tr>';
document.getElementById('nbres').innerHTML = '...';
document.getElementById('loader').style.display = '';
document.body.style.cursor = "wait";
console.log(motCond,mot,transCond,trans);
//variable qui contiendra le dictionnaire de listes de graphies
var reponseDico = new Object();
//requête qui récupère la liste de graphies pour chaque phonème
$.ajax({
url: '/dicoSearch/',
data: {
mot: mot,
trans: trans,
motCond: motCond,
transCond: transCond
},
dataType: 'json',
success: function(data) {listEntries(data)},
error: function(){
document.getElementById('loader').style.display = 'none';
document.body.style.cursor = "default";
console.log("Problème de requête !");
}
});
} else window.alert('Veuillez entrer une requête de recherche.');
function listEntries(data) {
document.getElementById('loader').style.display = 'none';
document.body.style.cursor = "default";
document.getElementById('resultTable').innerHTML = '<colgroup><col width="40%"><col width="40%"><col width="20%"></colgroup><tr><th>Mot</th><th>Transcription (API)</th><th>Actions</th></tr>';
console.log(data.length + ' résultats.');
document.getElementById('nbres').innerHTML = data.length;
var cptEntr = 0;
for (i in data) {
cptEntr += 1;
var entr = data[i][0];
var lienWiki = '<button role="button" class="btn btn-sm"><a href="https://fr.wiktionary.org/wiki/'+entr.replace(' ','_')+'" target="_blank"><svg class="wikiLienIcon" aria-hidden="true" focusable="false" data-prefix="fab" data-icon="wikipedia-w" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512" data-fa-i2svg=""><path fill="currentColor" d="M640 51.2l-.3 12.2c-28.1.8-45 15.8-55.8 40.3-25 57.8-103.3 240-155.3 358.6H415l-81.9-193.1c-32.5 63.6-68.3 130-99.2 193.1-.3.3-15 0-15-.3C172 352.3 122.8 243.4 75.8 133.4 64.4 106.7 26.4 63.4.2 63.7c0-3.1-.3-10-.3-14.2h161.9v13.9c-19.2 1.1-52.8 13.3-43.3 34.2 21.9 49.7 103.6 240.3 125.6 288.6 15-29.7 57.8-109.2 75.3-142.8-13.9-28.3-58.6-133.9-72.8-160-9.7-17.8-36.1-19.4-55.8-19.7V49.8l142.5.3v13.1c-19.4.6-38.1 7.8-29.4 26.1 18.9 40 30.6 68.1 48.1 104.7 5.6-10.8 34.7-69.4 48.1-100.8 8.9-20.6-3.9-28.6-38.6-29.4.3-3.6 0-10.3.3-13.6 44.4-.3 111.1-.3 123.1-.6v13.6c-22.5.8-45.8 12.8-58.1 31.7l-59.2 122.8c6.4 16.1 63.3 142.8 69.2 156.7L559.2 91.8c-8.6-23.1-36.4-28.1-47.2-28.3V49.6l127.8 1.1.2.5z"></path></svg></a></button>';
var transList = '';
for (j in data[i][1]) {
transList += data[i][1][j];
if (j < data[i][1].length-1) transList += ', '
}
var btnModifier = '<button id="btnModifier'+cptEntr+'" class="btn btn-primary btn-perso" onclick="modifEntry('+cptEntr+',\''+entr+'\')"><span class="glyphicon glyphicon-edit" area-hidden="true" title="Modifier"></span></button>';
var btnValider = '<button id="btnValider'+cptEntr+'" class="btn btn-success btn-perso" style="display: none;"><span class="glyphicon glyphicon-ok" area-hidden="true" title="Valider"></span></button>';
var btnAnnuler = '<button id="btnAnnuler'+cptEntr+'" class="btn btn-secondary btn-perso" style="display: none;" onclick="annuler('+cptEntr+')"><span class="glyphicon glyphicon-remove" area-hidden="true" title="Annuler"></span></button>';
document.getElementById('resultTable').innerHTML += '<tr id="tr'+cptEntr+'" class="tr"><td>'+lienWiki+' '+entr+'</td><td><input class="api-kb" disabled="true" type="text" id="td'+cptEntr+'" value="'+transList+'"></td><td style="text-align:center">'+btnModifier+btnValider+btnAnnuler+'</td></tr>';
getAPIkeyboard();
}
if (cptEntr >= 300) window.alert('Trop de résultats ! Merci de préciser un peu plus votre recherche :)')
}
});
});
var entrActif = 0;
function modifEntry(cptEntr,entr) {
if (entrActif > 0) annuler(entrActif); // désélectionne la ligne active, si elle existe.
entrActif = cptEntr;
var thisTr = 'tr'+cptEntr;
var thisTd = 'td'+cptEntr;
thisTr = document.getElementById(thisTr);
thisTd = document.getElementById(thisTd);
var thisBtnModifier = 'btnModifier'+cptEntr;
var thisBtnValider = 'btnValider'+cptEntr;
var thisBtnAnnuler = 'btnAnnuler'+cptEntr;
thisBtnModifier = document.getElementById(thisBtnModifier);
thisBtnValider = document.getElementById(thisBtnValider);
thisBtnAnnuler = document.getElementById(thisBtnAnnuler);
thisTr.style.backgroundColor = "lightgreen";
thisTd.classList.add('editTrans');
thisTd.disabled = false;
thisTd.focus();
thisBtnModifier.style.display = 'none';
thisBtnValider.style.display = '';
thisBtnAnnuler.style.display = '';
}
function annuler(cptEntr) {
var thisTr = 'tr'+cptEntr;
var thisTd = 'td'+cptEntr;
thisTr = document.getElementById(thisTr);
thisTd = document.getElementById(thisTd);
var thisBtnModifier = 'btnModifier'+cptEntr;
var thisBtnValider = 'btnValider'+cptEntr;
var thisBtnAnnuler = 'btnAnnuler'+cptEntr;
thisBtnModifier = document.getElementById(thisBtnModifier);
thisBtnValider = document.getElementById(thisBtnValider);
thisBtnAnnuler = document.getElementById(thisBtnAnnuler);
thisTr.style.backgroundColor = "";
thisTd.classList.remove('editTrans');
thisTd.disabled = true;
thisBtnModifier.style.display = '';
thisBtnValider.style.display = 'none';
thisBtnAnnuler.style.display = 'none';
entrActif = 0;
}
\ No newline at end of file
......@@ -9,24 +9,27 @@ $.keyboard.keyaction.redo = function (base) {
return false;
};
var apizones = Object.entries($('.api-kb'));
getAPIkeyboard();
function getAPIkeyboard() {
var apizones = Object.entries($('.api-kb'));
for (i = 0 ; i < apizones.length-2 ; i++) {
$(apizones[i][1]).keyboard({
usePreview: false, // disabled for contenteditable
useCombos: false,
autoAccept: true,
layout: 'custom',
customLayout: {
'normal': [
'ɑ ɔ ə ɛ ø œ ɥ ‿ \u0303',
'ɡ ʁ ʃ ʒ ɲ ŋ'
],
},
display: {
del: '\u2326:Delete',
redo: '',
undo: ''
}
});
};
for (i = 0 ; i < apizones.length-2 ; i++) {
$(apizones[i][1]).keyboard({
usePreview: false, // disabled for contenteditable
useCombos: false,
autoAccept: true,
layout: 'custom',
customLayout: {
'normal': [
'ɑ ɔ ə ɛ ø œ ɥ ‿ \u0303',
'ɡ ʁ ʃ ʒ ɲ ŋ'
],
},
display: {
del: '\u2326:Delete',
redo: '',
undo: ''
}
});
};
}
......@@ -15,7 +15,8 @@ import re
import sys
import os
import datetime
from colorapp.models import Entree
import json
from colorapp.models import Entree, DicEntry
import tempfile
import csv
......@@ -26,8 +27,8 @@ from phon2graph import decoupage
# FICHIERS
phonColFile = "../phon2graph/data/class-phoneme_v2.csv"
phonGraphFile = "../phon2graph/data/phoneme-graphies_fr.scsv"
dicFile = "../wikiphon/dico_frwiktionary-20200301-alpha.csv"
logFile = "../logs/dico_frwiktionary-20200301-alpha.log"
dicFile = "../wikiphon/dico_frwiktionary-20200301_v2.json"
logFile = "../logs/dico_frwiktionary-20200301_v2.log"
# LECTURE DU CODE PHONEME-COULEUR
phonFile = open(phonColFile,mode="r")
......@@ -67,36 +68,12 @@ phonFile.close()
# LECTURE DU DICTIONNAIRE
dicoFile = open(dicFile,mode="r")
word2trans = {} # un mot → liste de trans
wordCpt = 0
for line in dicoFile:
line = line.strip()
l = line.split('§')
if len(l) == 2:
mot,trans = l
wordCpt += 1
mot = mot.lower()
if mot not in word2trans.keys():
word2trans[mot] = []
if trans not in word2trans[mot]:
word2trans[mot].append(trans)
## STATS DICO
# cpti = 0
# cptj = 0
# for i,j in word2trans.items():
# cpti += 1
# for c in j:
# cptj += 1
# print("Mots parsés :",wordCpt)
# print("Mots dans le dico :",len(word2trans.keys()), cpti)
# print("Nb de transcriptions enregistrées :",cptj)
dicoFile.close()
word2trans = {} # un mot → liste de trans possibles
with open(dicFile, 'r') as f:
word2trans = json.load(f)
print('len frwiki :',len(word2trans))
def mimi(mot):
# Enregistrement de la casse
......@@ -153,12 +130,15 @@ def getEntryByWord(m,mc,t,tc):
tc2 = r'$'
for entree,transList in word2trans.items():
for i,trans in enumerate(transList):
if re.match(mc1+m+mc2,entree) and re.match(tc1+t+tc2,trans):
yeah = Entree()
yeah.mot = entree
yeah.trans = word2trans[entree][i]
result.append(yeah)
if len(result) >= 300:
break
if re.match(mc1+m+mc2,entree):
resTrans = []
for i,trans in enumerate(transList):
if re.match(tc1+t+tc2,trans):
resTrans.append(trans)
result.append((entree,resTrans))
print(entree)
return result
'''
def modifEntry(motOrigin,mot,trans):
......
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 100px;
height: 100px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
margin: 30px;
}
/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
\ No newline at end of file
......@@ -180,6 +180,57 @@ textarea {
margin: 5px;
}
.loaderDiv {
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #4d4343a4;
cursor: wait;
}
.loaderDiv div {
position: absolute;
top: 40%;
}
#resultTable {
width: 90%;
margin: auto;
border: solid 1px black;
table-layout:fixed;
}
th td {
overflow: hidden;
display: inline-block;
white-space: nowrap;
}
th {
background-color: lightblue;
border: solid 1px black;
text-align: center;
font-style: italic;
}
td {
text-align: left;
background: none;
border: lightblue 1px solid;
}
tr:hover {
background-color: lightcyan;
}
.trgris {
background-color: gray;
}
.wikiLienIcon {
display: inline-block;
font-size: inherit;
height: 1em;
}
.dicEntry {
display: -ms-flexbox; /* IE10 */
display: flex;
......@@ -189,11 +240,31 @@ textarea {
margin: 3px auto;
text-align: left;
}
.dicEntryHead {
font-style: italic;
color: gray;
}
.btn-perso {
margin:2px;
}
.editTrans {
box-shadow: inset 0 0 7px 1px lightgreen;
background-color: white;
}
input[type="text"]:disabled {
background: white;
color: black;
border: inset 1px;
}
.btn-secondary:hover {
background-color: gray;
}
footer {
margin-top: 20px;
font-style: italic;
......
......@@ -2,8 +2,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Coloriseur phonographémique</title>
<title>WikiColor</title>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/png" href="{% static 'wikicolor.ico' %}"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static 'styles/kinephones_style_v2.css'%}">
<link rel="stylesheet" type="text/css" href="{% static 'styles/styles.css'%}">
......@@ -13,6 +14,7 @@
</head>
<body>
{% include 'header.html' %}
<img src="{% static 'im/logo_wikicolor6b.png'%}" width="40%" title="WikiColor">
<h2>
<span class="phon_k">C</span><span class="phon_o_maj">o</span><span class="phon_l">l</span><span class="phon_o_maj">o</span><span class="phon_r_maj">r</span><span class="phon_i">i</span><span class="phon_z">s</span><span class="phon_9">eu</span><span class="phon_r_maj">r</span>
<span> </span><span class="phon_f">Ph</span><span class="phon_o_maj">o</span><span class="phon_n">n</span><span class="phon_o_maj">o</span><span class="phon_g">g</span><span class="phon_r_maj">r</span><span class="phon_a">a</span><span class="phon_f">ph</span><span class="phon_e">é</span><span class="phon_m">m</span><span class="phon_i">i</span><span class="phon_k">que</span>
......@@ -58,7 +60,7 @@
<h2>Copier/coller le résultat</h2>
</div>
<div class="modal-body">
<p>Le texte ci-dessous peut être copié-collé dans Word, LibreOffice ou dans un email, par exemple.</p>
<p>Copier/coller le texte ci-dessous dans LibreOffice, Word ou dans un e-mail, par exemple.</p>
<div id="pLienDiv" contenteditable="true" class="pLienDiv" style="background-color: #000000; font-weight: bold;"></div>
<div class="copyButton">
<button onclick="toClipBoard('pLienDiv','myTooltip')" onmouseout="outFunc()"><span class="copyButtonText" id="myTooltip">Copier</span>Copier</button>
......
......@@ -3,80 +3,69 @@
<html>
<head>
<title>WikiColor - Dictionnaire</title>
<link rel="shortcut icon" type="image/png" href="{% static 'wikicolor.ico' %}"/>
<meta charset="utf-8">
<!-- keyboard widget css & script (required) -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="{% static 'scripts/jquery.keyboard.js'%}"></script>
<link href="{% static 'styles/keyboard-dark.css'%}" rel="stylesheet">
<link href="{% static 'styles/loading.css'%}" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static 'styles/styles.css'%}">
</head>
<body>
{% include 'header.html' %}
<div class="editDico">
<form action="/app/dico/" method="POST">{% csrf_token %}
<h2>Rechercher une entrée du dictionnaire</h2>
<div class="searchWindow">
<div class="input">
Mot :<br/>
<div class="searchWindow">
<select class="form-control searchCondition" name="condition-mot">
<option {% if data.motcond == "contient" %} selected {% endif %}>contient</option>
<option {% if data.motcond == "commence par" %} selected {% endif %}>commence par</option>
<option {% if data.motcond == "finit par" %} selected {% endif %}>finit par</option>
<option {% if data.motcond == "est égal à" %} selected {% endif %}>est égal à</option>
</select>
<input class="searchField" name="inMot" type="text" value="{{ data.mot }}"/>
</div>
</div>
<div class="input">
Transcription (API) : <br/>
<div class="searchWindow">
<select class="form-control searchCondition" name="condition-trans">
<option {% if data.transcond == "contient" %} selected {% endif %}>contient</option>
<option {% if data.transcond == "commence par" %} selected {% endif %}>commence par</option>
<option {% if data.transcond == "finit par" %} selected {% endif %}>finit par</option>
<option {% if data.transcond == "est égal à" %} selected {% endif %}>est égal à</option>
</select>
<input id="kb2" class="searchField api-kb" name="inTrans" type="text" value="{{ data.trans }}"/>
</div>
<h2>Rechercher une entrée du dictionnaire</h2>
<div class="searchWindow">
<div class="input">
Mot :<br/>
<div class="searchWindow">
<select class="form-control searchCondition" id="condition-mot">
<option selected>contient</option>
<option>commence par</option>
<option>finit par</option>
<option>est égal à</option>
</select>
<input class="searchField" id="inMot" type="text" value=""/>
</div>
</div>
<input id="rechercher" type="submit" value="Rechercher"/>
</form>
<div class="result">
<h3>Résultats de la recherche ({{ data.nb }})</h3>
{% for result in data.result %}
<div class="dicEntry">
<form method="POST" onsubmit="return confirm('Êtes-vous sûr de vouloir modifier cette entrée ?');">{% csrf_token %}
<input type="hidden" name="inMot" value="{{ data.mot }}"/>
<input type="hidden" name="inTrans" value="{{ data.trans }}"/>
<input type="hidden" name="motOrigin" value="{{ result.mot }}"/>
<input type="hidden" name="condition-mot" value="{{ data.motcond }}"/>
<input type="hidden" name="condition-trans" value="{{ data.transcond }}"/>
<span class="dicEntryHead">Mot : </span><input name="entreeMot" type="text" value="{{ result.mot }}"/>
<span class="dicEntryHead">Trans : </span><input class="api-kb" name="entreeTrans" type="text" value="{{ result.trans }}"/>
<button type="submit" onclick="window.alert('Fonction désactivée pour le moment')" {#formaction="/app/dico/edit/MODIF/"#} class="btn btn-light" title="Enregistrer les modifications">Éditer</button>
<button type="submit" onclick="window.alert('Fonction désactivée pour le moment')" {#formaction="/app/dico/edit/DELETE/"#} class="btn btn-danger" title="Supprimer l'entrée du dictionnaire"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</form>
<div class="input">
Transcription (API) : <br/>
<div class="searchWindow">
<select class="form-control searchCondition" id="condition-trans">
<option selected>contient</option>
<option>commence par</option>
<option>finit par</option>
<option>est égal à</option>
</select>
<input id="inTrans" class="searchField api-kb" type="text" value=""/>
</div>
{% endfor %}
<div class="dicEntry">
<form id="hiddenFields" method="POST">{% csrf_token %}
<input type="hidden" name="inMot" value="{{ data.mot }}"/>
<input type="hidden" name="inTrans" value="{{ data.trans }}"/>
<input type="hidden" name="motOrigin" value="{{ result.mot }}"/>
<input type="hidden" name="condition-mot" value="{{ data.motcond }}"/>
<input type="hidden" name="condition-trans" value="{{ data.transcond }}"/>
<input name="entreeMot" type="text" value=""/>
<input id="kb" class="api-kb" name="entreeTrans" type="text" value=""/>
<button type="submit" onclick="window.alert('Fonction désactivée pour le moment')" {#formaction="/app/dico/edit/ADD/"#} class="btn btn-success" title="Ajouter cette entrée"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</form>
<button id="btnAddEntry" type="submit" class="btn btn-light" title="Ajouter une entrée"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</div>
</div>
<button id="rechercher" title="Rechercher dans le dictionnaire">Rechercher</button>
<div class="result">
<h3>Résultats de la recherche (<span id="nbres"></span>)</h3>
<table id="resultTable">
<colgroup>
<col width="40%" />
<col width="40%" />
<col width="20%" />
</colgroup>
<tr>
<th>Mot</th>
<th>Transcri