Example #1
0
    def test_classifier_basic(self):
        x_hotel = ['book a hotel', 'need a nice place to stay', 'any motels near by']
        x_weather = ['what is the weather like', 'is it hot outside']

        clf = Classifier()
        clf.fit(x_hotel, 'hotel')
        clf.fit(x_weather, 'weather')

        assert clf.predict('will it rain today') == 'weather'
        assert clf.predict('find a place to stay') == 'hotel'

        x_greetings = ['hi', 'hello', 'hello there', 'hey']
        x_not_greetings = x_hotel + x_weather

        clf2 = Classifier()
        clf2.fit(x_greetings, 'greetings')
        clf2.fit(x_not_greetings, 'not_greetings')
        assert clf2.predict('flight information') == 'not_greetings'
        assert clf2.predict('hey there') == 'greetings'
Example #2
0
def test_classifier_basic():
    x_hotel = ['book a hotel', 'need a nice place to stay', 'any motels near by']
    x_weather = ['what is the weather like', 'is it hot outside']

    clf = Classifier()
    clf.fit(x_hotel, 'hotel')
    clf.fit(x_weather, 'weather')

    assert clf.predict('will it rain today') == 'weather'
    assert clf.predict('find a place to stay') == 'hotel'

    x_greetings = ['hi', 'hello', 'hello there', 'hey']
    x_not_greetings = x_hotel + x_weather

    clf2 = Classifier()
    clf2.fit(x_greetings, 'greetings')
    clf2.fit(x_not_greetings, 'not_greetings')
    assert clf2.predict('flight information') == 'not_greetings'
    assert clf2.predict('hey there') == 'greetings'
Example #3
0
    def adapt(self, q, inttype=False, priority=False):
        clf = Classifier()
        clauses = self.clauses
        int_clauses = self.int_clauses
        clauses.update(int_clauses)
        for i, tup in enumerate(clauses.items()):
            clause = tup[0]
            clf.fit(clause, clauses[clause])
            if inttype and priority:
                clf.fit(("how many", "number of", "who all", "how much",
                         "sum of", "total"), "sum of {} in {}")

        return clf.predict(q)
Example #4
0
    def test_classifier_serialization(self):
        x_hotel = ['book a hotel', 'need a nice place to stay', 'any motels near by']
        x_weather = ['what is the weather like', 'is it hot outside']

        clf1 = Classifier()
        clf1.fit(x_hotel, 'hotel')
        clf1.fit(x_weather, 'weather')

        config = clf1.serialize()
        clf2 = Classifier.deserialize(config)

        assert clf1.classes == clf2.classes

        test_inputs = ['will it rain today', 'find a place to stay']

        for test_input in test_inputs:
            clf1_out = clf1.predict(test_input, return_probs=True)
            clf2_out = clf2.predict(test_input, return_probs=True)
            assert clf1_out == clf2_out
Example #5
0
def test_classifier_serialization():
    x_hotel = ['book a hotel', 'need a nice place to stay', 'any motels near by']
    x_weather = ['what is the weather like', 'is it hot outside']

    clf1 = Classifier()
    clf1.fit(x_hotel, 'hotel')
    clf1.fit(x_weather, 'weather')

    config = clf1.serialize()
    clf2 = Classifier.deserialize(config)

    assert clf1.classes == clf2.classes

    test_inputs = ['will it rain today', 'find a place to stay']

    for test_input in test_inputs:
        clf1_out = clf1.predict(test_input, return_probs=True)
        clf2_out = clf2.predict(test_input, return_probs=True)
        assert clf1_out == clf2_out
Example #6
0
def test_classifier_basic():
    x_hotel = [
        'book a hotel', 'need a nice place to stay', 'any motels near by'
    ]
    x_weather = ['what is the weather like', 'is it hot outside']
    x_place = [
        'which place is this', 'where are we', 'where are you going',
        'which place is it'
    ]
    x_name = [
        'What is your name', 'Who are you', 'What do i call you',
        'what are you called'
    ]

    clf1 = Classifier()
    clf2 = Classifier()
    clfs = [clf1, clf2]
    for cl in clfs:
        cl.fit(x_hotel, 'hotel')
        cl.fit(x_weather, 'weather')
        cl.fit(x_place, 'place')
        cl.fit(x_name, 'name')

    assert clf1.predict('will it rain today') == 'weather'
    assert clf1.predict('find a place to stay') == 'hotel'
    assert clf1.predict('where am I') == 'place'
    assert clf1.predict('may i know your name') == 'name'

    # Testing return probablities for each of the above tests
    assert clf1.predict('will it rain today',
                        True) == clf2.predict('will it rain today', True)
    assert clf1.predict('find a place to stay',
                        True) == clf2.predict('find a place to stay', True)
    assert clf1.predict('where am I', True) == clf2.predict('where am I', True)
    assert clf1.predict('may i know your name',
                        True) == clf2.predict('may i know your name', True)
with open("dataset.txt", "r+") as file:
    text = file.readlines()
who = []
what = []
when = []
affirmation = []
unknown = []
for i in range(len(text)):
    line = text[i].split(",,,")
    if line[1] == " who\n":
        who.append(line[0])
    if line[1] == " what\n":
        what.append(line[0])
    if line[1] == " when\n":
        when.append(line[0])
    if line[1] == " affirmation\n":
        affirmation.append(line[0])
    if line[1] == " unknown\n":
        unknown.append(line[0])

from eywa.nlu import Classifier

clf = Classifier()
clf.fit(who, 'who')
clf.fit(what, 'what')
clf.fit(when, 'when')
clf.fit(affirmation, 'affirmation')
clf.fit(unknown, 'unknown')
x = input("Enter string :")
print(clf.predict(str(x)))