Created
August 16, 2024 06:08
-
-
Save diegovgsilva95/d10a24733e7144e3f63c883bb70fcbcf to your computer and use it in GitHub Desktop.
Simple Natural Language Processing - Finding/Classifying words by the least maximum offset between their letters
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
| import {clear, log} from "console" | |
| import { readFile } from "fs/promises" | |
| var sleep = ms => new Promise(r => setTimeout(r, ms)) | |
| let dict = (await readFile("english_words_alpha.txt", "utf-8")).split("\r\n") | |
| for(let i in dict){ | |
| let word = dict[i] | |
| let letters = [...word] | |
| let chars = letters.map(v=>v.charCodeAt()) | |
| let maxDist = 0 | |
| for(let j = 0; j < chars.length-1; j++) | |
| for(let k = j+1; k < chars.length; k++) | |
| maxDist = Math.max(maxDist, Math.abs(chars[j] - chars[k])) | |
| if(maxDist <= 3 && word.length > 4) | |
| log(word, maxDist) | |
| if((+i+1) % 500 == 0){ | |
| await sleep(10) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment