Skip to content

Commit

Permalink
fixed type imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Jan 23, 2019
1 parent 72bcad3 commit d63519f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rasa_nlu/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

from rasa_nlu import config
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.training_data import Message

if typing.TYPE_CHECKING:
from rasa_nlu.training_data import TrainingData
from rasa_nlu.model import Metadata
from rasa_nlu.training_data import Message

logger = logging.getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions rasa_nlu/training_data/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from rasa_nlu.training_data.formats.dialogflow import DialogflowReader
from rasa_nlu.training_data.formats.luis import LuisReader
from rasa_nlu.training_data.formats.wit import WitReader
from rasa_nlu.training_data.formats.markdown import MarkdownWriter, MarkdownReader
from rasa_nlu.training_data.formats.markdown import (
MarkdownWriter,
MarkdownReader)
from rasa_nlu.training_data.formats.rasa import RasaReader, RasaWriter
from rasa_nlu.training_data.formats.wit import WitReader
4 changes: 3 additions & 1 deletion rasa_nlu/training_data/formats/dialogflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
from typing import Text, Any

from rasa_nlu.training_data import Message, TrainingData
from rasa_nlu.training_data.formats.readerwriter import TrainingDataReader
from rasa_nlu import utils
from rasa_nlu.training_data.util import transform_entity_synonyms
Expand All @@ -22,6 +21,7 @@ class DialogflowReader(TrainingDataReader):
def read(self, fn, **kwargs):
# type: (Text, Any) -> TrainingData
"""Loads training data stored in the Dialogflow data format."""
from rasa_nlu.training_data import TrainingData

language = kwargs["language"]
fformat = kwargs["fformat"]
Expand All @@ -42,6 +42,7 @@ def read(self, fn, **kwargs):

def _read_intent(self, intent_js, examples_js):
"""Reads the intent and examples from respective jsons."""
from rasa_nlu.training_data import Message, TrainingData
intent = intent_js.get("name")

training_examples = []
Expand Down Expand Up @@ -78,6 +79,7 @@ def _extract_entity(self, chunk, current_offset):
return entity

def _read_entities(self, examples_js):
from rasa_nlu.training_data import TrainingData
entity_synonyms = transform_entity_synonyms(examples_js)
return TrainingData([], entity_synonyms)

Expand Down
6 changes: 5 additions & 1 deletion rasa_nlu/training_data/formats/luis.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import typing

import logging
from typing import Text, Any, Dict

from rasa_nlu.training_data import Message, TrainingData
from rasa_nlu.training_data.formats.readerwriter import JsonTrainingDataReader

if typing.TYPE_CHECKING:
from rasa_nlu.training_data import Message, TrainingData

logger = logging.getLogger(__name__)


Expand All @@ -13,6 +16,7 @@ class LuisReader(JsonTrainingDataReader):
def read_from_json(self, js, **kwargs):
# type: (Dict[Text, Any], Any) -> TrainingData
"""Loads training data stored in the LUIS.ai data format."""
from rasa_nlu.training_data import Message, TrainingData

training_examples = []
regex_features = []
Expand Down
10 changes: 9 additions & 1 deletion rasa_nlu/training_data/formats/markdown.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import typing

import logging
import re

from rasa_nlu.training_data import Message, TrainingData
from rasa_nlu.training_data.formats.readerwriter import (
TrainingDataReader,
TrainingDataWriter)
from rasa_nlu.training_data.util import check_duplicate_synonym
from rasa_nlu.utils import build_entity

if typing.TYPE_CHECKING:
from rasa_nlu.training_data import Message, TrainingData

INTENT = "intent"
SYNONYM = "synonym"
REGEX = "regex"
Expand Down Expand Up @@ -40,6 +44,8 @@ def __init__(self):

def reads(self, s, **kwargs):
"""Read markdown string and create TrainingData object"""
from rasa_nlu.training_data import TrainingData

self.__init__()
s = self._strip_comments(s)
for line in s.splitlines():
Expand Down Expand Up @@ -149,6 +155,8 @@ def _add_synonyms(self, plain_text, entities):

def _parse_training_example(self, example):
"""Extract entities and synonyms, and convert to plain text."""
from rasa_nlu.training_data import Message

entities = self._find_entities_in_training_example(example)
plain_text = re.sub(ent_regex,
lambda m: m.groupdict()['entity_text'],
Expand Down
8 changes: 7 additions & 1 deletion rasa_nlu/training_data/formats/rasa.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import typing

import logging
from collections import defaultdict

from typing import Dict, Text, Any

from rasa_nlu.training_data import Message, TrainingData
from rasa_nlu.training_data.formats.readerwriter import (
JsonTrainingDataReader,
TrainingDataWriter)
from rasa_nlu.training_data.util import transform_entity_synonyms
from rasa_nlu.utils import json_to_string

if typing.TYPE_CHECKING:
from rasa_nlu.training_data import Message, TrainingData

logger = logging.getLogger(__name__)


class RasaReader(JsonTrainingDataReader):
def read_from_json(self, js, **kwargs):
"""Loads training data stored in the rasa NLU data format."""
from rasa_nlu.training_data import Message, TrainingData

validate_rasa_nlu_data(js)

data = js['rasa_nlu_data']
Expand Down
5 changes: 4 additions & 1 deletion rasa_nlu/training_data/formats/wit.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import typing

import logging
from typing import Any, Text, Dict

from rasa_nlu.training_data import Message, TrainingData
from rasa_nlu.training_data.formats.readerwriter import JsonTrainingDataReader

if typing.TYPE_CHECKING:
from rasa_nlu.training_data import Message, TrainingData

logger = logging.getLogger(__name__)


Expand Down
14 changes: 10 additions & 4 deletions rasa_nlu/training_data/loading.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing

import json
import logging
Expand All @@ -6,16 +7,16 @@
from typing import Text, Optional

from rasa_nlu import utils
from rasa_nlu.training_data import TrainingData
from rasa_nlu.training_data.formats import (
MarkdownReader, WitReader, LuisReader,
RasaReader, DialogflowReader)

from rasa_nlu.training_data.formats import markdown
from rasa_nlu.training_data.formats.dialogflow import (
DIALOGFLOW_AGENT, DIALOGFLOW_PACKAGE, DIALOGFLOW_INTENT,
DIALOGFLOW_ENTITIES, DIALOGFLOW_ENTITY_ENTRIES, DIALOGFLOW_INTENT_EXAMPLES)
from rasa_nlu.utils import EndpointConfig

if typing.TYPE_CHECKING:
from rasa_nlu.training_data import TrainingData

logger = logging.getLogger(__name__)

# Different supported file formats and their identifier
Expand Down Expand Up @@ -46,6 +47,7 @@ def load_data(resource_name, language='en'):
"""Load training data from disk.
Merges them if loaded from disk and multiple files are found."""
from rasa_nlu.training_data import TrainingData

files = utils.list_files(resource_name)
data_sets = [_load(f, language) for f in files]
Expand Down Expand Up @@ -83,6 +85,10 @@ def load_data_from_endpoint(data_endpoint, language='en'):

def _reader_factory(fformat):
"""Generates the appropriate reader class based on the file format."""
from rasa_nlu.training_data.formats import (
MarkdownReader, WitReader, LuisReader,
RasaReader, DialogflowReader)

reader = None
if fformat == LUIS:
reader = LuisReader()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pytest PEP8 configuration
[tool:pytest]
pep8maxlinelength = 120
pep8maxlinelength = 80
pep8ignore =
docs/conf.py ALL
*.py W503
Expand Down

0 comments on commit d63519f

Please sign in to comment.