Commit d0739fac authored by Siltaar's avatar Siltaar
Browse files

add Python reimplementation ; remove ReasonML attempt

parent eb59ee64
......@@ -60,8 +60,8 @@ This clear separation between code and data is wanted to ease the re-use of
`month_nb.json` data structure with other languages, to reimplement a
`month_nb` feature.
An experimental *Python implementation* is provided with currently only 49
working languages.
An experimental *Python implementation* is provided with currently 49
working languages (only).
== Supported languages
......@@ -89,6 +89,23 @@ programming languages to re-use it (but would complicate the maintenance of
the tree).
== Update month definitions
To update the definitions, download a new copy of `Appendix:Months_of_the_year`
and run the `phantomjs_gen_def.js` script :
```sh
$ cd month_definitions
$ wget https://en.wiktionary.org/wiki/Appendix:Months_of_the_year
$ phantomjs phantomjs_gen_def.js <1>
```
<1> `phantomjs` is from the eponymous Debian package.
Then clean the `.json` file from error logging of phantomjs, and add the
"numeric" first line (that you can copy from the previous `.json` definition
file).
== Running tests
To test `month_nb.js` against the language definition file, run :
......@@ -101,8 +118,7 @@ The `node` v10.15.2 command comes from the `nodejs` package on Debian-based
distributions. The `node-fetch` and `node-requirejs` packages are also
required.
It will display various informations about the working languages and possible
errors.
It will display various informations about the working and broken languages.
== Who uses it ?
......@@ -116,26 +132,8 @@ errors.
The Wiktionary snapshot page of
https://en.wiktionary.org/wiki/Appendix:Months_of_the_year[Appendix:Months_of_the_year]
used is from 2019-09-18. 14 languages were added since the 2013 version of the initial release of `month_nb`.
==== Create new definitions
To update the definitions, download a new copy of `Appendix:Months_of_the_year` and run the `phantomjs_gen_def.js` script :
```sh
$ cd month_definitions
$ wget https://en.wiktionary.org/wiki/Appendix:Months_of_the_year
$ phantomjs phantomjs_gen_def.js <1>
```
<1> `phantomjs` is from the eponymous Debian package.
Then clean the `.json` file from error logging of phantomjs, and add the
"numeric" first line (copied from the previous `.json` definition file.
==== Run tests and update `month_nb.json` accordingly
Running the `test_month_nb.mjs` file will point out the months and langs that
are not working properly and that need to be fixed.
used is from 2019-09-18. 14 languages were added since the 2013 version of the
initial release of `month_nb`, they are not supported yet.
=== Node packaging
......
#!/bin/env python3
import json
from month_nb import month_nb
......
(executable
(name month_nb)
(libraries yojson)
)
// Name: month_nb.js
// Desc: returns month number from given litteral case-insensitive name or abbreviation
// Author: Simon 'Siltaar' Descarpentries ; siltaar § acoeuro ' com
// Version: 3
// Licence: GPLv3
/*
const month_nb = function(a, check_keys=false) {
var keys = [Object.keys(month_nb_json)];
var objs = [month_nb_json];
var o_ks = keys[keys.length-1];
var o = objs[objs.length-1];
var r_range = '';
while(o_ks.length) {
let k = o_ks.shift();
// console.log(a +' '+ k);
if (check_keys) { // show chars out of lang range in keys
if (keys.length == 1) {
str_r_range = `${k.slice(1,k.length-1)}|[\\$\\.\\?\\^\\(\\)\\|\\[\\] ])`;
r_range = new RegExp(str_r_range, 'gi');
} else if (keys.length > 1) {
char_to_remove = k.replace(r_range, '');
if (char_to_remove.length > 1) {
console.log(str_r_range);
console.log(`You should remove ${char_to_remove} from ${k}`);
}
}
}
let r = new RegExp(k, 'i');
if (r.test(a)) {
o = o[k];
if (typeof(o) === 'number') {
return o;
} else if (typeof(o) === 'object') {
objs.push(o);
o_ks = Object.keys(o);
keys.push(o_ks);
} else {
throw 'The JSON language-regexp-tree structure should only contain string '+
'keys as nodes, sub-objects as branchs and number leafs';
}
} else if (o_ks.length == 0) {
objs.pop(); // backtrack
o = objs[objs.length-1];
keys.pop();
// console.log(`depth level ${keys.length}`);
if (keys.length) {
o_ks = keys[keys.length-1];
// console.log(`keys to explore ${o_ks.length}`);
} else {
// console.error(`Did not found for ${a}.`);
return undefined;
}
}
}
};*/
open Yojson.Basic
open Yojson.Basic.Util
let month_nb_json = from_file ("../../month_nb.json")
let () = print_endline(show(member("comment", month_nb_json)))
#!/bin/zsh
eval $(opam env)
opam switch create month_nb ocaml-base-compiler.4.05.0
ERROR] Solver failed: "/usr/bin/aspcud /home/siltaar/.opam/log/solver-in-14825-9b8556
/home/siltaar/.opam/log/solver-out-14825-7afd23
-count(removed),-sum(request,version-lag),-count(down),-sum(solution,version-lag),-count(changed)"
opam switch create month_nb ocaml-system.4.05.0
[ERROR] Solver failed: "/usr/bin/aspcud /home/siltaar/.opam/log/solver-in-15846-9b8556
/home/siltaar/.opam/log/solver-out-15846-7afd23
-count(removed),-sum(request,version-lag),-count(down),-sum(solution,version-lag),-count(changed)"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment