Check if a token is a name

This commit is contained in:
2023-03-20 18:48:55 -06:00
parent 2722c1ddc3
commit 221bfd6644
7 changed files with 85 additions and 0 deletions

5
build.hxml Normal file
View File

@@ -0,0 +1,5 @@
-lib yaml
-lib kiss
-cp src
--main bad_nlp.Main
--interp

18
haxelib.json Normal file
View File

@@ -0,0 +1,18 @@
{
"main": "bad_nlp.Main",
"name": "bad-nlp",
"description": "",
"classPath": "src/",
"dependencies": {
"kiss": "",
"yaml": ""
},
"url": "https://github.com/NQNStudios/kisslang",
"contributors": [
"NQNStudios"
],
"version": "0.0.0",
"releasenote": "",
"tags": [],
"license": "LGPL"
}

7
src/bad_nlp/Main.hx Normal file
View File

@@ -0,0 +1,7 @@
package bad_nlp;
class Main {
static function main() {
Main_.main();
}
}

13
src/bad_nlp/Main_.kiss Normal file
View File

@@ -0,0 +1,13 @@
(doFor name [
"Finn"
"Miguel"
"George"
"Ernest"
"Crawford"
"Howard"
"Troy"
"Tracy"
"Valeria"
"Vanessa"
]
(Names.isName name))

12
src/bad_nlp/Names.hx Normal file
View File

@@ -0,0 +1,12 @@
package bad_nlp;
import kiss.Prelude;
import kiss.List;
import yaml.Yaml;
import yaml.Parser;
import yaml.util.ObjectMap;
import sys.FileSystem;
import bad_nlp.Names;
@:build(kiss.Kiss.build())
class Names {}

27
src/bad_nlp/Names.kiss Normal file
View File

@@ -0,0 +1,27 @@
(var :Map<String,Bool> loadedNameFiles (new Map))
(var :Map<String,Bool> loadedNames (new Map))
(var libPath (Prelude.libPath "bad-nlp"))
(var namesPath (joinPath libPath "name-database"))
(function loadFilesForToken [:String token]
(let [firstLetter (token.charAt 0)
firstTwoLetters (token.substr 0 2)
familyNameFile (joinPath namesPath "family_name" firstLetter "${firstTwoLetters}.yml")
givenNameFile (joinPath namesPath "given_name" firstLetter "${firstTwoLetters}.yml")]
(loadNameFile familyNameFile)
(loadNameFile givenNameFile)))
(function loadNameFile [:String file]
(unless (or !(FileSystem.exists file) (loadedNameFiles.exists file))
(let [:Array<Dynamic> data (Yaml.read file)]
(doFor name (data.iterator)
(typeCase [name]
([:String name] (dictSet loadedNames name true))
([:AnyObjectMap map]
(dictSet loadedNames (.next (map.keys)) true))))))
(dictSet loadedNameFiles file true))
(function isName [:String token]
(let [token (token.toLowerCase)]
(loadFilesForToken token)
(loadedNames.exists token)))

3
test.sh Executable file
View File

@@ -0,0 +1,3 @@
#! /bin/bash
haxe build.hxml