1.0.12 • Published 6 years ago

ubrain v1.0.12

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
6 years ago

ubrain

ubrain is ...

Specs

    const {Brain, Teach, Ask, Suggest, Reset, Group, SetLevel} = require('ubrain');
    const brain = Brain({level: .51});

    const teach = Teach({brain});
    const ask = Ask({brain});

    teach('hello', 'hi.1');
    teach('hi', 'hi.2');

    teach('bye', 'bye.1');
    teach('have to go', 'bye.2');

    expect(ask('hellooo')).to.deep.equal('hi.1');
    expect(ask('bye')).to.deep.equal('bye.1');

    expect(ask('hi')).to.deep.equal('hi.2');
    expect(ask('have to goooo!!')).to.deep.equal('bye.2');
    const brain = Brain();

    const teach = Teach({brain});
    const ask = Ask({brain});
    const reset = Reset({brain});

    teach('hello', 'hi.1');
    expect(ask('hellooo')).to.deep.equal('hi.1');

    reset();

    expect(ask('hellooo')).to.deep.equal(undefined);
    const brain = Brain();

    const teach = Teach({brain});
    const ask = Ask({brain});

    teach('0', '0');
    teach('0.5', '0');
    teach('3', '5');
    teach('11', '10');

    teach('20', '20');
    teach('21', '20');

    expect(ask('0')).to.deep.equal('0');
    expect(ask('0.8')).to.deep.equal('0');
    expect(ask('1')).to.deep.equal(undefined);

    expect(ask('2')).to.deep.equal('5');
    expect(ask('3')).to.deep.equal('5');
    expect(ask('4')).to.deep.equal('5');

    expect(ask('10')).to.deep.equal('10');
    expect(ask('11')).to.deep.equal('10');
    expect(ask('12')).to.deep.equal('10');

    expect(ask('18')).to.deep.equal('20');
    expect(ask('20')).to.deep.equal('20');
    expect(ask('21')).to.deep.equal('20');
    expect(ask('22')).to.deep.equal('20');
    const brain = Brain();

    const teach = Teach({brain});
    const ask = Ask({brain});

    teach([
      'hi',
      'hello',
      'hey'
    ], 'hi');

    teach([
      'bye',
      'bb',
      'have to go now'
    ], 'bye');

    expect(ask('hellooo')).to.deep.equal('hi');
    expect(ask('bb')).to.deep.equal('bye');
    const group = Group({level: .51});

    const groups = group([
      'slava',
      'slavko',
      'alex',
      'alexey',
      'eugene',
      'eug',
      'eugeniy'
    ]);


    expect(groups).to.deep.equal([
      [
        "slava",
        "slavko"
      ],
      [
        "alex",
        "alexey"
      ],
      [
        "eugene",
        "eug",
        "eugeniy"
      ]
    ]);
    const group = Group({level: .5, mode: 'fast'});

    const groups = group([
      {
        name: 'custom-field-1',
        value: 1
      },
      {
        value: 2
      },
      {
        value: 10
      },
      {
        value: 11
      },
      {
        value: 112
      },
      {
        value: 152
      }
    ], {get: ({value}) => value});


    expect(groups).to.deep.equal([
      [
        {
          "name": "custom-field-1",
          "value": 1
        },
        {
          "value": 2
        }
      ],
      [
        {
          "value": 10
        },
        {
          "value": 11
        }
      ],
      [
        {
          "value": 112
        },
        {
          "value": 152
        }
      ]
    ]);
    const brain = Brain({level: .3});

    const teach = Teach({brain});
    const suggest = Suggest({brain, size: 1});

    teach('hello', 'hi.1');
    teach('hallow', 'hi.2');
    teach('hey', 'hi.3');
    teach('hi', 'hi.4');

    teach('bye', 'bye.1');
    teach('go go go', 'bye.2');
    teach('have to go', 'bye.3');

    expect(suggest('hellooo', {size: 2})).to.deep.equal([
      'hi.1',
      'hi.2'
    ]);

    expect(suggest('go')).to.deep.equal([
      "bye.2"
    ]);
    const brain = Brain({level: .51});

    const teach = Teach({brain});
    const ask = Ask({brain});
    const level = SetLevel({brain});

    teach('hello', 'hi.1');
    teach('hi', 'hi.2');

    expect(ask('hellooo')).to.deep.equal('hi.1');

    level(1);

    expect(ask('hellooo')).to.deep.equal(undefined);
    expect(ask('hello')).to.deep.equal('hi.1');
1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago