diff --git a/README.md b/README.md index f869455284c3d30dd2397c9af0a327b78a5508f0..add0b79088ac31b2c45863c4fc5666a79a48996f 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,26 @@ Ran 2 tests in 0.045s OK ``` +## Documentation + +The documentation is accessible from any Python interactive shell using the command `help()`. + +```python +In [1]: import _unitex + +In [2]: help(_unitex.unitex_tool) +Help on built-in function unitex_tool in module _unitex: + +unitex_tool(...) + This function launches an Unitex command. + + Positional arguments (length: 1): + 0 [str] -- the Unitex command. + + Return [bool]: + True if the command succeeds, False otherwise. +``` + ## Getting started **NOTE: The texts must be encoded in UTF-8. There is so far no support for UTF-16-(LE|BE) or any other encoding.** diff --git a/extensions/_unitex.cpp b/extensions/_unitex.cpp index f8763b4ca295f1e29dc9673a7c82fd1836f77ce7..01b2737f15688c39478a2346edb5652f07ac6946 100644 --- a/extensions/_unitex.cpp +++ b/extensions/_unitex.cpp @@ -27,8 +27,13 @@ static char unitex_docstring[] = ************************/ /* 'unitex_tool' function */ -static char unitex_tool_docstring[] = - "This function launches an Unitex command."; +static char unitex_tool_docstring[] = "\ +This function launches an Unitex command.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the Unitex command.\n\n\ +Return [bool]:\n\ + True if the command succeeds, False otherwise.\ +"; static PyObject *unitex_tool(PyObject *self, PyObject *args); PyObject *unitex_tool(PyObject *self, PyObject *args) { @@ -49,8 +54,16 @@ PyObject *unitex_tool(PyObject *self, PyObject *args) { *************************/ /* 'unitex_load_persistent_dictionary' function */ -static char unitex_load_persistent_dictionary_docstring[] = - "This function loads a dictionary in the persistent space."; +static char unitex_load_persistent_dictionary_docstring[] = "\ +This function loads a dictionary in the persistent space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the dictionary path.\n\n\ +Return [str]:\n\ + The persistent file path [str] (derived from filename but not\n\ + strictly identical, depending of implementation). This path must\n\ + be used by the unitex tools and the 'free_persistent_dictionary'\n\ + function.\n\ +"; static PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args); PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args) { @@ -75,8 +88,15 @@ PyObject *unitex_load_persistent_dictionary(PyObject *self, PyObject *args) { } /* 'unitex_load_persistent_fst2' function */ -static char unitex_load_persistent_fst2_docstring[] = - "This function loads a fst2 in the persistent space."; +static char unitex_load_persistent_fst2_docstring[] = "\ +This function loads a grammar in the persistent space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the fst2 path.\n\n\ +Return [str]:\n\ + The persistent file path [str] (derived from filename but not\n\ + strictly identical, depending of implementation). This path must\n\ + be used by the unitex tools and the 'free_persistent_fst2' function.\n\ +"; static PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args); PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args) { @@ -101,8 +121,16 @@ PyObject *unitex_load_persistent_fst2(PyObject *self, PyObject *args) { } /* 'unitex_load_persistent_alphabet' function */ -static char unitex_load_persistent_alphabet_docstring[] = - "This function loads an alphabet in the persistent space."; +static char unitex_load_persistent_alphabet_docstring[] = "\ +This function loads an alphabet in the persistent space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the alphabet path.\n\n\ +Return [str]:\n\ + The persistent file path [str] (derived from filename but not\n\ + strictly identical, depending of implementation). This path must\n\ + be used by the unitex tools and the 'free_persistent_alphabet'\n\ + function.\n\ +"; static PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args); PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args) { @@ -129,8 +157,13 @@ PyObject *unitex_load_persistent_alphabet(PyObject *self, PyObject *args) { /* 'unitex_free_persistent_dictionary' function */ -static char unitex_free_persistent_dictionary_docstring[] = - "This function removes a dictionary from the persistent space."; +static char unitex_free_persistent_dictionary_docstring[] = "\ +This function unloads a dictionary from persistent space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the persistent file path returned by the\n\ + 'load_persistent_dictionary' function.\n\n\ +Return [None]\ +"; static PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args); PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args) { @@ -144,8 +177,13 @@ PyObject *unitex_free_persistent_dictionary(PyObject *self, PyObject *args) { } /* 'unitex_free_persistent_fst2' function */ -static char unitex_free_persistent_fst2_docstring[] = - "This function removes a fst2 from the persistent space."; +static char unitex_free_persistent_fst2_docstring[] = "\ +This function unloads a grammar from persistent space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the persistent file path returned by the\n\ + 'load_persistent_fst2' function.\n\n\ +Return [None]\ +"; static PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args); PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args) { @@ -159,8 +197,13 @@ PyObject *unitex_free_persistent_fst2(PyObject *self, PyObject *args) { } /* 'unitex_free_persistent_alphabet' function */ -static char unitex_free_persistent_alphabet_docstring[] = - "This function removes an alphabet from the persistent space."; +static char unitex_free_persistent_alphabet_docstring[] = "\ +This function unloads an alphabet from persistent space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the persistent file path returned by the\n\ + 'load_persistent_alphabet' function.\n\n\ +Return [None]\ +"; static PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args); PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args) { @@ -176,8 +219,14 @@ PyObject *unitex_free_persistent_alphabet(PyObject *self, PyObject *args) { /* 'unitex_is_persistent_dictionary' function */ -static char unitex_is_persistent_dictionary_docstring[] = - "This function checks if a dictionary is in the persistent space."; +static char unitex_is_persistent_dictionary_docstring[] = "\ +This function checks if a dictionary path points to the persistent\n\ +space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the file path to check.\n\n\ +Return [bool]:\n\ + True if the dictionary is persistent, False otherwise.\ +"; static PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args); PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args) { @@ -192,8 +241,14 @@ PyObject *unitex_is_persistent_dictionary(PyObject *self, PyObject *args) { } /* 'unitex_is_persistent_fst2' function */ -static char unitex_is_persistent_fst2_docstring[] = - "This function checks if a fst2 is in the persistent space."; +static char unitex_is_persistent_fst2_docstring[] = "\ +This function checks if a grammar path points to the persistent\n\ +space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the file path to check.\n\n\ +Return [bool]:\n\ + True if the grammar is persistent, False otherwise.\ +"; static PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args); PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args) { @@ -208,8 +263,14 @@ PyObject *unitex_is_persistent_fst2(PyObject *self, PyObject *args) { } /* 'unitex_is_persistent_alphabet' function */ -static char unitex_is_persistent_alphabet_docstring[] = - "This function checks if an alphabet is in the persistent space."; +static char unitex_is_persistent_alphabet_docstring[] = "\ +This function checks if an alphabet path points to the persistent\n\ +space.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the file path to check.\n\n\ +Return [bool]:\n\ + True if the alphabet is persistent, False otherwise.\ +"; static PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args); PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args) { @@ -230,8 +291,13 @@ PyObject *unitex_is_persistent_alphabet(PyObject *self, PyObject *args) { *****************/ /* 'unitex_enable_stdout' function */ -static char unitex_enable_stdout_docstring[] = - "This function enable the standard output."; +static char unitex_enable_stdout_docstring[] = "\ +This function enables Unitex standard output. This is the default\n\ +but should be used for debug purposes only.\n\n\ +No argument.\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg); PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg) { @@ -244,8 +310,13 @@ PyObject *unitex_enable_stdout(PyObject *self, PyObject *noarg) { } /* 'unitex_enable_stderr' function */ -static char unitex_enable_stderr_docstring[] = - "This function enable the error output."; +static char unitex_enable_stderr_docstring[] = "\ +This function enables Unitex error output. This is the default\n\ +but should be used for debug purposes only.\n\n\ +No argument.\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg); PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg) { @@ -258,8 +329,14 @@ PyObject *unitex_enable_stderr(PyObject *self, PyObject *noarg) { } /* 'unitex_disable_stdout' function */ -static char unitex_disable_stdout_docstring[] = - "This function disable the standard output."; +static char unitex_disable_stdout_docstring[] = "\ +This function disables Unitex standard output to ensure multithread\n\ +output consistency (i.e. avoid output mixing between threads) and to\n\ +improve performances.\n\n\ +No argument.\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg); PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg) { @@ -272,8 +349,14 @@ PyObject *unitex_disable_stdout(PyObject *self, PyObject *noarg) { } /* 'unitex_disable_stderr' function */ -static char unitex_disable_stderr_docstring[] = - "This function disable the error output."; +static char unitex_disable_stderr_docstring[] = "\ +This function disables Unitex error output to ensure multithread\n\ +output consistency (i.e. avoid output mixing between threads) and to\n\ +improve performances.\n\n\ +No argument.\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg); PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg) { @@ -286,8 +369,16 @@ PyObject *unitex_disable_stderr(PyObject *self, PyObject *noarg) { } /* 'unitex_cp' function */ -static char unitex_cp_docstring[] = - "This function copies a file to the (virtual) filesystem."; +static char unitex_cp_docstring[] = "\ +This function copies a file. Both pathes can be on the virtual\n\ +filesystem or the disk filesystem. Therefore, this function can be\n\ +used to virtualize a file or to dump a virtual file.\n\n\ +Positional arguments (length: 2):\n\ + 0 [str] -- source file path\n\ + 1 [str] -- target file path\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_cp(PyObject *self, PyObject *args); PyObject *unitex_cp(PyObject *self, PyObject *args) { @@ -303,8 +394,14 @@ PyObject *unitex_cp(PyObject *self, PyObject *args) { } /* 'unitex_rm' function */ -static char unitex_rm_docstring[] = - "This function removes a file from the (virtual) filesystem."; +static char unitex_rm_docstring[] = "\ +This function removes a file. The path can be on the virtual\n\ +filesystem or the disk filesystem.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- file path\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_rm(PyObject *self, PyObject *args); PyObject *unitex_rm(PyObject *self, PyObject *args) { @@ -319,8 +416,15 @@ PyObject *unitex_rm(PyObject *self, PyObject *args) { } /* 'unitex_mv' function */ -static char unitex_mv_docstring[] = - "This function renames (and potentially moves) a (virtual) file."; +static char unitex_mv_docstring[] = "\ +This function moves/renames a file. Both pathes can be on the\n\ +virtual filesystem or the disk filesystem.\n\n\ +Positional arguments (length: 2):\n\ + 0 [str] -- old file path\n\ + 1 [str] -- new file path\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_mv(PyObject *self, PyObject *args); PyObject *unitex_mv(PyObject *self, PyObject *args) { @@ -336,8 +440,13 @@ PyObject *unitex_mv(PyObject *self, PyObject *args) { } /* 'unitex_mkdir' function */ -static char unitex_mkdir_docstring[] = - "This function creates a directory on the disk."; +static char unitex_mkdir_docstring[] = "\ +This function creates a directory on the disk.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- directory path\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_mkdir(PyObject *self, PyObject *args); PyObject *unitex_mkdir(PyObject *self, PyObject *args) { @@ -352,8 +461,13 @@ PyObject *unitex_mkdir(PyObject *self, PyObject *args) { } /* 'unitex_rmdir' function */ -static char unitex_rmdir_docstring[] = - "This function removes a directory from disk (and all its content)."; +static char unitex_rmdir_docstring[] = "\ +This function removes a directory from the disk.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- directory path\n\n\ +Return [bool]:\n\ + True if it succeeds, False otherwise.\ +"; static PyObject *unitex_rmdir(PyObject *self, PyObject *args); PyObject *unitex_rmdir(PyObject *self, PyObject *args) { @@ -368,8 +482,14 @@ PyObject *unitex_rmdir(PyObject *self, PyObject *args) { } /* 'unitex_ls' function */ -static char unitex_ls_docstring[] = - "This function list (disk or virtual) directory contents."; +static char unitex_ls_docstring[] = "\ +This function lists (disk or virtual) directory contents.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- directory path\n\n\ +Return [list(str)]:\n\ + The function returns a list of files (not directories) if the\n\ + directory is not empty and an empty list otherwise.\ +"; static PyObject *unitex_ls(PyObject *self, PyObject *args); PyObject *unitex_ls(PyObject *self, PyObject *args) { @@ -402,8 +522,14 @@ PyObject *unitex_ls(PyObject *self, PyObject *args) { } /* 'unitex_read_file' function (UTF-8 encoding only)*/ -static char unitex_read_file_docstring[] = - "This function read a (virtual) file."; +static char unitex_read_file_docstring[] = "\ +This function read a file from the disk or from the virtual filesystem.\n\ +The file **must** be encoded in UTF-8.\n\n\ +Positional arguments (length: 1):\n\ + 0 [str] -- the file path\n\n\ +Return [str]:\n\ + The function returns an unicode string.\ +"; static PyObject *unitex_read_file(PyObject *self, PyObject *args); PyObject *unitex_read_file(PyObject *self, PyObject *args) { @@ -440,8 +566,16 @@ PyObject *unitex_read_file(PyObject *self, PyObject *args) { } /* 'unitex_write_file' function (UTF-8 encoding only)*/ -static char unitex_write_file_docstring[] = - "This function write a (virtual) file."; +static char unitex_write_file_docstring[] = "\ +This function writes a file on the disk or on the virtual filesystem.\n\ +The file will be encoded in UTF-8.\n\n\ +Positional arguments (length: 3):\n\ + 0 [str] -- the file path\n\ + 1 [unicode] -- the file content\n\ + 2 [int] -- 1 to writes the UTF-8 bom, 0 otherwise\n\n\ +Return [bool]:\n\ + True if the function succeeds, False otherwise.\ +"; static PyObject *unitex_write_file(PyObject *self, PyObject *args); PyObject *unitex_write_file(PyObject *self, PyObject *args) { @@ -467,8 +601,15 @@ PyObject *unitex_write_file(PyObject *self, PyObject *args) { } /* 'unitex_append_to_file' function */ -static char unitex_append_to_file_docstring[] = - "This function append_to a (virtual) file."; +static char unitex_append_to_file_docstring[] = "\ +This function writes at the end of an existing file (virtual or not).\n\ +The file **must** be encoded in UTF-8.\n\n\ +Positional arguments (length: 2):\n\ + 0 [str] -- the file path\n\ + 1 [unicode] -- the file content\n\n\ +Return [bool]:\n\ + True if the function succeeds, False otherwise.\ +"; static PyObject *unitex_append_to_file(PyObject *self, PyObject *args); PyObject *unitex_append_to_file(PyObject *self, PyObject *args) { diff --git a/unitex/__init__.py b/unitex/__init__.py index ed958438eedacdf77d24e0d631d76538f2c865e8..2d4f97a95ec2f30190fc336a777457242993e582 100644 --- a/unitex/__init__.py +++ b/unitex/__init__.py @@ -5,10 +5,7 @@ import logging import os import sys -from _unitex import unitex_enable_stdout,\ - unitex_disable_stdout,\ - unitex_enable_stderr,\ - unitex_disable_stderr +import _unitex @@ -114,12 +111,13 @@ def enable_stdout(): This function enables Unitex standard output. This is the default but should be used for debug purposes only. + No argument. + Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Enabling standard output...") - ret = unitex_enable_stdout() + ret = _unitex.unitex_enable_stdout() if ret is False: _LOGGER.error("Enabling standard output failed!") @@ -131,12 +129,13 @@ def disable_stdout(): output consistency (i.e. avoid output mixing between threads) and to improve performances. + No argument. + Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Disabling standard output...") - ret = unitex_disable_stdout() + ret = _unitex.unitex_disable_stdout() if ret is False: _LOGGER.error("Disabling standard output failed!") @@ -147,12 +146,13 @@ def enable_stderr(): This function enables Unitex error output. This is the default but should be used for debug purposes only. + No argument. + Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Enabling error output...") - ret = unitex_enable_stderr() + ret = _unitex.unitex_enable_stderr() if ret is False: _LOGGER.error("Enabling error output failed!") @@ -164,12 +164,13 @@ def disable_stderr(): output consistency (i.e. avoid output mixing between threads) and to improve performances. + No argument. + Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Disabling error output...") - ret = unitex_disable_stderr() + ret = _unitex.unitex_disable_stderr() if ret is False: _LOGGER.error("Disabling error output failed!") diff --git a/unitex/io.py b/unitex/io.py index 0244d50bead004e1615dd91153806cf427ab447f..2aa6cdc28ab9bc03ae77ed97f1639bf6b6b23ef8 100644 --- a/unitex/io.py +++ b/unitex/io.py @@ -4,15 +4,7 @@ import logging import os -from _unitex import unitex_cp,\ - unitex_rm,\ - unitex_mv,\ - unitex_mkdir,\ - unitex_rmdir,\ - unitex_ls,\ - unitex_write_file,\ - unitex_append_to_file,\ - unitex_read_file +import _unitex from unitex import * @@ -23,7 +15,7 @@ _LOGGER = logging.getLogger(__name__) 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 + filesystem or the disk filesystem. Therefore, this function can be used to virtualize a file or to dump a virtual file. Arguments: @@ -31,11 +23,10 @@ def cp(source_path, target_path): target_path [str] -- target file path Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Copying file '%s' to '%s'..." % (source_path, target_path)) - ret = unitex_cp(source_path, target_path) + ret = _unitex.unitex_cp(source_path, target_path) if ret is False: _LOGGER.info("[FAILED!]") @@ -50,11 +41,10 @@ def rm(path): path [str] -- file path Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Removing file '%s'..." % path) - ret = unitex_rm(path) + ret = _unitex.unitex_rm(path) if ret is False: _LOGGER.info("[FAILED!]") @@ -70,11 +60,10 @@ def mv(old_path, new_path): new_path [str] -- new file path Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Moving file '%s' to '%s'..." % (old_path, new_path)) - ret = unitex_mv(old_path, new_path) + ret = _unitex.unitex_mv(old_path, new_path) if ret is False: _LOGGER.info("[FAILED!]") @@ -88,11 +77,10 @@ def mkdir(path): path [str] -- directory path Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Creating directory '%s'..." % path) - ret = unitex_mkdir(path) + ret = _unitex.unitex_mkdir(path) if ret is False: _LOGGER.info("[FAILED!]") @@ -100,17 +88,16 @@ def mkdir(path): def rmdir(path): """ - This function removes a directory on the disk. + This function removes a directory from the disk. Argument: path [str] -- directory path Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if it succeeds, False otherwise. """ _LOGGER.info("Removing directory '%s'..." % path) - ret = unitex_rmdir(path) + ret = _unitex.unitex_rmdir(path) if ret is False: _LOGGER.info("[FAILED!]") @@ -128,7 +115,7 @@ def ls(path): directory is not empty and an empty list otherwise. """ _LOGGER.info("Listing directory '%s'..." % path) - return unitex_ls(path) + return _unitex.unitex_ls(path) def exists(path): """ @@ -139,8 +126,7 @@ def exists(path): path [str] -- directory path Return [bool]: - The function returns 'True' if it succeeds and 'False' - otherwise. + True if the path exists, False otherwise. """ if path.startswith(UnitexConstants.VFS_PREFIX) is False: return os.path.exists(path) @@ -186,13 +172,13 @@ class UnitexFile(object): if self.__mode == "w": bom = 1 if self.__use_bom is True else 0 - unitex_write_file(self.__file, data, bom) + _unitex.unitex_write_file(self.__file, data, bom) else: - unitex_append_to_file(self.__file, data) + _unitex.unitex_append_to_file(self.__file, data) def read(self): if self.__file is None: raise UnitexException("You must open a file before reading...") if self.__mode != "r": raise UnitexException("File '%s' is opened in write/append mode..." % self.__file) - return unitex_read_file(self.__file) + return _unitex.unitex_read_file(self.__file) diff --git a/unitex/processor.py b/unitex/processor.py index bd19160d908db7228556175f42a584f4fd68f799..5a5f5001ec115bd0dbbd602b2da504a57df551ce 100644 --- a/unitex/processor.py +++ b/unitex/processor.py @@ -64,9 +64,9 @@ class UnitexProcessor(object): init_log_system(verbose, debug, log) - self.load() + self._load() - def load(self): + def _load(self): if self.__options["persistence"] is False: return self.__persisted_objects = [] @@ -111,7 +111,7 @@ class UnitexProcessor(object): self.__options["resources"]["dictionaries"] = _objects - def free(self): + def _free(self): if self.__persisted_objects is None: return @@ -123,7 +123,7 @@ class UnitexProcessor(object): elif _type == UnitexConstants.ALPHABET: free_persistent_alphabet(_object) - def clean(self): + def _clean(self): if self.__txt is None: _LOGGER.error("Unable to clean processor. No file opened!") return @@ -370,10 +370,10 @@ class UnitexProcessor(object): your corpus are processed (default: False). """ if clean is True: - self.clean() + self._clean() if free is True: - self.free() + self._free() self.__txt = None self.__snt = None diff --git a/unitex/resources.py b/unitex/resources.py index 5301d696a7dac5b1aa5d79bb2a1eea9e5390b09f..8901930d0f6e4ec775ff67b214dc700a3763c64d 100644 --- a/unitex/resources.py +++ b/unitex/resources.py @@ -3,15 +3,7 @@ import logging -from _unitex import unitex_load_persistent_dictionary,\ - unitex_is_persistent_dictionary,\ - unitex_free_persistent_dictionary,\ - unitex_load_persistent_fst2,\ - unitex_is_persistent_fst2,\ - unitex_free_persistent_fst2,\ - unitex_load_persistent_alphabet,\ - unitex_is_persistent_alphabet,\ - unitex_free_persistent_alphabet +import _unitex from unitex import * @@ -34,7 +26,7 @@ def load_persistent_dictionary(path): function. """ _LOGGER.info("Load persistent dictionary '%s'..." % path) - return unitex_load_persistent_dictionary(path) + return _unitex.unitex_load_persistent_dictionary(path) def is_persistent_dictionary(path): """ @@ -45,9 +37,9 @@ def is_persistent_dictionary(path): path [str] -- the file path to check. Return [bool]: - True if the dictionary is persitent otherwise False. + True if the dictionary is persistent, False otherwise. """ - return unitex_is_persistent_dictionary(path) + return _unitex.unitex_is_persistent_dictionary(path) def free_persistent_dictionary(path): """ @@ -58,7 +50,7 @@ def free_persistent_dictionary(path): 'load_persistent_dictionary' function. """ _LOGGER.info("Free persistent dictionary '%s'..." % path) - unitex_free_persistent_dictionary(path) + _unitex.unitex_free_persistent_dictionary(path) @@ -77,7 +69,7 @@ def load_persistent_fst2(path): function. """ _LOGGER.info("Load persistent fst2 '%s'..." % path) - return unitex_load_persistent_fst2(path) + return _unitex.unitex_load_persistent_fst2(path) def is_persistent_fst2(path): """ @@ -87,9 +79,9 @@ def is_persistent_fst2(path): path [str] -- the file path to check. Return [bool]: - True if the fst2 is persitent otherwise False. + True if the fst2 is persistent, False otherwise. """ - return unitex_is_persistent_fst2(path) + return _unitex.unitex_is_persistent_fst2(path) def free_persistent_fst2(path): """ @@ -100,7 +92,7 @@ def free_persistent_fst2(path): 'load_persistent_fst2' function. """ _LOGGER.info("Free persistent fst2 '%s'..." % path) - unitex_free_persistent_fst2(path) + _unitex.unitex_free_persistent_fst2(path) @@ -119,7 +111,7 @@ def load_persistent_alphabet(path): function. """ _LOGGER.info("Load persistent alphabet '%s'..." % path) - return unitex_load_persistent_alphabet(path) + return _unitex.unitex_load_persistent_alphabet(path) def is_persistent_alphabet(path): """ @@ -130,9 +122,9 @@ def is_persistent_alphabet(path): path [str] -- the file path to check. Return [bool]: - True if the alphabet is persitent otherwise False. + True if the alphabet is persistent, False otherwise. """ - return unitex_is_persistent_alphabet(path) + return _unitex.unitex_is_persistent_alphabet(path) def free_persistent_alphabet(path): """ @@ -143,4 +135,4 @@ def free_persistent_alphabet(path): 'load_persistent_alphabet' function. """ _LOGGER.info("Free persistent alphabet '%s'..." % path) - unitex_free_persistent_alphabet(path) + _unitex.unitex_free_persistent_alphabet(path) diff --git a/unitex/tools.py b/unitex/tools.py index e6c998e7935810edb359502c85ca109fc20d7471..6b7862c0e4e89ae7bdec042b4d1e7ffba2f85700 100644 --- a/unitex/tools.py +++ b/unitex/tools.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# NOTE: The documentation adapted for each function is extracted from -# the Unitex manual. +# NOTE: The documentation is somehow a copy/paste from the Unitex +# manual. import logging -from _unitex import unitex_tool +import _unitex from unitex import * from unitex.config import CheckDicOptions,\ @@ -78,7 +78,7 @@ def check_dic(dictionary, dtype, alphabet, **kwargs): _LOGGER.info("Checking dic '%s'" % dictionary) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -148,7 +148,7 @@ def compress(dictionary, **kwargs): _LOGGER.info("Compressing dic '%s'" % dictionary) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -168,7 +168,7 @@ def concord(index, alphabet, **kwargs): and a text file with the name defined by the user of the function if the function has constructed a modified version of the text. - In --html mode, the occurrence is coded as a hypertext link. The + In html mode, the occurrence is coded as a hypertext link. The reference associated to this link is of the form <a href="X Y Z">. X et Y represent the beginning and ending positions of the occurrence in characters in the file text_name.snt. Z represents the @@ -400,7 +400,7 @@ def concord(index, alphabet, **kwargs): _LOGGER.info("Create concordance for '%s'" % index) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -491,7 +491,7 @@ def dico(dictionaries, text, alphabet, **kwargs): _LOGGER.info("Applying dictionaries") _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -544,7 +544,7 @@ def extract(text, output, index, **kwargs): _LOGGER.info("Extracting sentences") _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -618,7 +618,7 @@ def fst2txt(grammar, text, alphabet, **kwargs): _LOGGER.info("Applying grammar '%s'..." % grammar) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -720,7 +720,7 @@ def grf2fst2(grammar, alphabet, **kwargs): _LOGGER.info("Compiling grammar '%s'..." % grammar) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -908,7 +908,7 @@ def locate(grammar, text, alphabet, **kwargs): _LOGGER.info("Locating pattern '%s'..." % grammar) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -985,7 +985,7 @@ def normalize(text, **kwargs): _LOGGER.info("Normalizing text '%s'..." % text) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -1056,7 +1056,7 @@ def sort_txt(text, **kwargs): _LOGGER.info("Sorting file '%s'..." % text) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -1153,7 +1153,7 @@ def tokenize(text, alphabet, **kwargs): _LOGGER.info("Tokenizing file '%s'..." % text) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret @@ -1221,6 +1221,6 @@ def txt2tfst(text, alphabet, **kwargs): _LOGGER.info("Building text automaton for '%s'..." % text) _LOGGER.debug("Command: %s", command) - ret = unitex_tool(command) + ret = _unitex.unitex_tool(command) return ret