Libraryless. Click here for Pure Java version (11989L/85K).
1 | static PTElement ai_parseToTreeWithCurlyPhrases(S input) { |
2 | ret ai_parseToTreeWithCurlyPhrases(input, new AI_BottomUpParser1); |
3 | } |
4 | |
5 | static PTElement ai_parseToTreeWithCurlyPhrases(S input, AI_BottomUpParser1 parser) { |
6 | L<S> tok = javaTokPlusBrackets(input); |
7 | tok = dropPunctuation(tok); |
8 | //pnlStruct(tok); |
9 | |
10 | // Pre-parse curly fragments & guess categories for unknown words |
11 | Map<S, Map<S, Double>> guessMap = new HashMap; |
12 | parser.wordsToCategories = DerivedMap(ai_wordToCategories()); |
13 | for (int i = 1; i < l(tok); i += 2) { |
14 | S t = tok.get(i); |
15 | if (isCurlyBraced(t)) { |
16 | tok.set(i, t = uncurly(t)); |
17 | PTElement tree = ai_parseToTreeWithGuessing(t); |
18 | if (tree != null) { |
19 | //preparsed.put(i, tree); |
20 | //print(className(tree)); |
21 | //print(ai_renderCulledParseTree(tree)); |
22 | |
23 | if (!tree instanceof ChooseCategory) |
24 | print("Weird: " + className(tree)); |
25 | else { |
26 | for (HaveCategory c : (L<HaveCategory>) (L) tree.children) |
27 | subHashMap(guessMap, t).put(c.category, c.totalWeight); |
28 | } |
29 | } else { |
30 | //print("No parse for " + t); |
31 | } |
32 | } else if (ai_isUncategorizedWord(t)) |
33 | guessMap.put(t, ai_guessCategoriesForUnknownWord_weighted(t)); |
34 | } |
35 | |
36 | temp tempSetThreadLocal(ai_getWordToCategoryWeight_map, guessMap); |
37 | for (S word : keys(guessMap)) |
38 | parser.wordsToCategories.put(word, keys(guessMap.get(word))); |
39 | ret ai_parseBottomUpToTree(parser, tok); |
40 | } |
Began life as a copy of #1017403
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017685 |
Snippet name: | ai_parseToTreeWithCurlyPhrases (Parser v3) |
Eternal ID of this version: | #1017685/3 |
Text MD5: | 4b397020203a9808dcf3899b4e2353c2 |
Transpilation MD5: | 5f4e42cbe1cd124d5dee0b8bb98ad7a8 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-10 11:32:41 |
Source code size: | 1502 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 412 / 513 |
Version history: | 2 change(s) |
Referenced in: | [show references] |