Skip to content

Commit

Permalink
Merge f7db6ba into 91e1e65
Browse files Browse the repository at this point in the history
  • Loading branch information
twhughes committed Jul 25, 2018
2 parents 91e1e65 + f7db6ba commit bcc1629
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Expand Up @@ -46,7 +46,7 @@ Removed
Fixed
-----
- Fixed Luis emulation output to add start, end position and confidence for each entity.

- Fixed byte encoding issue where training data could not be loaded by URL in python 3.

[0.12.3] - 2018-05-02
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion rasa_nlu/training_data/loading.py
Expand Up @@ -70,7 +70,8 @@ def load_data_from_url(url, language='en'):
try:
response = requests.get(url)
response.raise_for_status()
temp_data_file = utils.create_temporary_file(response.content)
temp_data_file = utils.create_temporary_file(response.content,
mode="w+b")
return _load(temp_data_file, language)
except Exception as e:
logger.warning("Could not retrieve training data "
Expand Down
11 changes: 6 additions & 5 deletions rasa_nlu/utils/__init__.py
Expand Up @@ -331,13 +331,14 @@ def pycloud_pickle(file_name, obj):
cloudpickle.dump(obj, f)


def create_temporary_file(data, suffix=""):
"""Creates a tempfile.NamedTemporaryFile object for data"""
def create_temporary_file(data, suffix="", mode="w+"):
"""Creates a tempfile.NamedTemporaryFile object for data.
mode defines NamedTemporaryFile's mode parameter in py3."""

if PY3:
f = tempfile.NamedTemporaryFile("w+", suffix=suffix,
delete=False,
encoding="utf-8")
f = tempfile.NamedTemporaryFile(mode=mode, suffix=suffix,
delete=False)
f.write(data)
else:
f = tempfile.NamedTemporaryFile("w+", suffix=suffix,
Expand Down
34 changes: 34 additions & 0 deletions tests/base/test_training_data.py
Expand Up @@ -332,3 +332,37 @@ def test_training_data_conversion(tmpdir, data_file, gold_standard_file,
# to dump to the file and diff using git
# with io.open(gold_standard_file) as f:
# f.write(td.as_json(indent=2))


def test_url_data_format():
data = u"""
{
"rasa_nlu_data": {
"entity_synonyms": [
{
"value": "nyc",
"synonyms": ["New York City", "nyc", "the big apple"]
}
],
"common_examples" : [
{
"text": "show me flights to New York City",
"intent": "unk",
"entities": [
{
"entity": "destination",
"start": 19,
"end": 32,
"value": "NYC"
}
]
}
]
}
}"""
fname = utils.create_temporary_file(data.encode("utf-8"),
suffix="_tmp_training_data.json",
mode="w+b")
data = utils.read_json_file(fname)
assert data is not None
validate_rasa_nlu_data(data)

0 comments on commit bcc1629

Please sign in to comment.