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

(1) Extension _unitex.cpp finished so far. (2) Harmonization of the function...

(1) Extension _unitex.cpp finished so far. (2) Harmonization of the function returns in io.py, resources.py and tools.py. (3) io module finished (UnitexFile class added). (4) More documentation.
parent 932a09c9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -34,7 +34,7 @@ PyObject *unitex_tool(PyObject *self, PyObject *args) {
unsigned int ret;
ret = UnitexTool_public_run_string(command);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
......@@ -183,7 +183,7 @@ PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args) {
unsigned int ret;
ret = persistence_public_is_persisted_dictionary_filename(path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
/*'unitex_is_persistent_fst2' function*/
......@@ -199,7 +199,7 @@ PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args) {
unsigned int ret;
ret = persistence_public_is_persisted_fst2_filename(path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
/*'unitex_is_persistent_alphabet' function*/
......@@ -215,7 +215,7 @@ PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args) {
unsigned int ret;
ret = persistence_public_is_persisted_alphabet_filename(path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
......@@ -235,7 +235,7 @@ PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg) {
unsigned int ret;
ret = SetStdWriteCB(swk, 0, NULL, NULL);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
/* 'unitex_enable_stderr' function*/
......@@ -249,7 +249,7 @@ PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg) {
unsigned int ret;
ret = SetStdWriteCB(swk, 0, NULL, NULL);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
/* 'unitex_disable_stdout' function*/
......@@ -263,7 +263,7 @@ PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg) {
unsigned int ret;
ret = SetStdWriteCB(swk, 1, NULL, NULL);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
/* 'unitex_disable_stderr' function*/
......@@ -277,7 +277,7 @@ PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg) {
unsigned int ret;
ret = SetStdWriteCB(swk, 1, NULL, NULL);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_True: Py_False);
}
/* 'unitex_cp' function*/
......@@ -294,7 +294,7 @@ PyObject *unitex_cp(PyObject *self, PyObject *args) {
unsigned int ret;
ret = CopyUnitexFile(source_path, target_path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
/* 'unitex_rm' function*/
......@@ -310,7 +310,7 @@ PyObject *unitex_rm(PyObject *self, PyObject *args) {
unsigned int ret;
ret = RemoveUnitexFile(path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
/* 'unitex_mv' function*/
......@@ -327,7 +327,7 @@ PyObject *unitex_mv(PyObject *self, PyObject *args) {
unsigned int ret;
ret = RenameUnitexFile(old_path, new_path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
/* 'unitex_mkdir' function*/
......@@ -343,7 +343,7 @@ PyObject *unitex_mkdir(PyObject *self, PyObject *args) {
unsigned int ret;
ret = CreateUnitexFolder(path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
/* 'unitex_rmdir' function*/
......@@ -359,10 +359,12 @@ PyObject *unitex_rmdir(PyObject *self, PyObject *args) {
unsigned int ret;
ret = RemoveUnitexFolder(path);
return Py_BuildValue("i", ret);
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
/* 'unitex_ls' function*/
/* 'unitex_ls' function
* -> adapted from the function 'getFileList' developped
* by Gilles Vollant and distributed with Unitex */
static char unitex_ls_docstring[] =
"This function list (disk or virtual) directory contents.";
static PyObject *unitex_ls(PyObject *self, PyObject *args);
......@@ -372,7 +374,7 @@ PyObject *unitex_ls(PyObject *self, PyObject *args) {
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
char **_file_list=GetUnitexFileList(path);
char **_file_list = GetUnitexFileList(path);
if (_file_list==NULL)
return PyList_New(0);
......@@ -396,6 +398,87 @@ PyObject *unitex_ls(PyObject *self, PyObject *args) {
return file_list;
}
/* 'unitex_read_file' function (UTF-8 encoding only)
* -> adapted from the function 'getUnitexFileString' developped
* by Gilles Vollant and distributed with Unitex */
static char unitex_read_file_docstring[] =
"This function read a (virtual) file.";
static PyObject *unitex_read_file(PyObject *self, PyObject *args);
PyObject *unitex_read_file(PyObject *self, PyObject *args) {
char *path;
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
PyObject *content = NULL;
UNITEXFILEMAPPED *amf;
const void *buffer;
size_t file_size;
GetUnitexFileReadBuffer(path, &amf, &buffer, &file_size);
const unsigned char* bufchar = (const unsigned char*)buffer;
size_t bom_size = 0;
if (file_size>2) {
if (((*(bufchar))==0xef) && ((*(bufchar+1))==0xbb) && ((*(bufchar+2))==0xbf)) {
bom_size = 3;
}
}
char* _content = (char*)malloc(file_size+1);
memcpy(_content, bufchar+bom_size, file_size-bom_size);
*(_content+file_size-bom_size) = '\0';
content = PyUnicode_FromString(_content);
free(_content);
CloseUnitexFileReadBuffer(amf, buffer, file_size);
return content;
}
/* 'unitex_write_file' function (UTF-8 encoding only)
* -> adapted from the function 'doWriteUnitexFileUtf' developped
* by Gilles Vollant and distributed with Unitex */
static char unitex_write_file_docstring[] =
"This function write a (virtual) file.";
static PyObject *unitex_write_file(PyObject *self, PyObject *args);
PyObject *unitex_write_file(PyObject *self, PyObject *args) {
char *path;
char *content;
int *use_bom;
if (!PyArg_ParseTuple(args, "ssi", &path, &content, &use_bom))
return NULL;
const unsigned char UTF8BOM[3] = { 0xef,0xbb,0xbf };
unsigned int ret;
ret = WriteUnitexFile(path, UTF8BOM, use_bom ? 3:0, content, strlen(content));
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
/* 'unitex_append_to_file' function*/
static char unitex_append_to_file_docstring[] =
"This function append_to a (virtual) file.";
static PyObject *unitex_append_to_file(PyObject *self, PyObject *args);
PyObject *unitex_append_to_file(PyObject *self, PyObject *args) {
char *path;
char *content;
if (!PyArg_ParseTuple(args, "ss", &path, &content))
return NULL;
unsigned int ret;
ret = AppendUnitexFile(path, content, strlen(content));
return Py_BuildValue("O", ret ? Py_False: Py_True);
}
static PyMethodDef unitex_methods[] = {
/*Unitex Tool function*/
{"unitex_tool", unitex_tool, METH_VARARGS, unitex_tool_docstring},
......@@ -404,9 +487,11 @@ static PyMethodDef unitex_methods[] = {
{"unitex_load_persistent_dictionary", unitex_load_persistent_dictionary, METH_VARARGS, unitex_load_persistent_dictionary_docstring},
{"unitex_load_persistent_fst2", unitex_load_persistent_fst2, METH_VARARGS, unitex_load_persistent_fst2_docstring},
{"unitex_load_persistent_alphabet", unitex_load_persistent_alphabet, METH_VARARGS, unitex_load_persistent_alphabet_docstring},
{"unitex_free_persistent_dictionary", unitex_free_persistent_dictionary, METH_VARARGS, unitex_free_persistent_dictionary_docstring},
{"unitex_free_persistent_fst2", unitex_free_persistent_fst2, METH_VARARGS, unitex_free_persistent_fst2_docstring},
{"unitex_free_persistent_alphabet", unitex_free_persistent_alphabet, METH_VARARGS, unitex_free_persistent_alphabet_docstring},
{"unitex_is_persistent_dictionary", unitex_is_persistent_dictionary, METH_VARARGS, unitex_is_persistent_dictionary_docstring},
{"unitex_is_persistent_fst2", unitex_is_persistent_fst2, METH_VARARGS, unitex_is_persistent_fst2_docstring},
{"unitex_is_persistent_alphabet", unitex_is_persistent_alphabet, METH_VARARGS, unitex_is_persistent_alphabet_docstring},
......@@ -416,6 +501,7 @@ static PyMethodDef unitex_methods[] = {
{"unitex_disable_stdout", unitex_disable_stdout, METH_NOARGS, unitex_disable_stdout_docstring},
{"unitex_enable_stderr", unitex_enable_stderr, METH_NOARGS, unitex_enable_stderr_docstring},
{"unitex_disable_stderr", unitex_disable_stderr, METH_NOARGS, unitex_disable_stderr_docstring},
{"unitex_cp", unitex_cp, METH_VARARGS, unitex_cp_docstring},
{"unitex_rm", unitex_rm, METH_VARARGS, unitex_rm_docstring},
{"unitex_mv", unitex_mv, METH_VARARGS, unitex_mv_docstring},
......@@ -423,10 +509,14 @@ static PyMethodDef unitex_methods[] = {
{"unitex_rmdir", unitex_rmdir, METH_VARARGS, unitex_rmdir_docstring},
{"unitex_ls", unitex_ls, METH_VARARGS, unitex_ls_docstring},
{"unitex_read_file", unitex_read_file, METH_VARARGS, unitex_read_file_docstring},
{"unitex_write_file", unitex_write_file, METH_VARARGS, unitex_write_file_docstring},
{"unitex_append_to_file", unitex_append_to_file, METH_VARARGS, unitex_append_to_file_docstring},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef unitexdef = {
static struct PyModuleDef unitex_module_def = {
PyModuleDef_HEAD_INIT,
"_unitex",
unitex_docstring,
......@@ -435,7 +525,7 @@ static struct PyModuleDef unitexdef = {
};
PyMODINIT_FUNC PyInit__unitex(void) {
PyObject *module = PyModule_Create(&unitexdef);
PyObject *module = PyModule_Create(&unitex_module_def);
if (module == NULL)
return NULL;
......
......@@ -98,9 +98,9 @@ class TestUnitexTools(unittest.TestCase):
ret = check_dic(*args, **kwargs)
ok = os.path.exists(self._arguments["dic_check"]) and (ret == 0)
ok = os.path.exists(self._arguments["dic_check"]) and ret
self.assertTrue(ok, "Dictionary checking failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Dictionary checking failed!")
def test_02_compress(self):
args = [self._arguments["dic"]]
......@@ -112,9 +112,9 @@ class TestUnitexTools(unittest.TestCase):
ret = compress(*args, **kwargs)
ok = os.path.exists(self._arguments["bin"]) and os.path.exists(self._arguments["inf"]) and (ret == 0)
ok = os.path.exists(self._arguments["bin"]) and os.path.exists(self._arguments["inf"]) and ret
self.assertTrue(ok, "Compression failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Compression failed!")
def test_03_normalize(self):
args = [self._arguments["txt"]]
......@@ -128,9 +128,9 @@ class TestUnitexTools(unittest.TestCase):
ret = normalize(*args, **kwargs)
ok = os.path.exists(self._arguments["snt"]) and (ret == 0)
ok = os.path.exists(self._arguments["snt"]) and ret
self.assertTrue(ok, "Normalisation failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Normalisation failed!")
def test_04_fst2txt(self):
args = [self._arguments["sentence"]]
......@@ -144,9 +144,9 @@ class TestUnitexTools(unittest.TestCase):
ret = fst2txt(*args, **kwargs)
ok = (ret == 0)
ok = ret
self.assertTrue(ok, "FST application failed! Return code is '%s'" % ret)
self.assertTrue(ok, "FST application failed!")
def test_05_tokenize(self):
if not os.path.exists(self._arguments["dir"]):
......@@ -163,14 +163,14 @@ class TestUnitexTools(unittest.TestCase):
ret = tokenize(*args, **kwargs)
ok = (ret == 0)
ok = ret
ok = ok and os.path.exists(self._arguments["text.cod"])
ok = ok and os.path.exists(self._arguments["tok_by_freq.txt"])
ok = ok and os.path.exists(self._arguments["tok_by_alph.txt"])
ok = ok and os.path.exists(self._arguments["stats.n"])
ok = ok and os.path.exists(self._arguments["enter.pos"])
self.assertTrue(ok, "Tokenisation failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Tokenisation failed!")
def test_06_dico(self):
args = [self._arguments["bin"]]
......@@ -186,7 +186,7 @@ class TestUnitexTools(unittest.TestCase):
ret = dico(*args, **kwargs)
ok = (ret == 0)
ok = ret
ok = ok and os.path.exists(self._arguments["dlf"])
ok = ok and os.path.exists(self._arguments["dlc"])
ok = ok and os.path.exists(self._arguments["err"])
......@@ -194,7 +194,7 @@ class TestUnitexTools(unittest.TestCase):
ok = ok and os.path.exists(self._arguments["tags.ind"])
ok = ok and os.path.exists(self._arguments["stat_dic.n"])
self.assertTrue(ok, "Dictionary application failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Dictionary application failed!")
def test_07_sort_txt(self):
files = []
......@@ -218,9 +218,9 @@ class TestUnitexTools(unittest.TestCase):
ret = sort_txt(*args, **kwargs)
ok = ok and (ret == 0)
ok = ok and ret
self.assertTrue(ok, "Sorting failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Sorting failed!")
def test_08_grf2fst2(self):
args = [self._arguments["grf"]]
......@@ -239,9 +239,9 @@ class TestUnitexTools(unittest.TestCase):
ret = grf2fst2(*args, **kwargs)
ok = os.path.exists(self._arguments["fst"]) and (ret == 0)
ok = os.path.exists(self._arguments["fst"]) and ret
self.assertTrue(ok, "Grammar compilation failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Grammar compilation failed!")
def test_09_locate(self):
args = [self._arguments["fst"]]
......@@ -272,9 +272,9 @@ class TestUnitexTools(unittest.TestCase):
ret = locate(*args, **kwargs)
ok = os.path.exists(self._arguments["ind"]) and os.path.exists(self._arguments["concord.n"]) and (ret == 0)
ok = os.path.exists(self._arguments["ind"]) and os.path.exists(self._arguments["concord.n"]) and ret
self.assertTrue(ok, "Locate failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Locate failed!")
def test_10_concord(self):
args = [self._arguments["ind"]]
......@@ -301,9 +301,9 @@ class TestUnitexTools(unittest.TestCase):
ret = concord(*args, **kwargs)
ok = os.path.exists(self._arguments["concordances"]) and (ret == 0)
ok = os.path.exists(self._arguments["concordances"]) and ret
self.assertTrue(ok, "Concord failed! Return code is '%s'" % ret)
self.assertTrue(ok, "Concord failed!")
......
......@@ -7,38 +7,54 @@ from unitex import UnitexException, LOGGER
def enable_stdout():
"""This function enable Unitex standard output. This should be used
for debug purposes only.
"""This function enables Unitex standard output. This is the default but
should be used for debug purposes only.
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Enabling standard output...")
ret = unitex_enable_stdout()
if ret == 0:
raise UnitexException("Enabling stdout failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def disable_stdout():
"""This function disable Unitex standard output to ensure multithread
"""This function disables Unitex standard output to ensure multithread
output consistency (i.e. avoid output mixing between threads) and to
improve performances.
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Disabling standard output...")
ret = unitex_disable_stdout()
if ret == 0:
raise UnitexException("Disabling stdout failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def enable_stderr():
"""This function enable Unitex error output. This should be used
for debug purposes only.
"""This function enables Unitex error output. This is the default but
should be used for debug purposes only.
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Enabling error output...")
ret = unitex_enable_stderr()
if ret == 0:
raise UnitexException("Enabling stderr failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def disable_stderr():
"""This function disable Unitex error output to ensure multithread
"""This function disables Unitex error output to ensure multithread
output consistency (i.e. avoid output mixing between threads) and to
improve performances.
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Disabling error output...")
ret = unitex_disable_stderr()
if ret == 0:
raise UnitexException("Disabling stderr failed!")
if ret is False:
LOGGER.info("[FAILED!]")
......@@ -49,36 +65,101 @@ class UnitexIOConstants:
def cp(source_path, target_path):
"""This function copies a file. Both pathes can be on the virtual filesystem
or the disk filesystem. Therefor, this function can be used to virtualize a
file or to dump a virtual file.
Arguments:
source_path [str] -- source file path
target_path [str] -- target file path
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Copying file '%s' to '%s'..." % (source_path, target_path))
ret = unitex_cp(source_path, target_path)
if ret != 0:
raise UnitexException("File copy failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def rm(path):
"""This function removes a file. The path can be on the virtual filesystem
or the disk filesystem.
Argument:
path [str] -- file path
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Removing file '%s'..." % path)
ret = unitex_rm(path)
if ret != 0:
raise UnitexException("File suppression failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def mv(old_path, new_path):
"""This function moves/renames a file. Both pathes can be on the virtual
filesystem or the disk filesystem.
Arguments:
old_path [str] -- old file path
new_path [str] -- new file path
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Moving file '%s' to '%s'..." % (old_path, new_path))
ret = unitex_mv(old_path, new_path)
if ret != 0:
raise UnitexException("File renaming failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def mkdir(path):
"""This function creates a directory on the disk.
Argument:
path [str] -- directory path
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Creating directory '%s'..." % path)
ret = unitex_mkdir(path)
if ret != 0:
raise UnitexException("Folder creation failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def rmdir(path):
"""This function removes a directory on the disk.
Argument:
path [str] -- directory path
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
LOGGER.info("Removing directory '%s'..." % path)
ret = unitex_rmdir(path)
if ret != 0:
raise UnitexException("Folder suppression failed!")
if ret is False:
LOGGER.info("[FAILED!]")
def ls(path):
"""This function lists (disk or virtual) directory contents.
Argument:
path [str] -- directory path
Return [list(str)]:
The function returns a list of files (not directories) if the directory
is not empty and an empty list otherwise.
"""
LOGGER.info("Listing directory '%s'..." % path)
return unitex_ls(path)
class VirtualFile(object):
class UnitexFile(object):
"""The UnitexFile class provides the minimum functionality necessary to
manipulate files on the disk and the virtual filesystems. *The encoding
must be UTF-8*.
"""
def __init__(self):
self.__file = None
......@@ -87,15 +168,21 @@ class VirtualFile(object):
def open(self, file, mode=None):
self.__file = file
self.__mode = mode
raise NotImplementedError
def close(self):
raise NotImplementedError
self.__file = None
self.__mode = None
def write(self, data):
if self.__mode not in ("w", "a"):
raise UnitexException("File '%s' is opened in read mode..." % self.__file)
raise NotImplementedError
if self.__file is None:
raise UnitexException("You must open a file before writing...")
if self.__mode == "w":
unitex_write_file(self.__file, data, 1)
else:
unitex_append_to_file(self.__file, data)
def read(self):
raise NotImplementedError
return unitex_read_file(self.__file)
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
from _unitex import *
from unitex import UnitexException, LOGGER
from unitex import LOGGER
......@@ -18,12 +18,7 @@ def load_persistent_dictionary(path):
'free_persistent_dictionary' function.
"""
LOGGER.info("Load persistent dictionary '%s'..." % path)
ret = unitex_load_persistent_dictionary(path)
if ret == 0:
LOGGER.debug("Loading dictionary '%s' failed..." % path)
raise UnitexException("Unable to load persistent dictionary '%s'..." % path)
return ret
return unitex_load_persistent_dictionary(path)
def is_persistent_dictionary(path):
"""This function checks if a dictionary path points to the persistent space.
......@@ -34,10 +29,7 @@ def is_persistent_dictionary(path):
Return [bool]:
True if the dictionary is persitent otherwise False
"""
ret = unitex_is_persistent_dictionary(path)
if ret == 0:
return False
return True
return unitex_is_persistent_dictionary(path)
def free_persistent_dictionary(path):
"""This function unloads a dictionary from persistent space.
......@@ -62,12 +54,7 @@ def load_persistent_fst2(path):
'free_persistent_fst2' function.
"""
LOGGER.info("Load persistent fst2 '%s'..." % path)
ret = unitex_load_persistent_fst2(path)
if ret == 0:
LOGGER.debug("Loading fst2 '%s' failed..." % path)
raise UnitexException("Unable to load persistent fst2 '%s'..." % path)
return ret
return unitex_load_persistent_fst2(path)
def is_persistent_fst2(path):
"""This function checks if a fst2 path points to the persistent space.
......@@ -78,10 +65,7 @@ def is_persistent_fst2(path):
Return [bool]:
True if the fst2 is persitent otherwise False
"""
ret = unitex_is_persistent_fst2(path)
if ret == 0:
return False
return True
return unitex_is_persistent_fst2(path)
def free_persistent_fst2(path):
"""This function unloads a fst2 from persistent space.
......@@ -106,12 +90,7 @@ def load_persistent_alphabet(path):
'free_persistent_alphabet' function.
"""
LOGGER.info("Load persistent alphabet '%s'..." % path)
ret = unitex_load_persistent_alphabet(path)
if ret == 0:
LOGGER.debug("Loading alphabet '%s' failed..." % path)
raise UnitexException("Unable to load persistent alphabet '%s'..." % path)
return ret
return unitex_load_persistent_alphabet(path)
def is_persistent_alphabet(path):
"""This function checks if a alphabet path points to the persistent space.
......@@ -122,10 +101,7 @@ def is_persistent_alphabet(path):
Return [bool]:
True if the alphabet is persitent otherwise False
"""
ret = unitex_is_persistent_alphabet(path)
if ret == 0:
return False
return True
return unitex_is_persistent_alphabet(path)
def free_persistent_alphabet(path):
"""This function unloads a alphabet from persistent space.
......
......@@ -20,6 +20,9 @@ def check_dic(*args, **kwargs):
alphabet [str] -- alphabet file to use
strict [bool] -- strict syntax checking against unprotected dot and comma (default: False)
no_space_warning [bool] -- tolerates spaces in grammatical/semantic/inflectional codes (default: True)
Return [bool]:
The function returns 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -90,6 +93,9 @@ def compress(*args, **kwargs):
version [str] -- 'v1': produces an old style .bin file
'v2': produces a new style .bin file, with no file size limitation to 16 Mb
and a smaller size (default)
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -222,6 +228,9 @@ def concord(*args, **kwargs):
than <index> but in 'directory'
alphabet [str] -- alphabet file used for sorting
thai [bool] -- option to use for Thai concordances (default: False)
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -382,6 +391,9 @@ def dico(*args, **kwargs):
arabic_rules [str] -- specifies the Arabic typographic rule configuration file path
raw [str] -- alternative output file path containing both simple and compound
words, without requiring a text directory
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if not args:
......@@ -450,6 +462,8 @@ def fst2txt(*args, **kwargs):
This is useful for languages like Thai (default: False)
merge [bool] -- merge transducer outputs with text inputs (default: True)
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -538,6 +552,9 @@ def grf2fst2(*args, **kwargs):
debug [bool] -- compile graphs in debug mode (default: False)
check_variables [bool] -- check output validity to avoid malformed variable
expressions (default: False)
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -664,6 +681,9 @@ def locate(*args, **kwargs):
variable_error [str] -- 'exit': kills the function if variable has an empty content
'ignore': ignore the errors (default)
'backtrack': stop the current path exploration
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -820,6 +840,9 @@ def normalize(*args, **kwargs):
replaces { and } by [ and ]
no_separator_normalization [bool] -- only applies replacement rules specified with -r
(default: False)
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -889,6 +912,9 @@ def sort_txt(*args, **kwargs):
factorize_inflectional_codes [bool] -- makes two entries XXX,YYY.ZZZ:A and XXX,YYY.ZZZ:B
become a single entry XXX,YYY.ZZZ:A:B
(default: False)
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......@@ -982,6 +1008,9 @@ def tokenize(*args, **kwargs):
- Offsets options:
input_offsets [str] -- base offset file to be used;
output_offsets [str] -- offset file to be produced;
Return [bool]:
The function return 'True' if it succeeds and 'False' otherwise.
"""
if len(args) != 1:
......
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