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
}
}
$currentMilestone
=
$success
->
getCurrentMilestone
();
if
(
$newPosition
>
$currentMilestone
)
{
if
(
$newPosition
>
$currentMilestone
&&
$currentMilestone
<
count
(
$successMilestones
)
-
1
)
{
$success
->
setCurrentMilestone
(
$newPosition
);
$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;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Serializer\SerializerAwareInterface
;
use
Symfony\Component\Serializer\SerializerInterface
;
use
Symfony\Component\HttpClient\HttpClient
;
use
Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
;
use
Symfony\Component\HttpClient\Exception\ClientException
;
class
WiktionaryManager
{
...
...
@@ -33,6 +36,7 @@ class WiktionaryManager
* @param $word
* @param $language
* @return mixed
* @throws \Exception|TransportExceptionInterface
*/
public
function
search
(
$word
,
$language
)
{
...
...
@@ -42,41 +46,44 @@ class WiktionaryManager
return
$this
->
lastSearch
[
'data'
];
}
// usage: wikstraktor.py [-h] [-l LANGUAGE] [-w WIKI_LANGUAGE] [-m MOT]
// [-f DESTINATION_FILE] [-A] [-C]
//
// Interroger un wiktionnaire
// ex :
// ‣./wikstraktor.py -m blue
// ‣./wikstraktor.py -m blue -f blue.json -A -C
// ‣./wikstraktor.py -l en -w fr -m blue -f blue.json -A -C
// options:
// -h, --help show this help message and exit
// -l LANGUAGE, --language LANGUAGE
// la langue du mot
// -w WIKI_LANGUAGE, --wiki_language WIKI_LANGUAGE
// la langue du wiki
// -m MOT, --mot MOT le mot à chercher
// -f DESTINATION_FILE, --destination_file DESTINATION_FILE
// le fichier dans lequel stocker le résultat
// -A, --force_ascii json avec que des caractères ascii
// -C, --compact json sans indentation
//$time_start = microtime(true); /*Debug*/
if
(
$_ENV
[
'WIKTIONARY_TOOL'
]
==
'WIKSTRAKTOR'
)
{
$command
=
$_ENV
[
'WIKSTRAKTOR_COMMAND'
]
.
' -l '
.
$language
.
' -w '
.
$language
.
' -m "'
.
$word
.
'" -A -C 2>&1'
;
}
else
{
$command
=
$_ENV
[
'WIKTEXTRACT_COMMAND'
]
.
' -l '
.
$language
.
' -w '
.
$language
.
' -e "'
.
$word
.
'"'
.
' -zA 2>&1'
;
//$time_start = microtime(true); /*Debug*/
$url
=
'http://localhost:5000/search/'
.
$language
.
'/'
.
$language
.
'/'
.
$word
.
'/a_wikstraktor'
;
$client
=
HttpClient
::
create
();
$result
=
null
;
// Make the initial request with a timeout
try
{
$response
=
$client
->
request
(
'GET'
,
$url
);
// dump($response->getStatusCode());die();
// Check the HTTP status code
if
(
$response
->
getStatusCode
()
===
200
)
{
// Server is up and returned a successful response
$result
=
$response
->
getContent
();
}
}
catch
(
TransportExceptionInterface
$exception
)
{
if
(
empty
(
exec
(
'ps aux | grep "[a]pp.py"'
)))
{
// Server is down, restart it
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
);
if
(
$response
->
getStatusCode
()
===
200
)
{
// Server is up and returned a successful response
$result
=
$response
->
getContent
();
}
}
else
{
throw
new
\Exception
(
'Server is down'
);
}
}
}
$result
=
exec
(
$command
);
//dump($word);dump($command);dump(microtime(true)-$time_start);dump($result);die();/*Debug*/
//dump(gettype($result));dump($url);dump(microtime(true)-$time_start);dump($result);/*Debug*/
// Output and error handling
$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
$this
->
lastSearch
=
[
...
...
@@ -87,8 +94,7 @@ class WiktionaryManager
//dump(json_last_error());
//dump(json_last_error_msg());
//dump($dataArray);die(); Wiktionary
//dump($dataArray);die();
return
$dataArray
;
}
...
...
@@ -135,14 +141,17 @@ class WiktionaryManager
$morphologicalLabels
=
[];
$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
;
$items
=
[];
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));
}
}
*/
$posData
=
$pos
[
$word
];
$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
$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
$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
...
...
@@ -119,7 +119,16 @@ class AppTwigExtension extends AbstractExtension
$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
...
...
@@ -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