Beispiel #1
0
def populate_sub_words_recursive(thin_structure_words,
                                 depth=6,
                                 _current_depth=0,
                                 root_value=None):
    print 'populate sub words recursive {}/{}'.format(_current_depth, depth)
    words = populate_sub_words(thin_structure_words, allow_fetch=False)
    if _current_depth >= depth:
        print 'kill depth'
        return words

    for word_result in words:
        if 'words' in word_result['meta']:
            print 'recursive inspection of', len(word_result['meta'])
            _words = populate_sub_words_recursive(
                word_result['meta'],
                depth=depth,
                _current_depth=_current_depth + 1,
                root_value=root_value,
            )
            words.extend(_words)

    return words
Beispiel #2
0
import tensorflow
import random

import json
with open('vendor.json') as file:
    data = json.load(file)

words = []
labels = []
docs_x = []
docs_y = []

for intent in data['intents']:
    for pattern in intent["patterns"]:
        wrds = nltk.word_tokenize(pattern)
        words.extend(wrds)
        docs_x.append(wrds)
        docs_y.append(intent["tag"])

    if intent['tag'] not in labels:
        labels.append(intent['tag'])
words = [stemmer.stem(w.lower()) for w in words if w != "?"] #convert all cases in small later and convert the words into roots or base form and remove unwanted character
words = sorted(list(set(words))) #remove the duplicate words


# labels = sorted(labels) #remove the duplicate classes
training = []
output = []

out_empty = [0 for _ in range(len(labels))]