Created
February 18, 2018 22:35
-
-
Save SergProduction/280b994f2a85fa51c57732205fe6ec3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @flow | |
| class Person { | |
| constructor() {} | |
| listen(data) {} | |
| say() { | |
| return {} | |
| } | |
| } | |
| const playerOne = new Person() | |
| const playerTwo = new Person() | |
| // --- lib | |
| const lib = { | |
| pair: (fn) => (arr) => { | |
| const acc = [] | |
| for (let i=1; i<arr.length; i++) { | |
| acc.push(fn(arr[i-1], arr[i])) | |
| } | |
| return acc | |
| } | |
| } | |
| // --- | |
| class StructWords { | |
| constructor() { | |
| this.pair = {} | |
| } | |
| learn(data: string[]) { | |
| const arrPair = lib.pair((prev, next) => [prev, next])(data) | |
| arrPair.forEach(pair => { | |
| if (this.pair[pair[0]]) this.pair[pair[0]] = {l:[], r:[pair[1]]} | |
| else this.pair[pair[0]].r.push(pair[1]) | |
| if (this.pair[pair[1]]) this.pair[pair[1]] = {l:[pair[0]], r:[]} | |
| else this.pair[pair[1]].l.push(pair[0]) | |
| }) | |
| } | |
| normalizeText(text: string, param = {}) { | |
| // const punct = param.punctuation | |
| const words = text.split(' ').map(word => { | |
| if (punct) | |
| const w = word.replace(/,|\./, '') | |
| .trim() | |
| .toLocaleLowerCase() | |
| if (w.length > 5) return w.slice(0, 5) | |
| return w | |
| }).filter(w => w !== '') | |
| return words | |
| } | |
| learnContext(text) { | |
| const words = this.normalizeText(text) | |
| if (words.length < 4) return | |
| } | |
| } | |
| const struct = new StructWords() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment