From 7f08319c17569e84e4e0623250fa05cfbbf94cbb Mon Sep 17 00:00:00 2001 From: Tom Bocklisch Date: Wed, 14 Feb 2018 16:38:22 +0100 Subject: [PATCH] added run script and changed setup --- .travis.yml | 3 +- Makefile | 6 +++ rasa_nlu/extractors/duckling_extractor.py | 2 + rasa_nlu/run.py | 55 +++++++++++++++++++++++ setup.py | 51 +++++++++++---------- 5 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 rasa_nlu/run.py diff --git a/.travis.yml b/.travis.yml index b4f3122e78a7..10bccf72ba11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,7 +48,8 @@ jobs: - export ${!TRAVIS*} - sphinx-versioning push docs gh-pages . - stage: deploy - install: skip + install: + - pip install pypandoc==1.4 script: skip deploy: provider: pypi diff --git a/Makefile b/Makefile index fb043d726db3..fc786bd5f2b0 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ help: @echo " Check style with flake8." @echo " test" @echo " Run py.test" + @echo " check-readme" + @echo " Check if the readme can be converted from md to rst for pypi" clean: find . -name '*.pyc' -exec rm -f {} + @@ -27,3 +29,7 @@ test: clean livedocs: cd docs && make livehtml + +check-readme: + # if this runs through we can be sure the readme is properly shown on pypi + python setup.py check --restructuredtext --strict diff --git a/rasa_nlu/extractors/duckling_extractor.py b/rasa_nlu/extractors/duckling_extractor.py index 7e658f2466c3..44ed8fa4dc69 100644 --- a/rasa_nlu/extractors/duckling_extractor.py +++ b/rasa_nlu/extractors/duckling_extractor.py @@ -82,6 +82,8 @@ def create(cls, config): # type: (RasaNLUConfig) -> DucklingExtractor dims = config["duckling_dimensions"] + + config.get({}) if dims: unknown_dimensions = [dim for dim in dims diff --git a/rasa_nlu/run.py b/rasa_nlu/run.py new file mode 100644 index 000000000000..819b0592241f --- /dev/null +++ b/rasa_nlu/run.py @@ -0,0 +1,55 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import json +import logging +import os + +import six +from builtins import input + +from rasa_nlu.config import RasaNLUConfig +from rasa_nlu.model import Interpreter + +logger = logging.getLogger(__name__) + + +def create_argparser(): # pragma: no cover + import argparse + parser = argparse.ArgumentParser( + description='run a Rasa NLU model locally on the command line ' + 'for manual testing') + + parser.add_argument('-c', '--config', required=True, + help="config file") + + parser.add_argument('-m', '--model', required=True, + help="path to model") + return parser + + +def run_cmdline(config, model_path, component_builder=None): + interpreter = Interpreter.load(model_path, config, component_builder) + + logger.info("NLU model loaded. Type a message and press enter to parse it.") + while True: + text = input().strip() + if six.PY2: + # in python 2 input doesn't return unicode values + text = text.decode("utf-8") + r = interpreter.parse(text) + print(json.dumps(r, indent=2)) + + +if __name__ == '__main__': # pragma: no cover + parser = create_argparser() + args = parser.parse_args() + + nlu_config = RasaNLUConfig(args.config, os.environ, vars(args)) + logging.basicConfig(level=nlu_config['log_level']) + + run_cmdline(nlu_config, args.model) + + logger.info("Finished evaluation") diff --git a/setup.py b/setup.py index c9210251662e..0120d05b68b9 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,16 @@ -from setuptools import setup +from setuptools import setup, find_packages +import io -__version__ = None # Avoids IDE errors, but actual version is read from version.py -exec(open('rasa_nlu/version.py').read()) +# Avoids IDE errors, but actual version is read from version.py +__version__ = None +exec (open('rasa_nlu/version.py').read()) + +try: + import pypandoc + readme = pypandoc.convert_file('README.md', 'rst') +except (IOError, ImportError): + with io.open('README.md', encoding='utf-8') as f: + readme = f.read() tests_requires = [ "pytest", @@ -41,18 +50,12 @@ setup( name='rasa_nlu', - packages=[ - 'rasa_nlu', - 'rasa_nlu.utils', - 'rasa_nlu.classifiers', - 'rasa_nlu.emulators', - 'rasa_nlu.extractors', - 'rasa_nlu.featurizers', - 'rasa_nlu.tokenizers', - 'rasa_nlu.training_data', - 'rasa_nlu.training_data.formats' - ], + packages = find_packages(exclude=['contrib', 'docs', 'tests']), classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + # supported python versions "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", @@ -64,17 +67,19 @@ extras_require=extras_requires, include_package_data=True, description="Rasa NLU a natural language parser for bots", - author='Alan Nichol', - author_email='alan@rasa.ai', + long_description=readme, + author='Rasa Technologies GmbH', + author_email='hi@rasa.ai', + license='Apache 2.0', url="https://rasa.com", - keywords=["nlp", "machine-learning", "machine-learning-library", "bot", - "bots", - "botkit", "rasa", "conversational-agents", - "conversational-ai", - "chatbot", "chatbot-framework", "bot-framework"], - download_url="https://github.com/RasaHQ/rasa_nlu/archive/{}.tar.gz".format(__version__) + keywords="nlp machine-learning machine-learning-library bot bots " + "botkit rasa conversational-agents conversational-ai chatbot" + "chatbot-framework bot-framework", + download_url="https://github.com/RasaHQ/rasa_nlu/archive/{}.tar.gz" + "".format(__version__) ) print("\nWelcome to Rasa NLU!") -print("If any questions please visit documentation page https://rasahq.github.io/rasa_nlu") +print("If any questions please visit documentation " + "page https://rasahq.github.io/rasa_nlu") print("or join community chat on https://gitter.im/RasaHQ/rasa_nlu")