From a9f83ba3b29c09d1bd01c2e7740099c3a6cdd4da Mon Sep 17 00:00:00 2001 From: Anton Antonov Date: Wed, 15 Nov 2017 06:34:38 -0800 Subject: [PATCH] New implementation of JavaTrieRootToLeafPaths; moved the previous one into JavaTrieJSONRootToLeafPaths. --- JavaTriesWithFrequencies.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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];