If you use specific language with DataMelt, such as Jython, you can use the full set of Python commands. However, DataMelt has a number of useful utilities implemented in Java which can be rather handy and can be called from Java, Jython, Groovy and JRuby using exactly the same options.
To make our example short, we will use Jython coding to access these Java tools.
Downloading data from the web
You can download a file from the web using the class jhplot.Web. Here is an example:
http='http://datamelt.org/examples/data/' print Web.get(http+"mnist.zip")
This example downloads the file "mnist.zip" to the current directory.
Dynamically load external jar file
The same class allows to use external jar files from URL. You can use this method:
print Web.load("url to a jar file")
It does the following: It downloads a jar file from the given URL, save it to the directory "lib/user" inside the installation path of DataMelt, and load this jar file so you can imidiately start using it. Here is an example:
# This example shows how to download a jar library, # dynamically load it and execute a class from the downloaded library. # The downloaded jar will be located in lib/user directory. # Second execution will skip the download from jhplot import Web url="http://central.maven.org/maven2/it/unimi/dsi/fastutil/8.2.2/fastutil-8.2.2.jar" print "Loading ",url print Web.load(url) from it.unimi.dsi.fastutil.longs import Long2IntAVLTreeMap m =Long2IntAVLTreeMap() # Now we can easily modify and access its content m.put(1, 5) m.put(2, 6) m.put(3, 7) m.put(1000000000L, 10) print m
It does the following: It downloads Fastutil java library from , load dynamically to the Java class path (at runtime), and executes a class from this library.
Zipping and unziping files
You can unzip file in the current foulder (or any directory) using jhplot.IO
The print command prints the status of the download. You can remove "print", and the command will unzip the file quietly.
There is a similar class tig.Zip whoch can zip and unzip files.
Working with files
There is another useful class tig.Files which can do some file manipulations. The Java class jhplot.utils.FileList can list all files in all sub-directories of a given directory. The output is an array with file names.
Showing colors and fonts
The Java class jhplot.utils.ShowColors shows a dialog with available colors.
Similarly, you can look at available fonts in your system using jhplot.utils.ShowFonts