From 5556ed741df2bdda072db877cc9c3fe1aa4b4a3d Mon Sep 17 00:00:00 2001 From: amir-zeldes Date: Tue, 26 May 2020 12:18:31 -0400 Subject: [PATCH 1/3] Make module --- hebpipe/__init__.py | 2 ++ ..._dependencies_go_here => binary_dependencies_go_here.txt} | 0 hebpipe/heb_pipe.py | 5 ++++- hebpipe/models/{models_go_here => models_go_here.txt} | 0 4 files changed, 6 insertions(+), 1 deletion(-) rename hebpipe/bin/{binary_dependencies_go_here => binary_dependencies_go_here.txt} (100%) rename hebpipe/models/{models_go_here => models_go_here.txt} (100%) diff --git a/hebpipe/__init__.py b/hebpipe/__init__.py index e69de29..8c00833 100644 --- a/hebpipe/__init__.py +++ b/hebpipe/__init__.py @@ -0,0 +1,2 @@ +from .heb_pipe import run_hebpipe +run_hebpipe() \ No newline at end of file diff --git a/hebpipe/bin/binary_dependencies_go_here b/hebpipe/bin/binary_dependencies_go_here.txt similarity index 100% rename from hebpipe/bin/binary_dependencies_go_here rename to hebpipe/bin/binary_dependencies_go_here.txt diff --git a/hebpipe/heb_pipe.py b/hebpipe/heb_pipe.py index 41a3a7d..4c5a547 100644 --- a/hebpipe/heb_pipe.py +++ b/hebpipe/heb_pipe.py @@ -553,7 +553,7 @@ def nlp(input_data, do_whitespace=True, do_tok=True, do_tag=True, do_lemma=True, return tagged -if __name__ == "__main__": +def run_hebpipe(): if sys.version_info[0] == 2 and sys.version_info[1] < 7: @@ -683,3 +683,6 @@ def nlp(input_data, do_whitespace=True, do_tok=True, do_tag=True, do_lemma=True, fileword = " files\n\n" if len(files) > 1 else " file\n\n" sys.stderr.write("\nFinished processing " + str(len(files)) + fileword) + +if __name__ == "__main__": + run_hebpipe() \ No newline at end of file diff --git a/hebpipe/models/models_go_here b/hebpipe/models/models_go_here.txt similarity index 100% rename from hebpipe/models/models_go_here rename to hebpipe/models/models_go_here.txt From 59038501492544c280f14d94a8999b1cab65d218 Mon Sep 17 00:00:00 2001 From: amir-zeldes Date: Tue, 26 May 2020 12:19:16 -0400 Subject: [PATCH 2/3] version --- hebpipe/lib/_version.py | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hebpipe/lib/_version.py b/hebpipe/lib/_version.py index dac0253..dd711c7 100644 --- a/hebpipe/lib/_version.py +++ b/hebpipe/lib/_version.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -__version__ = "1.0.0.0" +__version__ = "1.0.0.1" __author__ = "Amir Zeldes" __copyright__ = "Copyright 2018-2020, Amir Zeldes" __license__ = "Apache 2.0 License" diff --git a/setup.py b/setup.py index 0baf0f1..b1194b5 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = 'hebpipe', packages = find_packages(), - version = '1.0.0.0', + version = '1.0.0.1', description = 'A pipeline for Hebrew NLP', author = 'Amir Zeldes', author_email = 'amir.zeldes@georgetown.edu', @@ -11,7 +11,7 @@ install_requires=['numpy','pandas','scipy','joblib','xgboost==0.81','rftokenizer','depedit','xmltodict'], url = 'https://github.com/amir-zeldes/HebPipe', license='Apache License, Version 2.0', - download_url = 'https://github.com/amir-zeldes/HebPipe/releases/tag/v1.0.0.0', + download_url = 'https://github.com/amir-zeldes/HebPipe/releases/tag/v1.0.0.1', keywords = ['NLP', 'Hebrew', 'segmentation', 'tokenization', 'tagging', 'parsing','morphology','POS'], classifiers = ['Programming Language :: Python', 'Programming Language :: Python :: 2', From 8d35903507097582f16b8cf41fe476247adc7cd1 Mon Sep 17 00:00:00 2001 From: amir-zeldes Date: Tue, 26 May 2020 12:26:21 -0400 Subject: [PATCH 3/3] Allow relative import --- README.md | 4 ++++ hebpipe/heb_pipe.py | 26 +++++++++++++++++++------- hebpipe/lib/_version.py | 2 +- setup.py | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 817f888..3be0726 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ Either install from PyPI using pip: `pip install hebpipe` +And run as a module: + +`python -m hebpipe example_in.txt` + Or install manually: * Clone this repository into the directory that the script should run in (git clone https://github.com/amir-zeldes/HebPipe) diff --git a/hebpipe/heb_pipe.py b/hebpipe/heb_pipe.py index 4c5a547..34f00f7 100644 --- a/hebpipe/heb_pipe.py +++ b/hebpipe/heb_pipe.py @@ -7,12 +7,21 @@ from glob import glob from rftokenizer import RFTokenizer -from lib.xrenner import Xrenner -from lib._version import __version__ -from lib.tt2conll import conllize -from lib.append_column import inject_col -from lib.sent_split import toks_to_sents -from lib.whitespace_tokenize import tokenize as whitespace_tokenize +try: # Module usage + from .lib.xrenner import Xrenner + from .lib._version import __version__ + from .lib.tt2conll import conllize + from .lib.append_column import inject_col + from .lib.sent_split import toks_to_sents + from .lib.whitespace_tokenize import tokenize as whitespace_tokenize +except ImportError: # direct script usage + from lib.xrenner import Xrenner + from lib._version import __version__ + from lib.tt2conll import conllize + from lib.append_column import inject_col + from lib.sent_split import toks_to_sents + from lib.whitespace_tokenize import tokenize as whitespace_tokenize + PY3 = sys.version_info[0] > 2 @@ -617,7 +626,10 @@ def run_hebpipe(): dotok = opts.tokenize if not opts.quiet: - from lib import timing + try: + from .lib import timing + except ImportError: # direct script usage + from lib import timing files = glob(opts.files) diff --git a/hebpipe/lib/_version.py b/hebpipe/lib/_version.py index dd711c7..daaf383 100644 --- a/hebpipe/lib/_version.py +++ b/hebpipe/lib/_version.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -__version__ = "1.0.0.1" +__version__ = "1.0.0.2" __author__ = "Amir Zeldes" __copyright__ = "Copyright 2018-2020, Amir Zeldes" __license__ = "Apache 2.0 License" diff --git a/setup.py b/setup.py index b1194b5..70d0045 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = 'hebpipe', packages = find_packages(), - version = '1.0.0.1', + version = '1.0.0.2', description = 'A pipeline for Hebrew NLP', author = 'Amir Zeldes', author_email = 'amir.zeldes@georgetown.edu', @@ -11,7 +11,7 @@ install_requires=['numpy','pandas','scipy','joblib','xgboost==0.81','rftokenizer','depedit','xmltodict'], url = 'https://github.com/amir-zeldes/HebPipe', license='Apache License, Version 2.0', - download_url = 'https://github.com/amir-zeldes/HebPipe/releases/tag/v1.0.0.1', + download_url = 'https://github.com/amir-zeldes/HebPipe/releases/tag/v1.0.0.2', keywords = ['NLP', 'Hebrew', 'segmentation', 'tokenization', 'tagging', 'parsing','morphology','POS'], classifiers = ['Programming Language :: Python', 'Programming Language :: Python :: 2',