Libraryless. Click here for Pure Java version (5353L/34K).
//import static main.DateStructures.*; sclass EnglishDateParser > DateStructures { bool assumeFuture = true; // e.g. for "tuesday" [not used] SomeDate parse(S s) null { new ProbabilisticParser1 parser; // action that parses a number ProbabilisticParser1.Action number = parser.new Any { double calcProbabilityForMatchedText(S s) { ret isInteger(s) ? 100 : 50; } }; LS tok = javaTok(s); BasicLogicRule rule = parser.ruleFromActions( number, parser.new ConsumeToken("/"), number, parser.new ConsumeToken("/"), number ); parser.addState(tok, rule).userObject = func(Matches m) -> SomeDate { new Day(parseInt($3), new Month(parseInt($2), new Year(parseInt($1)))) }; parser.think(); ProbabilisticParser1.State state = parser.bestDoneState(); print(state); if (state != null) { Matches m = parser.stateToMatches(state); print(m); ret (SomeDate) callF(state.userObject, m); } } }
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: | #1028544 |
Snippet name: | EnglishDateParser v2 [dev.] |
Eternal ID of this version: | #1028544/4 |
Text MD5: | 1acd37e2ffc9e6accd404ee6d17f272c |
Transpilation MD5: | 0922b76d971071b552417bcc80b4efda |
Author: | stefan |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-06-25 19:00:47 |
Source code size: | 1023 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 185 / 264 |
Version history: | 3 change(s) |
Referenced in: | -