Check if a token is a name
This commit is contained in:
5
build.hxml
Normal file
5
build.hxml
Normal file
@@ -0,0 +1,5 @@
|
||||
-lib yaml
|
||||
-lib kiss
|
||||
-cp src
|
||||
--main bad_nlp.Main
|
||||
--interp
|
18
haxelib.json
Normal file
18
haxelib.json
Normal 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
7
src/bad_nlp/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package bad_nlp;
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
Main_.main();
|
||||
}
|
||||
}
|
13
src/bad_nlp/Main_.kiss
Normal file
13
src/bad_nlp/Main_.kiss
Normal 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
12
src/bad_nlp/Names.hx
Normal 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
27
src/bad_nlp/Names.kiss
Normal 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)))
|
Reference in New Issue
Block a user