Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
EWOK
Manage
Activity
Members
Labels
Plan
Issues
2
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
EWOK
Commits
a8f4d1c7
Commit
a8f4d1c7
authored
1 year ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Plain Diff
Merge no-live
parents
5dc452be
8e440680
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
requirements.txt
+2
-1
2 additions, 1 deletion
requirements.txt
src/wiktextract_wrapper.py
+58
-4
58 additions, 4 deletions
src/wiktextract_wrapper.py
with
60 additions
and
5 deletions
requirements.txt
+
2
−
1
View file @
a8f4d1c7
Flask
==2.3.3
flask_cors
==4.0.0
wiktextract
@
git+https://github.com/tatuylonen/wiktextract.git
lupa
==1.8
wiktextract
@
git+https://github.com/tatuylonen/wiktextract.git@a3665b8779ad78b045406cc7b1e9ce31876bc6b6
This diff is collapsed.
Click to expand it.
src/wiktextract_wrapper.py
+
58
−
4
View file @
a8f4d1c7
from
wiktextract.page
import
parse_page
from
wiktextract_context
import
get_wiktextract_context
import
json
class
Wiktextract
:
def
__init__
(
self
,
wiktlang
:
str
,
wordlang
:
str
):
...
...
@@ -14,10 +14,64 @@ class Wiktextract:
if
not
page
:
return
None
result
=
parse_page
(
self
.
wxr
,
title
,
page
.
body
)
# convert(result)
return
result
return
convert
(
result
)
def
convert
(
data_format1
)
transformed_data
=
[]
# Iterate through entries in format 1
for
lang_code
,
entry
in
data_format1
.
items
():
transformed_entry
=
{
"
sources
"
:
[
{
"
wiktionary_language
"
:
lang_code
,
"
permanentId
"
:
hash
(
json
.
dumps
(
entry
)),
"
wikstraktor_version
"
:
"
f391b7f3b6c2a322f2eca90384ff6038851ba541
"
}
],
"
id
"
:
f
"
{
lang_code
}
-
{
entry
[
'
word
'
]
}{
entry
[
'
pos
'
]
}
"
,
entry
[
'
word
'
]:
{
"
pos
"
:
entry
[
'
pos
'
],
"
pronunciations
"
:
[
{
"
id
"
:
f
"
{
lang_code
}
-
{
entry
[
'
word
'
]
}
_prn1
"
,
"
transcript
"
:
pronunciation
[
'
ipa
'
],
"
sounds
"
:
[
{
"
id
"
:
f
"
{
lang_code
}
-
{
entry
[
'
word
'
]
}
_sound
{
index
}
"
,
"
audio
"
:
sound
.
get
(
"
audio
"
,
""
),
"
text
"
:
sound
.
get
(
"
enpr
"
,
""
),
"
tags
"
:
sound
.
get
(
"
tags
"
,
[]),
"
ogg_url
"
:
sound
.
get
(
"
ogg_url
"
,
""
),
"
mp3_url
"
:
sound
.
get
(
"
mp3_url
"
,
""
)
}
for
index
,
sound
in
enumerate
(
entry
[
'
sounds
'
],
start
=
1
)
]
}
],
"
senses
"
:
{}
}
}
# Iterate through senses in the entry
for
sense_index
,
sense
in
enumerate
(
entry
[
'
senses
'
],
start
=
0
):
sense_key
=
f
"
{
lang_code
}
.
{
lang_code
}
-
{
entry
[
'
word
'
]
}{
entry
[
'
pos
'
]
}
_
{
sense_index
}
"
transformed_entry
[
entry
[
'
word
'
]][
'
senses
'
][
sense_key
]
=
{
"
Definitions
"
:
[
{
"
id
"
:
f
"
{
lang_code
}
-
{
entry
[
'
word
'
]
}{
entry
[
'
pos
'
]
}
_def
{
index
}
"
,
"
lang
"
:
lang_code
,
"
definition
"
:
definition
}
for
index
,
definition
in
enumerate
(
sense
.
get
(
'
glosses
'
,
[]),
start
=
0
)
],
"
Examples
"
:
[
{
"
id
"
:
f
"
{
lang_code
}
-
{
entry
[
'
word
'
]
}{
entry
[
'
pos
'
]
}
_ex
{
index
}
"
,
"
example
"
:
example
[
'
text
'
]
}
for
index
,
example
in
enumerate
(
sense
.
get
(
'
examples
'
,
[]),
start
=
0
)
]
}
# def convert
transformed_data
.
append
(
transformed_entry
)
return
json
.
dumps
(
transformed_data
,
indent
=
2
)
if
__name__
==
"
__main__
"
:
import
argparse
...
...
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