Skip to content

Commit

Permalink
Workaround for Import[__,"JSON"] using UTF-8. Using classic plot them…
Browse files Browse the repository at this point in the history
…e for JavaTrieForm for V12.0.
  • Loading branch information
antononcube committed Aug 19, 2019
1 parent 3194242 commit 646196c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions JavaTriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,13 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
]
];

(*JavaTrieLeafProbabilitiesSimple[jTr_?JavaObjectQ]:=*)
(* ImportString[ StringReplace[ TrieFunctions`leafProbabilitiesJSON[jTr], "\"\"\"" -> "\"\\\"\""], "JSON"];*)
JavaTrieLeafProbabilitiesSimple[jTr_?JavaObjectQ]:=
ImportString[ StringReplace[ TrieFunctions`leafProbabilitiesJSON[jTr], "\"\"\"" -> "\"\\\"\""], "JSON"];

Block[{str},
str = StringReplace[ TrieFunctions`leafProbabilitiesJSON[jTr], "\"\"\"" -> "\"\\\"\""];
ImportString[ FromCharacterCode@ToCharacterCode[str, "UTF-8"], "RawJSON"]
];

Clear[JavaTrieNodeCounts];
JavaTrieNodeCounts[jTr_?JavaObjectQ] :=
Expand All @@ -321,8 +325,13 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
TrieFunctions`shrinkInternalNodes[jTr, sep, th];

Clear[JavaTrieToJSON];
JavaTrieToJSON[jTr_?JavaObjectQ] := ImportString[jTr@toJSON[], "JSON"];
JavaTrieToJSON[jTr_?JavaObjectQ, maxLevel_Integer ] := ImportString[jTr@toJSON[maxLevel], "JSON"];
(*JavaTrieToJSON[jTr_?JavaObjectQ] := ImportString[jTr@toJSON[], "JSON"];*)
(*JavaTrieToJSON[jTr_?JavaObjectQ, maxLevel_Integer ] := ImportString[jTr@toJSON[maxLevel], "JSON"];*)
JavaTrieToJSON[jTr_?JavaObjectQ] :=
ImportString[FromCharacterCode@ToCharacterCode[jTr@toJSON[], "UTF-8"], "RawJSON"];

JavaTrieToJSON[jTr_?JavaObjectQ, maxLevel_Integer ] :=
ImportString[FromCharacterCode@ToCharacterCode[jTr@toJSON[maxLevel], "UTF-8"], "RawJSON"];

Clear[JavaTrieRetrieve];
JavaTrieRetrieve[jTr_?JavaObjectQ, sword : {_String ..}] :=
Expand Down Expand Up @@ -477,7 +486,7 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
Options[JavaTrieForm] = Options[LayeredGraphPlot];
JavaTrieForm[jTr_?JavaObjectQ, opts:OptionsPattern[]] :=
LayeredGraphPlot[JSONTrieToRules[JavaTrieToJSON[jTr]],
opts, VertexRenderingFunction -> (Text[GrFramed[#2[[1]]], #1] &)];
opts, VertexShapeFunction -> (Text[GrFramed[#2[[1]]], #1] &), PlotTheme -> "Classic" ];


ClearAll[JavaTrieComparisonGrid];
Expand Down

0 comments on commit 646196c

Please sign in to comment.