Skip to content

Commit

Permalink
Updated train function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarenne committed Jun 7, 2017
1 parent 9b661ae commit df341c0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions rasa_nlu/classifiers/regex_intent_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from typing import Text
import re

import rasa_nlu.converters as converters
from rasa_nlu.training_data import TrainingData

from rasa_nlu.components import Component


Expand All @@ -26,17 +29,12 @@ def __init__(self, clf=None, regex_dict=None):
self.regex_dict = {}

def train(self, training_data):
# extract dictionary of (regexp: intent) pairs from a text file with 'regexp : intent' on each line
self.regex_dict = {}
with open(training_data) as f:
for line in f:
if ':' in line:
regex, intent = line.strip().split(' : ')
self.regex_dict[regex] = intent
# build regex: intent dict from training data
for example in training_data.intent_examples:
self.regex_dict[example["text"]] = example["intent"]

def process(self, text):
# type: (Text) -> Dict[Text, Any]

return {
"intent": {
"name": self.parse(text),
Expand All @@ -55,4 +53,4 @@ def parse(self, text):
search = (re.search(exp, text) != None)
if search:
return intent
return "None"
return "None"

0 comments on commit df341c0

Please sign in to comment.