Skip to content

Commit

Permalink
Added JavaTrieInstall that loads JLink and the corresponding JavaTrie…
Browse files Browse the repository at this point in the history
… classes.
  • Loading branch information
antononcube committed Jan 11, 2017
1 parent d555950 commit 5fec921
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions JavaTriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
JavaTrieInsert::usage = "JavaTrieInsert[ jTr_, sw:{_String..}] inserts a list of strings into the Java trie jTr.\
JavaTrieInsert[ jTr_, sws:{{_String..}..}] inserts each of the \"words\" of sws into jTr."

JavaTrieInstall::usage = "JavaTrieInstall[path_String] installs Java and loads the JavaTrie classes\
from the jar file in the specified class path."

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

JavaTrieMemberQ::usage = "Same as JavaTrieContains."
Expand Down Expand Up @@ -204,6 +207,21 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
TrieFunctions`merge[jTr, jTr2]
];

Clear[JavaTrieInstall]
JavaTrieInstall[path_String, opts:OptionsPattern[]] :=
Block[{},
Needs["JLink`"];
JLink`AddToClassPath[path];
If[ Length[{opts}] > 0,
JLink`ReinstallJava[opts],
JLink`ReinstallJava[JLink`JVMArguments -> "-Xmx2g"]
];
JLink`LoadJavaClass["java.util.Collections"];
JLink`LoadJavaClass["java.util.Arrays"];
JLink`LoadJavaClass["Trie"];
JLink`LoadJavaClass["TrieFunctions"];
];

Clear[JavaTrieNodeCounts]
JavaTrieNodeCounts[jTr_?JavaObjectQ] :=
AssociationThread[{"total","internal","leaves"}->JLink`JavaObjectToExpression[TrieFunctions`nodeCounts[jTr]]];
Expand Down

0 comments on commit 5fec921

Please sign in to comment.