Skip to content
Extraits de code Groupes Projets
Valider 54bec9e6 rédigé par Patrick Watrin's avatar Patrick Watrin
Parcourir les fichiers

Settings loading and checking

parent 223e89ee
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -10,8 +10,8 @@ resources:
alphabet: /home/resources/media/fr/unitex/preprocessing/Alphabet.txt
alphabet-sorted: /home/resources/media/fr/unitex/preprocessing/Alphabet_sort.txt
sentence: /home/resources/media/fr/unitex/preprocessing/Sentence.fst2
replace: /home/resources/media/fr/unitex/preprocessing/Replace.fst2
sentence: /home/resources/media/fr/unitex/preprocessing/sentence/Sentence.fst2
replace: /home/resources/media/fr/unitex/preprocessing/replace/Replace.fst2
dictionaries:
- /home/resources/media/fr/unitex/dictionary/delaf-short.bin
......@@ -22,3 +22,4 @@ resources:
# functions.
options:
match-mode: longest
output-mode: merge
......@@ -44,7 +44,7 @@ class CustomBuild(build):
if sys.platform == "darwin":
library = "libunitex.dylib"
elif sys.platform == "linux":
elif sys.platform == "linux" or sys.platform == "linux2":
library = "libunitex.so"
else:
sys.stderr.write("Plateform '%s' not supported...\n" % sys.platform)
......@@ -125,8 +125,8 @@ setup(
sources = ["extensions/_unitex.cpp"])
],
cmdclass = {
"build": CustomBuild,
"clean": CustomClean
}
# cmdclass = {
# "build": CustomBuild,
# "clean": CustomClean
# }
)
......@@ -27,6 +27,7 @@ class UnitexSettings(object):
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)
......@@ -40,7 +41,49 @@ class UnitexSettings(object):
alphabet = resources.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)
alphabet_sort = resources.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)
sentence = resources.get("sentence", None)
if sentence is None:
LOGGER.warning("No sentence grammar provided.")
else:
_, extension = os.path.splitext(sentence)
if extension != ".fst2":
raise UnitexException("Wrong extension for '%s'. Grammars must be compiled and have the '.fst2' extension.")
if not os.path.exists(sentence):
raise UnitexException("Sentence grammar file '%s' doesn't exist." % sentence)
replace = resources.get("replace", None)
if replace is None:
LOGGER.warning("No replace grammar provided.")
else:
_, extension = os.path.splitext(replace)
if extension != ".fst2":
raise UnitexException("Wrong extension for '%s'. Grammars must be compiled and have the '.fst2' extension.")
if not os.path.exists(replace):
raise UnitexException("Replace grammar file '%s' doesn't exist." % replace)
dictionaries = resources.get("dictionaries", None)
if dictionaries is None:
LOGGER.warning("No dictionaries provided.")
else:
if not isinstance(dictionaries, list):
raise UnitexException("The 'dictionaries' element must be a list of .bin files.")
for dictionary in dictionaries:
prefix, extension = os.path.splitext(dictionary)
if extension != ".bin":
raise UnitexException("Wrong extension for '%s'. Dictionaries must be compiled and have the '.bin' extension.")
if not os.path.exists(dictionary):
raise UnitexException("Dictionary file '%s' doesn't exist." % dictionary)
if not os.path.exists("%s.bin" % prefix):
raise UnitexException("Dictionary .inf file missing for '%s'." % dictionary)
......@@ -62,4 +105,3 @@ class UnitexProcessor(object):
def close(self):
raise NotImplementedError
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter