Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
python-unitex
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneur
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Patrick Watrin
python-unitex
Validations
689e97a8
Valider
689e97a8
rédigé
9 years ago
par
Patrick Watrin
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
config file loading and checking (work in progress)
parent
776b28f2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
config/processor.yaml
+6
-3
6 ajouts, 3 suppressions
config/processor.yaml
unitex/processor.py
+77
-20
77 ajouts, 20 suppressions
unitex/processor.py
avec
83 ajouts
et
23 suppressions
config/processor.yaml
+
6
−
3
Voir le fichier @
689e97a8
...
...
@@ -2,6 +2,8 @@ global:
debug
:
1
verbose
:
1
tempdir
:
"
/tmp"
persistence
:
1
virtualization
:
1
...
...
@@ -19,7 +21,8 @@ resources:
-
/home/resources/media/fr/unitex/dictionary/toponyms.bin
# The 'options' section can contain any of the argument used by the unitex tools
# functions.
# functions. Note that some argument will be overriden to fit the 'tag' and 'extract'
# behaviour. For intance, there is not point to define a font or a context for
# 'concord'.
options
:
match-mode
:
longest
output-mode
:
merge
match_mode
:
longest
Ce diff est replié.
Cliquez pour l'agrandir.
unitex/processor.py
+
77
−
20
Voir le fichier @
689e97a8
...
...
@@ -2,13 +2,14 @@
# -*- coding: utf-8 -*-
import
os
import
tempfile
import
yaml
from
unitex
import
UnitexException
,
LOGGER
,
DEFAULT_ENCODING
from
unitex
import
UnitexException
,
LOGGER
,
DEFAULT_ENCODING
,
VERBOSE
,
DEBUG
class
Unitex
Settings
(
object
):
class
Unitex
Config
(
object
):
def
__init__
(
self
):
self
.
__settings
=
None
...
...
@@ -21,36 +22,63 @@ class UnitexSettings(object):
raise
UnitexException
(
"
Key
'
%s
'
not found!
"
%
key
)
return
self
.
__settings
[
key
]
def
set
(
self
,
key
,
value
):
def
__
set
item__
(
self
,
key
,
value
):
self
.
__settings
[
key
]
=
value
def
load
(
self
,
f
):
with
open
(
f
,
'
r
'
)
as
config
:
self
.
__settings
=
yaml
.
load
(
config
)
self
.
check
()
def
check
(
self
):
resources
=
self
.
__settings
.
get
(
"
resources
"
,
None
)
if
resources
is
None
:
raise
UnitexException
(
"
You must provide the
'
resources
'
config element.
"
)
language
=
resources
.
get
(
"
language
"
,
None
)
def
__load_global
(
self
,
options
):
verbose
=
options
.
get
(
"
verbose
"
,
VERBOSE
)
if
verbose
not
in
(
0
,
1
,
2
):
raise
UnitexException
(
"
Wrong value for the
'
verbose
'
global option.
"
)
self
.
__settings
[
"
verbose
"
]
=
verbose
debug
=
options
.
get
(
"
debug
"
,
DEBUG
)
if
debug
not
in
(
0
,
1
):
raise
UnitexException
(
"
Wrong value for the
'
debug
'
global option.
"
)
self
.
__settings
[
"
debug
"
]
=
debug
for
handler
in
LOGGER
.
handlers
:
if
debug
==
1
:
fh
.
setLevel
(
logging
.
DEBUG
)
elif
verbose
==
1
:
fh
.
setLevel
(
logging
.
WARNING
)
elif
verbose
==
2
:
fh
.
setLevel
(
logging
.
INFO
)
else
:
fh
.
setLevel
(
logging
.
ERROR
)
persistence
=
options
.
get
(
"
persistence
"
,
0
)
if
persistence
not
in
(
0
,
1
)
raise
UnitexException
(
"
Wrong value for the
'
persistence
'
global option.
"
)
self
.
__settings
[
"
persistence
"
]
=
bool
(
persistence
)
virtualization
=
options
.
get
(
"
virtualization
"
,
0
)
if
virtualization
not
in
(
0
,
1
)
raise
UnitexException
(
"
Wrong value for the
'
virtualization
'
global option.
"
)
self
.
__settings
[
"
virtualization
"
]
=
bool
(
virtualization
)
def
__load_resources
(
self
,
options
):
language
=
options
.
get
(
"
language
"
,
None
)
if
language
is
None
:
raise
UnitexException
(
"
The
'
resources
'
section must contain the
'
language
'
element.
"
)
self
.
__settings
[
"
language
"
]
=
language
alphabet
=
resource
s
.
get
(
"
alphabet
"
,
None
)
alphabet
=
option
s
.
get
(
"
alphabet
"
,
None
)
if
alphabet
is
None
:
LOGGER
.
warning
(
"
No alphabet file provided.
"
)
elif
not
os
.
path
.
exists
(
alphabet
):
raise
UnitexException
(
"
Alphabet file
'
%s
'
doesn
'
t exist.
"
%
alphabet
)
self
.
__settings
[
"
alphabet
"
]
=
alphabet
alphabet_sort
=
resource
s
.
get
(
"
alphabet-sort
"
,
None
)
alphabet_sort
=
option
s
.
get
(
"
alphabet-sort
"
,
None
)
if
alphabet_sort
is
None
:
LOGGER
.
warning
(
"
No sorted alphabet file provided.
"
)
elif
not
os
.
path
.
exists
(
alphabet_sort
):
raise
UnitexException
(
"
Sorted alphabet file
'
%s
'
doesn
'
t exist.
"
%
alphabet_sort
)
self
.
__settings
[
"
alphabet-sort
"
]
=
alphabet_sort
sentence
=
resource
s
.
get
(
"
sentence
"
,
None
)
sentence
=
option
s
.
get
(
"
sentence
"
,
None
)
if
sentence
is
None
:
LOGGER
.
warning
(
"
No sentence grammar provided.
"
)
else
:
...
...
@@ -60,7 +88,9 @@ class UnitexSettings(object):
if
not
os
.
path
.
exists
(
sentence
):
raise
UnitexException
(
"
Sentence grammar file
'
%s
'
doesn
'
t exist.
"
%
sentence
)
replace
=
resources
.
get
(
"
replace
"
,
None
)
self
.
__settings
[
"
sentence
"
]
=
sentence
replace
=
options
.
get
(
"
replace
"
,
None
)
if
replace
is
None
:
LOGGER
.
warning
(
"
No replace grammar provided.
"
)
else
:
...
...
@@ -70,7 +100,9 @@ class UnitexSettings(object):
if
not
os
.
path
.
exists
(
replace
):
raise
UnitexException
(
"
Replace grammar file
'
%s
'
doesn
'
t exist.
"
%
replace
)
dictionaries
=
resources
.
get
(
"
dictionaries
"
,
None
)
self
.
__settings
[
"
replace
"
]
=
replace
dictionaries
=
options
.
get
(
"
dictionaries
"
,
None
)
if
dictionaries
is
None
:
LOGGER
.
warning
(
"
No dictionaries provided.
"
)
else
:
...
...
@@ -85,6 +117,31 @@ class UnitexSettings(object):
if
not
os
.
path
.
exists
(
"
%s.bin
"
%
prefix
):
raise
UnitexException
(
"
Dictionary .inf file missing for
'
%s
'
.
"
%
dictionary
)
self
.
__settings
[
"
dictionaries
"
]
=
dictionaries
def
__load_normalize_options
(
self
,
options
):
pass
def
load
(
self
,
path
):
self
.
__settings
=
{}
settings
=
None
with
open
(
path
,
'
r
'
)
as
config
:
settings
=
yaml
.
load
(
config
)
if
not
settings
:
return
if
"
global
"
in
settings
:
self
.
__load_global
(
settings
[
"
global
"
])
if
"
resources
"
not
in
settings
:
raise
UnitexException
(
"
You must provide the
'
resources
'
config element.
"
)
self
.
__load_resources
(
settings
[
"
resources
"
])
if
"
options
"
in
settings
:
pass
class
UnitexProcessor
(
object
):
...
...
@@ -96,7 +153,7 @@ class UnitexProcessor(object):
self
.
reset
(
config
)
def
reset
(
self
,
config
):
self
.
__settings
=
Unitex
Settings
()
self
.
__settings
=
Unitex
Config
()
self
.
__settings
.
load
(
config
)
def
open
(
self
,
path
,
mode
=
"
srtlf
"
,
encoding
=
None
,
tagged
=
False
,
virtualize
=
False
):
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter