Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Base lexicale BaLex
Manage
Activity
Members
Labels
Plan
Issues
18
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
Base lexicale BaLex
Commits
b85bda6c
Commit
b85bda6c
authored
1 year ago
by
pfleu
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'liris/master' into dev_pierre_202401
parents
c39535f9
47098bda
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Manager/SuccessManager.php
+1
-1
1 addition, 1 deletion
src/Manager/SuccessManager.php
src/Manager/WiktionaryManager.php
+44
-35
44 additions, 35 deletions
src/Manager/WiktionaryManager.php
src/Twig/AppTwigExtension.php
+12
-3
12 additions, 3 deletions
src/Twig/AppTwigExtension.php
with
57 additions
and
39 deletions
src/Manager/SuccessManager.php
+
1
−
1
View file @
b85bda6c
...
@@ -124,7 +124,7 @@ class SuccessManager
...
@@ -124,7 +124,7 @@ class SuccessManager
}
}
}
}
$currentMilestone
=
$success
->
getCurrentMilestone
();
$currentMilestone
=
$success
->
getCurrentMilestone
();
if
(
$newPosition
>
$currentMilestone
)
{
if
(
$newPosition
>
$currentMilestone
&&
$currentMilestone
<
count
(
$successMilestones
)
-
1
)
{
$success
->
setCurrentMilestone
(
$newPosition
);
$success
->
setCurrentMilestone
(
$newPosition
);
$success
->
getUser
()
->
setUserPoints
(
$success
->
getUser
()
->
getUserPoints
()
+
$success
->
getSuccessPoints
()[
$currentMilestone
]);
$success
->
getUser
()
->
setUserPoints
(
$success
->
getUser
()
->
getUserPoints
()
+
$success
->
getSuccessPoints
()[
$currentMilestone
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Manager/WiktionaryManager.php
+
44
−
35
View file @
b85bda6c
...
@@ -12,6 +12,9 @@ use Symfony\Component\HttpFoundation\Response;
...
@@ -12,6 +12,9 @@ use Symfony\Component\HttpFoundation\Response;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Serializer\SerializerAwareInterface
;
use
Symfony\Component\Serializer\SerializerAwareInterface
;
use
Symfony\Component\Serializer\SerializerInterface
;
use
Symfony\Component\Serializer\SerializerInterface
;
use
Symfony\Component\HttpClient\HttpClient
;
use
Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
;
use
Symfony\Component\HttpClient\Exception\ClientException
;
class
WiktionaryManager
class
WiktionaryManager
{
{
...
@@ -33,6 +36,7 @@ class WiktionaryManager
...
@@ -33,6 +36,7 @@ class WiktionaryManager
* @param $word
* @param $word
* @param $language
* @param $language
* @return mixed
* @return mixed
* @throws \Exception|TransportExceptionInterface
*/
*/
public
function
search
(
$word
,
$language
)
public
function
search
(
$word
,
$language
)
{
{
...
@@ -42,41 +46,44 @@ class WiktionaryManager
...
@@ -42,41 +46,44 @@ class WiktionaryManager
return
$this
->
lastSearch
[
'data'
];
return
$this
->
lastSearch
[
'data'
];
}
}
// usage: wikstraktor.py [-h] [-l LANGUAGE] [-w WIKI_LANGUAGE] [-m MOT]
//$time_start = microtime(true); /*Debug*/
// [-f DESTINATION_FILE] [-A] [-C]
//
$url
=
'http://localhost:5000/search/'
.
$language
.
'/'
.
$language
.
'/'
.
$word
.
'/a_wikstraktor'
;
// Interroger un wiktionnaire
$client
=
HttpClient
::
create
();
// ex :
$result
=
null
;
// ‣./wikstraktor.py -m blue
// ‣./wikstraktor.py -m blue -f blue.json -A -C
// Make the initial request with a timeout
// ‣./wikstraktor.py -l en -w fr -m blue -f blue.json -A -C
try
{
$response
=
$client
->
request
(
'GET'
,
$url
);
// options:
// dump($response->getStatusCode());die();
// -h, --help show this help message and exit
// -l LANGUAGE, --language LANGUAGE
// Check the HTTP status code
// la langue du mot
if
(
$response
->
getStatusCode
()
===
200
)
{
// -w WIKI_LANGUAGE, --wiki_language WIKI_LANGUAGE
// Server is up and returned a successful response
// la langue du wiki
$result
=
$response
->
getContent
();
// -m MOT, --mot MOT le mot à chercher
}
// -f DESTINATION_FILE, --destination_file DESTINATION_FILE
}
catch
(
TransportExceptionInterface
$exception
)
{
// le fichier dans lequel stocker le résultat
if
(
empty
(
exec
(
'ps aux | grep "[a]pp.py"'
)))
{
// -A, --force_ascii json avec que des caractères ascii
// Server is down, restart it
// -C, --compact json sans indentation
exec
(
'nohup /var/www/live-query-wiktextract/venv/bin/python3 /var/www/live-query-wiktextract/src/app.py'
);
if
(
!
empty
(
exec
(
'ps aux | grep "[a]pp.py"'
)))
{
$response
=
$client
->
request
(
'GET'
,
$url
);
//$time_start = microtime(true); /*Debug*/
if
(
$response
->
getStatusCode
()
===
200
)
{
if
(
$_ENV
[
'WIKTIONARY_TOOL'
]
==
'WIKSTRAKTOR'
)
{
// Server is up and returned a successful response
$command
=
$_ENV
[
'WIKSTRAKTOR_COMMAND'
]
.
' -l '
.
$language
.
' -w '
.
$language
.
' -m "'
.
$word
.
'" -A -C 2>&1'
;
$result
=
$response
->
getContent
();
}
else
{
}
$command
=
$_ENV
[
'WIKTEXTRACT_COMMAND'
]
.
' -l '
.
$language
.
' -w '
.
$language
.
' -e "'
.
$word
.
'"'
.
' -zA 2>&1'
;
}
else
{
throw
new
\Exception
(
'Server is down'
);
}
}
}
}
$result
=
exec
(
$command
);
//dump(gettype($result));dump($url);dump(microtime(true)-$time_start);dump($result);/*Debug*/
//dump($word);dump($command);dump(microtime(true)-$time_start);dump($result);die();/*Debug*/
// Output and error handling
// Output and error handling
$dataArray
=
json_decode
(
$result
,
true
);
$dataArray
=
json_decode
(
$result
,
true
);
//dump(gettype($dataArray));dump($dataArray);die();/*Debug*/
// On sauvegarde la recherche pour optimiser le nb de requêtes vers le wiktionnaire
// On sauvegarde la recherche pour optimiser le nb de requêtes vers le wiktionnaire
$this
->
lastSearch
=
[
$this
->
lastSearch
=
[
...
@@ -87,8 +94,7 @@ class WiktionaryManager
...
@@ -87,8 +94,7 @@ class WiktionaryManager
//dump(json_last_error());
//dump(json_last_error());
//dump(json_last_error_msg());
//dump(json_last_error_msg());
//dump($dataArray);die(); Wiktionary
//dump($dataArray);die();
return
$dataArray
;
return
$dataArray
;
}
}
...
@@ -135,14 +141,17 @@ class WiktionaryManager
...
@@ -135,14 +141,17 @@ class WiktionaryManager
$morphologicalLabels
=
[];
$morphologicalLabels
=
[];
$entryData
=
[];
$entryData
=
[];
$word
=
array_keys
(
$wiktionaryData
[
0
])[
2
];
$excludedKeys
=
[
"id"
,
"sources"
,
"translations"
];
$allKeys
=
array_keys
(
$wiktionaryData
[
0
]);
$single
=
array_diff
(
$allKeys
,
$excludedKeys
);
$word
=
reset
(
$single
);
$entryData
[
'Headword'
]
=
$word
;
$entryData
[
'Headword'
]
=
$word
;
$items
=
[];
$items
=
[];
foreach
(
$wiktionaryData
as
$pos
)
{
foreach
(
$wiktionaryData
as
$pos
)
{
if
(
array_keys
(
$pos
)[
2
]
!=
$word
)
{
/*
if (array_keys($pos)[
3
] != $word) {
throw new \Exception(sprintf("Items se rapportant à des mots différents dans les données du wiktionnaire pour le mot %s.", $word));
throw new \Exception(sprintf("Items se rapportant à des mots différents dans les données du wiktionnaire pour le mot %s.", $word));
}
}
*/
$posData
=
$pos
[
$word
];
$posData
=
$pos
[
$word
];
$item
=
[];
$item
=
[];
...
...
This diff is collapsed.
Click to expand it.
src/Twig/AppTwigExtension.php
+
12
−
3
View file @
b85bda6c
...
@@ -102,7 +102,7 @@ class AppTwigExtension extends AbstractExtension
...
@@ -102,7 +102,7 @@ class AppTwigExtension extends AbstractExtension
$nextMilestoneIndex
=
$currentMilestone
<
$numSuccesses
-
1
?
$currentMilestone
+
1
:
$numSuccesses
-
1
;
$nextMilestoneIndex
=
$currentMilestone
<
$numSuccesses
-
1
?
$currentMilestone
+
1
:
$numSuccesses
-
1
;
$progressPercentage
=
(
$counter
-
$successMilestones
[
$currentMilestone
])
/
(
$successMilestones
[
$currentMilestone
+
1
]
-
$currentMilestone
)
*
100
;
// Calculate progress percentage
$progressPercentage
=
(
$counter
-
$successMilestones
[
$currentMilestone
])
/
(
$successMilestones
[
min
(
$currentMilestone
+
1
,
$numSuccesses
-
1
)
]
-
$currentMilestone
)
*
100
;
// Calculate progress percentage
// Define CSS styles for the progress bar container and fill
// Define CSS styles for the progress bar container and fill
$containerStyle
=
sprintf
(
'background-color: %s;'
,
$successColors
[
1
]);
// Use the first color in $successColors for the container background
$containerStyle
=
sprintf
(
'background-color: %s;'
,
$successColors
[
1
]);
// Use the first color in $successColors for the container background
$fillStyle
=
sprintf
(
'background-color: %s; width: %s%%;'
,
$successColors
[
0
],
$progressPercentage
);
// Use the second color in $successColors for the fill
$fillStyle
=
sprintf
(
'background-color: %s; width: %s%%;'
,
$successColors
[
0
],
$progressPercentage
);
// Use the second color in $successColors for the fill
...
@@ -119,7 +119,16 @@ class AppTwigExtension extends AbstractExtension
...
@@ -119,7 +119,16 @@ class AppTwigExtension extends AbstractExtension
$currentReward
=
$this
->
renderRewardImageSmall
(
$successMilestones
[
$currentMilestone
],
$successMilestones
[
$currentMilestone
],
$successName
);
$currentReward
=
$this
->
renderRewardImageSmall
(
$successMilestones
[
$currentMilestone
],
$successMilestones
[
$currentMilestone
],
$successName
);
}
}
$nextReward
=
$this
->
renderRewardImageSmall
(
$successMilestones
[
$nextMilestoneIndex
],
$successMilestones
[
$currentMilestone
],
$successName
);
if
(
$currentMilestone
==
$numSuccesses
-
1
)
{
$nextReward
=
$this
->
renderRewardImageSmall
(
$successMilestones
[
$currentMilestone
],
$successMilestones
[
$currentMilestone
],
$successName
);
}
else
{
$nextReward
=
$this
->
renderRewardImageSmall
(
$successMilestones
[
$nextMilestoneIndex
],
$successMilestones
[
$currentMilestone
],
$successName
);
}
// Return the concatenated HTML for rewards and progress bar
// Return the concatenated HTML for rewards and progress bar
...
@@ -202,4 +211,4 @@ class AppTwigExtension extends AbstractExtension
...
@@ -202,4 +211,4 @@ class AppTwigExtension extends AbstractExtension
}
}
}
}
}
}
\ No newline at end of file
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