1 | sclass EnglishDateParser > DateStructures { |
2 | bool assumeFuture = true; // e.g. for "tuesday" [not used] |
3 | ProbabilisticMachine2 pm; |
4 | LS tok; // tokenized input |
5 | |
6 | class CompletedParse extends ProbabilisticMachine2.State { |
7 | IntRange tokenRange; // what did we parse |
8 | SomeDate interpretation; // what do we think it means |
9 | } |
10 | |
11 | |
12 | record ParseYear(int iTok) extends ProbabilisticMachine2.State { |
13 | int minTokensToConsume = 0; |
14 | |
15 | double calcProbabilityForMatchedText(S s) { |
16 | } |
17 | |
18 | void step { |
19 | int maxTokensToConsume = state.remainingTokens(); |
20 | } |
21 | |
22 | @Override |
23 | void run(State state) { |
24 | |
25 | if (verbose) print(this + ": maxTokensToConsume= " + maxTokensToConsume); |
26 | |
27 | for (int n = minTokensToConsume; n <= maxTokensToConsume; n++) { |
28 | State s = state.prepareClone(); |
29 | s.iNextToken += n*2; |
30 | LS tok = subList(state.tok, state.iNextToken, s.iNextToken-1); |
31 | s.probability = multiplyPercentages(s.probability, calcProbabilityForMatchedTokens(tok)); |
32 | s.matches = revChainPlus(s.matches, pair(state, tok)); |
33 | pm.addState(s); |
34 | } |
35 | } |
36 | } |
37 | |
38 | if (isInteger(tok.get(iTok))) |
39 | ret |
40 | } |
41 | } |
42 | |
43 | record ScanFromToken(int iTok) extends ProbabilisticMachine2.State { |
44 | void step() { |
45 | if (i <= l(tok)) |
46 | } |
47 | } |
48 | |
49 | SomeDate parse(S s) null { |
50 | pm = new ProbabilisticMachine2; |
51 | tok = javaTok(s); |
52 | |
53 | // let's try to parse a year just to get started |
54 | |
55 | pm.addState(new ScanFromToken(1)); |
56 | } |
57 | } |
Began life as a copy of #1028540
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028547 |
Snippet name: | EnglishDateParser, attempt 2 [dev.] |
Eternal ID of this version: | #1028547/1 |
Text MD5: | 4abd92799999279b5b202e3c776c07fa |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-06-26 17:06:10 |
Source code size: | 1574 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 221 / 233 |
Referenced in: | [show references] |