Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Dec 12, 2017
1 parent 3625c61 commit f88f506
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions rasa_nlu/extractors/entity_synonyms.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from builtins import str
from builtins import range
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import io
import json
import os
import warnings
import six

import six
from builtins import str
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Text

from rasa_nlu.config import RasaNLUConfig
from rasa_nlu.extractors import EntityExtractor
from rasa_nlu.model import Metadata
from rasa_nlu.training_data import Message
Expand All @@ -41,7 +39,8 @@ def train(self, training_data, config, **kwargs):
for example in training_data.entity_examples:
for entity in example.get("entities", []):
entity_val = example.text[entity["start"]:entity["end"]]
self.add_entities_if_synonyms(entity_val, str(entity.get("value")))
self.add_entities_if_synonyms(entity_val,
str(entity.get("value")))

def process(self, message, **kwargs):
# type: (Message, **Any) -> None
Expand All @@ -54,9 +53,11 @@ def persist(self, model_dir):
# type: (Text) -> Dict[Text, Any]

if self.synonyms:
entity_synonyms_file = os.path.join(model_dir, "entity_synonyms.json")
entity_synonyms_file = os.path.join(model_dir,
"entity_synonyms.json")
with io.open(entity_synonyms_file, 'w') as f:
f.write(str(json.dumps(self.synonyms, indent=2, separators=(',', ': '))))
f.write(str(json.dumps(self.synonyms, indent=2,
separators=(',', ': '))))
return {"entity_synonyms": "entity_synonyms.json"}
else:
return {"entity_synonyms": None}
Expand Down

0 comments on commit f88f506

Please sign in to comment.