Skip to content

Commit

Permalink
Implemented LeafProbabilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Feb 2, 2017
1 parent f60a0e3 commit 6895a3c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions JavaTriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
JavaTrieInstall::usage = "JavaTrieInstall[path_String] installs Java and loads the JavaTrie classes\
from the jar file in the specified class path."

JavaTrieLeafProbabilities::usage = "Gives the probabilities to reach the leaves of a trie."

JavaTrieMapOptimizationCall::usage = "Used for optimization calls over lists of \"words\"."

JavaTrieMemberQ::usage = "Same as JavaTrieContains."
Expand Down Expand Up @@ -247,6 +249,13 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
JLink`LoadJavaClass["TrieFunctions"];
];

Clear[JavaTrieLeafProbabilities]
JavaTrieLeafProbabilities[jTr_?JavaObjectQ] :=
ImportString[ TrieFunctions`leafProbabilitiesJSON[jTr, 1], "JSON"];

JavaTrieLeafProbabilities[jTr_?JavaObjectQ, initProb_?NumericQ ] :=
ImportString[ TrieFunctions`leafProbabilitiesJSON[jTr, initProb ], "JSON"];

Clear[JavaTrieNodeCounts]
JavaTrieNodeCounts[jTr_?JavaObjectQ] :=
AssociationThread[{"total","internal","leaves"}->JLink`JavaObjectToExpression[TrieFunctions`nodeCounts[jTr]]];
Expand Down Expand Up @@ -377,16 +386,20 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.

ClearAll[JavaTrieComparisonGrid]
SetAttributes[JavaTrieComparisonGrid, HoldAll]
Options[JavaTrieComparisonGrid] = Union[Options[Graphics], Options[Grid], {"NumberFormPrecision"->3}];
JavaTrieComparisonGrid[jTrs : {_?JavaObjectQ ..}, opts : OptionsPattern[]] :=
Block[{},
Block[{graphOpts,gridOpts,nfp},
graphOpts = Select[{opts}, MemberQ[Options[Graphics][[All, 1]], #[[1]]] &];
gridOpts = Select[{opts}, MemberQ[Options[Grid][[All, 1]], #[[1]]] &];
nfp = OptionValue["NumberFormPrecision"];
Grid[{
HoldForm /@ Inactivate[jTrs],
If[ Length[{opts}] == 0,
Map[JavaTrieForm, jTrs],
Map[JavaTrieForm[#] /. (gr_Graphics) :> Append[gr, opts] &, jTrs],
Map[JavaTrieForm, jTrs]
If[ Length[{graphOpts}] == 0,
Map[JavaTrieForm[#] /. {k_String, v_?NumericQ} :> {k, NumberForm[v,nfp]}, jTrs],
Map[JavaTrieForm[#] /. {k_String, v_?NumericQ} :> {k, NumberForm[v,nfp]} /. (gr_Graphics) :> Append[gr, graphOpts] &, jTrs],
Map[JavaTrieForm[#] /. {k_String, v_?NumericQ} :> {k, NumberForm[v,nfp]}, jTrs]
]
}, Dividers -> All, FrameStyle -> LightGray]
}, gridOpts, Dividers -> All, FrameStyle -> LightGray]
];


Expand Down

0 comments on commit 6895a3c

Please sign in to comment.