Skip to content

Commit

Permalink
New implementation of JavaTrieRootToLeafPaths; moved the previous one…
Browse files Browse the repository at this point in the history
… into JavaTrieJSONRootToLeafPaths.
  • Loading branch information
antononcube committed Nov 15, 2017
1 parent d55e938 commit a9f83ba
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions JavaTriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit a9f83ba

Please sign in to comment.