From 646196c741a81c8f09b35d95f0a024211486e96f Mon Sep 17 00:00:00 2001 From: antonocube Date: Mon, 19 Aug 2019 18:44:46 -0400 Subject: [PATCH] Workaround for Import[__,"JSON"] using UTF-8. Using classic plot theme for JavaTrieForm for V12.0. --- JavaTriesWithFrequencies.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/JavaTriesWithFrequencies.m b/JavaTriesWithFrequencies.m index 6913afe4..d7232bc9 100644 --- a/JavaTriesWithFrequencies.m +++ b/JavaTriesWithFrequencies.m @@ -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] := @@ -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 ..}] := @@ -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];