From 221bfd6644a39b78df35e3c9d476dd67e4dee43d Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 20 Mar 2023 18:48:55 -0600 Subject: [PATCH] Check if a token is a name --- build.hxml | 5 +++++ haxelib.json | 18 ++++++++++++++++++ src/bad_nlp/Main.hx | 7 +++++++ src/bad_nlp/Main_.kiss | 13 +++++++++++++ src/bad_nlp/Names.hx | 12 ++++++++++++ src/bad_nlp/Names.kiss | 27 +++++++++++++++++++++++++++ test.sh | 3 +++ 7 files changed, 85 insertions(+) create mode 100644 build.hxml create mode 100644 haxelib.json create mode 100644 src/bad_nlp/Main.hx create mode 100644 src/bad_nlp/Main_.kiss create mode 100644 src/bad_nlp/Names.hx create mode 100644 src/bad_nlp/Names.kiss create mode 100755 test.sh diff --git a/build.hxml b/build.hxml new file mode 100644 index 0000000..adbf6eb --- /dev/null +++ b/build.hxml @@ -0,0 +1,5 @@ +-lib yaml +-lib kiss +-cp src +--main bad_nlp.Main +--interp \ No newline at end of file diff --git a/haxelib.json b/haxelib.json new file mode 100644 index 0000000..fffc734 --- /dev/null +++ b/haxelib.json @@ -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" +} \ No newline at end of file diff --git a/src/bad_nlp/Main.hx b/src/bad_nlp/Main.hx new file mode 100644 index 0000000..5b097c2 --- /dev/null +++ b/src/bad_nlp/Main.hx @@ -0,0 +1,7 @@ +package bad_nlp; + +class Main { + static function main() { + Main_.main(); + } +} diff --git a/src/bad_nlp/Main_.kiss b/src/bad_nlp/Main_.kiss new file mode 100644 index 0000000..ff1ff32 --- /dev/null +++ b/src/bad_nlp/Main_.kiss @@ -0,0 +1,13 @@ +(doFor name [ + "Finn" + "Miguel" + "George" + "Ernest" + "Crawford" + "Howard" + "Troy" + "Tracy" + "Valeria" + "Vanessa" + ] + (Names.isName name)) diff --git a/src/bad_nlp/Names.hx b/src/bad_nlp/Names.hx new file mode 100644 index 0000000..69ab5a8 --- /dev/null +++ b/src/bad_nlp/Names.hx @@ -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 {} diff --git a/src/bad_nlp/Names.kiss b/src/bad_nlp/Names.kiss new file mode 100644 index 0000000..fb84ff0 --- /dev/null +++ b/src/bad_nlp/Names.kiss @@ -0,0 +1,27 @@ +(var :Map loadedNameFiles (new Map)) +(var :Map 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 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))) \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..0ee8ae9 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +haxe build.hxml \ No newline at end of file