Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ff2balex
Manage
Activity
Members
Labels
Plan
Issues
9
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lex gaMe
ff2balex
Commits
afdee4e1
Commit
afdee4e1
authored
5 months ago
by
Lucie Bader
Browse files
Options
Downloads
Patches
Plain Diff
Correction balex_id -> internal_id
parent
47434a3b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utils/definitions.js
+22
-21
22 additions, 21 deletions
src/utils/definitions.js
with
22 additions
and
21 deletions
src/utils/definitions.js
+
22
−
21
View file @
afdee4e1
...
@@ -58,6 +58,7 @@ async function fetchLexiconDefinitions(word) {
...
@@ -58,6 +58,7 @@ async function fetchLexiconDefinitions(word) {
return
{
lexiconId
:
lex
.
id
,
entries
:
[]
};
return
{
lexiconId
:
lex
.
id
,
entries
:
[]
};
}
}
const
entries
=
await
searchResponse
.
json
();
const
entries
=
await
searchResponse
.
json
();
log
(
"
Entrées récupérées :
"
,
entries
);
// Filtrage côté client : ne garder que les entrées dont entry.lexicon.id correspond exactement à lex.id
// Filtrage côté client : ne garder que les entrées dont entry.lexicon.id correspond exactement à lex.id
const
filteredEntries
=
entries
.
filter
(
entry
=>
{
const
filteredEntries
=
entries
.
filter
(
entry
=>
{
...
@@ -91,7 +92,7 @@ async function fetchLexiconDefinitions(word) {
...
@@ -91,7 +92,7 @@ async function fetchLexiconDefinitions(word) {
}
}
}
}
const
balexId
=
entry
.
balex
_id
||
null
;
const
balexId
=
entry
.
internal
_id
||
null
;
items
.
forEach
(
item
=>
{
items
.
forEach
(
item
=>
{
const
definitionsArray
=
item
.
Sense
?.
Definitions
;
const
definitionsArray
=
item
.
Sense
?.
Definitions
;
...
@@ -109,7 +110,7 @@ async function fetchLexiconDefinitions(word) {
...
@@ -109,7 +110,7 @@ async function fetchLexiconDefinitions(word) {
allDefinitions
.
push
({
allDefinitions
.
push
({
source
:
sourceName
,
source
:
sourceName
,
text
:
defObj
.
Def
,
text
:
defObj
.
Def
,
balex
_id
:
balexId
,
internal
_id
:
balexId
,
pronunciations
:
pronunciations
,
pronunciations
:
pronunciations
,
lexiconId
:
lexiconId
lexiconId
:
lexiconId
});
});
...
@@ -145,7 +146,7 @@ async function fetchWiktionaryDefinition(word) {
...
@@ -145,7 +146,7 @@ async function fetchWiktionaryDefinition(word) {
if
(
!
authToken
)
{
if
(
!
authToken
)
{
log
(
`Requête Wiktionnaire pour "
${
word
}
"...`
);
log
(
`Requête Wiktionnaire pour "
${
word
}
"...`
);
if
(
!
word
||
word
.
trim
()
===
""
)
{
if
(
!
word
||
word
.
trim
()
===
""
)
{
throw
new
Error
(
"
️
Mot vide, impossible d'envoyer la requête.
"
);
throw
new
Error
(
`
Mot vide, impossible d'envoyer la requête.
`
);
}
}
const
wiktionaryURL
=
`https://fr.wiktionary.org/w/api.php?action=query&format=json&origin=*&prop=extracts&explaintext=true&redirects=1&titles=
${
encodeURIComponent
(
word
)}
`
;
const
wiktionaryURL
=
`https://fr.wiktionary.org/w/api.php?action=query&format=json&origin=*&prop=extracts&explaintext=true&redirects=1&titles=
${
encodeURIComponent
(
word
)}
`
;
...
@@ -341,7 +342,7 @@ function displayDefinitions(definitions) {
...
@@ -341,7 +342,7 @@ function displayDefinitions(definitions) {
const
noLexiconDefinitionsContainer
=
document
.
getElementById
(
"
noLexiconDefinitionsContainer
"
);
const
noLexiconDefinitionsContainer
=
document
.
getElementById
(
"
noLexiconDefinitionsContainer
"
);
const
noWiktionaryDefinitionsContainer
=
document
.
getElementById
(
"
noWiktionaryDefinitionsContainer
"
);
const
noWiktionaryDefinitionsContainer
=
document
.
getElementById
(
"
noWiktionaryDefinitionsContainer
"
);
const
balex
IdMap
=
new
Map
();
// Dictionnaire pour stocker
balex
_id par lexique
const
internal
IdMap
=
new
Map
();
// Dictionnaire pour stocker
internal
_id par lexique
// Nettoyage des listes existantes
// Nettoyage des listes existantes
mesLexiquesList
.
innerHTML
=
""
;
mesLexiquesList
.
innerHTML
=
""
;
...
@@ -355,9 +356,9 @@ function displayDefinitions(definitions) {
...
@@ -355,9 +356,9 @@ function displayDefinitions(definitions) {
let
hasWiktionaryDefinitions
=
false
;
let
hasWiktionaryDefinitions
=
false
;
const
lexiconGroups
=
{};
const
lexiconGroups
=
{};
definitions
.
forEach
(({
source
,
text
,
balex
_id
,
definitionsByPOS
})
=>
{
definitions
.
forEach
(({
source
,
text
,
internal
_id
,
definitionsByPOS
})
=>
{
if
(
!
source
||
!
text
)
return
;
if
(
!
source
||
!
text
)
return
;
log
(
`Traitement de
${
source
}
,
balex_id:`
,
balex
_id
);
log
(
`Traitement de
${
source
}
,
internal_id:`
,
internal
_id
);
const
definitionContainer
=
document
.
createElement
(
"
div
"
);
const
definitionContainer
=
document
.
createElement
(
"
div
"
);
definitionContainer
.
classList
.
add
(
"
definition-item
"
);
definitionContainer
.
classList
.
add
(
"
definition-item
"
);
...
@@ -369,9 +370,9 @@ function displayDefinitions(definitions) {
...
@@ -369,9 +370,9 @@ function displayDefinitions(definitions) {
li
.
textContent
=
text
;
li
.
textContent
=
text
;
definitionContainer
.
appendChild
(
li
);
definitionContainer
.
appendChild
(
li
);
// Stocker le premier `
balex
_id` trouvé pour chaque lexique
// Stocker le premier `
internal
_id` trouvé pour chaque lexique
if
(
!
balex
IdMap
.
has
(
source
)
&&
balex
_id
)
{
if
(
!
internal
IdMap
.
has
(
source
)
&&
internal
_id
)
{
balex
IdMap
.
set
(
source
,
balex
_id
);
internal
IdMap
.
set
(
source
,
internal
_id
);
}
}
// Ajout dans le bon groupe
// Ajout dans le bon groupe
if
(
!
lexiconGroups
[
source
])
{
if
(
!
lexiconGroups
[
source
])
{
...
@@ -510,7 +511,7 @@ function displayDefinitions(definitions) {
...
@@ -510,7 +511,7 @@ function displayDefinitions(definitions) {
headerContainer
.
appendChild
(
lexiconHeader
);
headerContainer
.
appendChild
(
lexiconHeader
);
const
balexButton
=
createBaLexButton
(
lexiconName
,
balex
IdMap
);
const
balexButton
=
createBaLexButton
(
lexiconName
,
internal
IdMap
);
if
(
balexButton
)
{
if
(
balexButton
)
{
balexButton
.
style
.
position
=
"
absolute
"
;
balexButton
.
style
.
position
=
"
absolute
"
;
balexButton
.
style
.
top
=
"
50%
"
;
balexButton
.
style
.
top
=
"
50%
"
;
...
@@ -702,7 +703,7 @@ function displayLexiconResults(lexicons) {
...
@@ -702,7 +703,7 @@ function displayLexiconResults(lexicons) {
lexicons
.
forEach
((
lexicon
)
=>
{
lexicons
.
forEach
((
lexicon
)
=>
{
if
(
!
lexicon
)
{
if
(
!
lexicon
)
{
console
.
warn
(
"
️
Lexique incorrect :
"
,
lexicon
);
console
.
warn
(
"
️Lexique incorrect :
"
,
lexicon
);
return
;
return
;
}
}
if
(
!
lexicon
.
id
)
{
if
(
!
lexicon
.
id
)
{
...
@@ -724,22 +725,22 @@ function displayLexiconResults(lexicons) {
...
@@ -724,22 +725,22 @@ function displayLexiconResults(lexicons) {
/**
/**
* Crée un bouton permettant d'ouvrir une entrée dans BaLex.
* Crée un bouton permettant d'ouvrir une entrée dans BaLex.
* @param {string} lexiconName - Le nom du lexique.
* @param {string} lexiconName - Le nom du lexique.
* @param {Map}
balex
IdMap - Une Map contenant les
balex
_id associés aux lexiques.
* @param {Map}
internal
IdMap - Une Map contenant les
internal
_id associés aux lexiques.
* @returns {HTMLElement|null} - Un bouton HTML ou null si `
balex
_id` est manquant.
* @returns {HTMLElement|null} - Un bouton HTML ou null si `
internal
_id` est manquant.
*/
*/
function
createBaLexButton
(
lexiconName
,
balex
IdMap
)
{
function
createBaLexButton
(
lexiconName
,
internal
IdMap
)
{
const
balexServ
=
"
babalex.lezinter.net
"
;
const
balexServ
=
"
babalex.lezinter.net
"
;
const
balex_id
=
balex
IdMap
.
get
(
lexiconName
)
||
null
;
const
internal_id
=
internal
IdMap
.
get
(
lexiconName
)
||
null
;
log
(
`ID BaLex trouvé pour "
${
lexiconName
}
" :`
,
balex
_id
);
log
(
`ID BaLex trouvé pour "
${
lexiconName
}
" :`
,
internal
_id
);
// Vérifie si `
balex
_id` est valide
// Vérifie si `
internal
_id` est valide
if
(
!
balex
_id
)
{
if
(
!
internal
_id
)
{
console
.
warn
(
`
️
Aucun
balex
_id trouvé pour "
${
lexiconName
}
". Bouton non créé.`
);
console
.
warn
(
`Aucun
internal
_id trouvé pour "
${
lexiconName
}
". Bouton non créé.`
);
return
null
;
return
null
;
}
}
const
balexUrl
=
`https://
${
balexServ
}
/entry/
${
balex
_id
}
/show`
;
const
balexUrl
=
`https://
${
balexServ
}
/entry/
${
internal
_id
}
/show`
;
// Création du bouton
// Création du bouton
const
balexButton
=
document
.
createElement
(
"
img
"
);
const
balexButton
=
document
.
createElement
(
"
img
"
);
...
@@ -753,7 +754,7 @@ function createBaLexButton(lexiconName, balexIdMap) {
...
@@ -753,7 +754,7 @@ function createBaLexButton(lexiconName, balexIdMap) {
// Ajout du lien
// Ajout du lien
balexButton
.
addEventListener
(
"
click
"
,
(
event
)
=>
{
balexButton
.
addEventListener
(
"
click
"
,
(
event
)
=>
{
event
.
stopPropagation
();
//
event.stopPropagation();
window
.
open
(
balexUrl
,
"
_blank
"
);
window
.
open
(
balexUrl
,
"
_blank
"
);
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment