diff --git a/JavaTriesWithFrequencies.m b/JavaTriesWithFrequencies.m index e31d3740..e39901c2 100644 --- a/JavaTriesWithFrequencies.m +++ b/JavaTriesWithFrequencies.m @@ -166,6 +166,9 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc. that corresponds to sw. Note that only a leading part of sw can be found jTr. \ The last found element of sw is the root of the returned sub-trie." +JavaTrieJSONRootToLeafPaths::usage = "Gives lists of key-value pairs corresponding to the root-to-leaf paths\ + in a given trie. (Using a JSON string.)" + JavaTrieRootToLeafPaths::usage = "Gives lists of key-value pairs corresponding to the root-to-leaf paths\ in a given trie." @@ -382,11 +385,20 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc. If[res === Null, {}, res] ]; -Clear[JavaTrieRootToLeafPaths] -JavaTrieRootToLeafPaths[jTr_?JavaObjectQ] := +Clear[JavaTrieJSONRootToLeafPaths] +JavaTrieJSONRootToLeafPaths[jTr_?JavaObjectQ] := Map[{"key", "value"} /. # &, ImportString[TrieFunctions`pathsToJSON[TrieFunctions`rootToLeafPaths[jTr]], "JSON"], {2}]; +Clear[JavaTrieRootToLeafPaths] +JavaTrieRootToLeafPaths[jTr_?JavaObjectQ] := + Block[{pathsObj, keyPaths, valuePaths}, + pathsObj = JLink`ReturnAsJavaObject[ TrieFunctions`rootToLeafPaths[ jTr ] ]; + keyPaths = JLink`JavaObjectToExpression[TrieFunctions`pathsKeys[ pathsObj ]]; + valuePaths = JLink`JavaObjectToExpression[TrieFunctions`pathsValues[ pathsObj ]]; + MapThread[Transpose[{#1,#2}]&, {JLink`JavaObjectToExpression/@keyPaths, JLink`JavaObjectToExpression/@valuePaths}] + ]; + Clear[JavaTrieRegexRemove] JavaTrieRegexRemove[jTr_?JavaObjectQ, regex_String ] := TrieFunctions`removeByKeyRegex[jTr, regex];