Elki plots from pure Java API - java

I've been searching for a way to export ELKI generated visualization into SVG file, which can later be displayed on my application. However, I could not find any example code which uses typical java constructors. My goals are:
input Results in a Visualization.
set VisualizerParameterizer constructor, adding the previous Visualization.
set ExportVisualizations constructor properly to write the file.
For instance, let's say I already have an OutlierResult instance and now I want to plot the scores using BubbleVisualization and produce an SVG file? How can I do that using the pure Java API?

Some classes like VisualizerParameterizer can be a bit annoying to set up manually, because this involves finding all desired visualization factories from the service loader - there is a plug-in layer there, that allows to add new visualizations to be rendered automatically.
Because of this, the easiest way is to use the parameterization API, for example (git style):
ExportVisualizations export = new ELKIBuilder<>(ExportVisualizations.class)
.with(ExportVisualizations.Parameterizer.FOLDER_ID, "folder")
.build();
or if you are still using an old release / do not like builders:
ListParameterization params = new ListParameterization();
params.addParameter(ExportVisualizations.Parameterizer.FOLDER_ID, "folder");
ExportVisualizations export = ClassGenericsUtil.parameterizeOrAbort(
ExportVisualizations.class, params);
Because you only need to give mandatory parameters, and it can construct nested objects. In this case, it will also construct the VisualizerParameterizer, so you can also add options for that class, such as
.with(VisualizerParameterizer.Parameterizer.ENABLEVIS_ID, "scatter")
to only enable scatter plot visualizations.

Related

In geotools ,how to use Geometry as feature source add into layer?

In geotools ,how to use geometry as feature source add into layers?
I know that .shp file can add into layers, and add into content,then we can show it.
I read it in geotools quickstart:
http://docs.geotools.org/latest/userguide/tutorial/quickstart/intellij.html
but I want to show the geometry object in content, I need to use geometry object as feature source replace shap file.(It's right?)
So how to do it? I only konw that how to get geometry's WKT and geojson.
thank you!
GeoTools will only display Features so you need to create a Feature and add your Geometry object to the feature. You will also need to know the projection of your geometry if you plan to display it with other data sets (e.g. shapefiles).
If you look at the Feature Tutorial you will see a worked example of how to create a FeatureType and how to make Features using it. The QuickStart tutorial shows how to display features on the screen.
The utility class DataUtilities provides methods for converting lists of features to FeatureCollections and FeatureSources.
You mention WKT and GeoJSON as possible sources so you will want to explore the JTS.WKTReader and the gt-geojson module for help parsing those formats into Geometries that GeoTools can make use of.

Creating and training a model for OpenNlp using BRAT?

I may need to create a custom training set for OpenNLP, and this will require me to manually annotate a lot of entries.
To make things easier, a GUI solution may be the best idea (manually writing annotation tags it's not cool), and I've just discovered BRAT which looks like what I need.
BRAT can export an annotated file (.ann), but I'm not finding any reference to this filetype in OpenNLP's manual and I'm not sure that this can work.
What I'd like to do is to export this annotated file from BRAT and use it to train an OpenNLP's model, and I don't really care if it can be done using code or CLI.
Can someone point me in the right direction?
OpenNLP has native support for the BRAT format for training and evaluation of the Name Finder. Other components are not supported currently. Adding support for other components would probably not be difficult and in case you are interested you should ask for it on the opennlp-dev list.
The CLI can be used to train a model with brat, here is the command which will show you the usage:
bin/opennlp TokenNameFinderTrainer.brat
The following arguments are mandatory to train a model:
bratDataDir this should point to a folder containing your .ann and .txt files
annotationConfig this has to point to the config file brat is using for annotation project
lang the language of your text documents (e.g. en)
model the name of the created model file
The Name Finder needs its input cut into sentences and into tokens. By default it assumes one sentence per line and applies white space tokenization. This behavior can be adjusted with the ruleBasedTokenizer or tokenizerModel arguments. Additional it is possible to use a custom sentence detector model via the sentenceDetector Model argument.
To evaluate your model the cross validation and evaluation tools can be used in a simliar way by attaching .brat to their names.
bin/opennlp TokenNameFinderCrossValidator.brat
bin/opennlp TokenNameFinderEvaluator.brat
To speed up your annotation project you can use the opennlp-brat-annotator. It can load the Name Finder model and integrates with BRAT to automatically annotate your documents. This can speed up your annotation effort. You can find that component in the opennlp sandbox.

Automatically generate Java code based on existing fields in a class

Scenario
I'm working with a Java model built from scratch in Eclipse. What's important in this model is that we save our output to MATLAB (.mat) files. I constantly add new features, which require new fields that in turn will have to be exported to the .mat file at every iteration. Upon restarting a crashed simulation, I might have to import the .mat file. To export or import my .mat file I use JMatIO.
For example, if I would add a new field rho_m (a simple double) to my class CModel, I have to add to my Save() method:
mlModel.setField("rho_m", new MLDouble(null, new double[] {rho_m}, 1));
And to my Load() method:
rho_m = ((MLDouble)mlModel.getField("rho_m")).getReal(0);
Note that even though rho_m is a double, it needs to be treated as a double[] in JMatIO. This probably has something to do with MATLAB being orientated towards matrices and matrix operations.
Problem
Instead of doing this manually (prone to errors, annoying to maintain) I would like to automate this procedure. Ideally, I would like my IDE to detect all the fields in CModel and write the code based on the field's name and type. Is there any way to do this in Java/Eclipse?
Ideas so far
I have no formal training in low-level programming languages (yes, Java is low-level to me) and am still relatively new to Java. I do have some experience with MATLAB. In MATLAB I think I could use eval() and fieldnames() in a for loop to do what I mentioned. My last resort is to copy-paste the Java code to MATLAB and from there generate the code using a huge, ugly script. Every time I want to make changes to the model I'd rerun the MATLAB script.
Besides that idea I've found terms like UML, but do not have the background knowledge to figure out if this is what I'm looking for or not.
Any help, even if it's just a small push in the right direction, is greatly appreciated. Let me know if I need to further clarify anything.
Looking at your scenario, you are doing model-driven code generation, that is, you have a model and want to get some code generated according to your current model. Therefore, you need a model-driven code generator.
I lead the ABSE/AtomWeaver project, so I'll outline what you can do to get what you want using AtomWeaver (There are however other solutions like MetaEdit+, XText or Eclipse's own GMT/EMF sub-system).
AtomWeaver is an IDE where you can build a model and generate code from that model. You can change your model as many times you want and hit the "Generate" button to get an updated version of your code. ABSE is the name of the modeling method.
We don't need to go into details, but essentially ABSE follows a "building-block" approach. You create a Template that represents a feature or concept of your model. Then, you can associate a mini-code generator just to that concept. You can then "instantiate" and combine those building blocks to quickly build your models. Variables increase the flexibility of your models.
You can also change your models, or add new features ("blocks") and generate again. The generators are built using the Lua programming language, a very simple language with C-Like syntax.
The best way to understand the ABSE development method and the AtomWeaver IDE is to download the IDE and see the samples or try the tutorials. And yes, you can use AtomWeaver for free.

Instantiating Rhinoscript Native Objects from Java/Scala

I'm trying to improve the performance of a javascript snippet evaluator. These script snippets can reference any number of variables that exist in a string-keyed map of json-like object graphs (IE: Json AST). I'm using JDK 1.6 and the embedded Rhinoscript engine (v1.6R2).
Currently, processing takes the form:
Snippet is parsed to discover the names of referenced variables
Variables are retrieved from the map and serialized to a json string
Json string is assigned to a similarly named variable at the start of the script
Evaluate augmented script
I'm trying to figure out how to skip the json serializing stage and create direct Rhinoscript native objects to place in the 'bindings' for the script. The desired steps would then be:
Snippet is parsed to discover the names of referenced variables
Variables are retrieved from the map and converted to native Rhinoscript equivalents
Native objects are placed in bindings
Evaluation of original script with said bindings
Do you know where I could find documentation or examples of how to instantiate native rhinoscript objects?
My scala learning project might be of some use if you want to tinker. And any answer I come up with should appear there too...
http://subversion.assembla.com/svn/freshcode_public/learn_scala/datastore/src/test/scala/pkg/script
Thanks in advance.
So after much fiddling I've come up with an adequate solution although it did not yield the performance increase I had hoped for (only 10% faster).
The solution is specific to Scala / Lift / Json and is contained in the ScriptingUtil.scala file.
To summarise:
Context.javaToJs() does not seem to work in all cases. (java.lang.RuntimeException: No Context associated with current Thread)
A 'scope' object of type Scriptable is needed. The solution I came up with isn't pretty but it works.
To create a NativeArray:
val na = new NativeArray(arr)
na.setPrototype(ScriptableObject.getClassPrototype(scope, "Array"))

java dyn parser

Im a novice java-programer, whos trying to create a small java app.
In the program im working on, I want to load the configurations from different ini-files.
The basic idea is, that I would have a library containing all the config files, the parser should read all of them and make configurations named after their filenames.
The parser should be created to work dynamicly, so it can read different types of configs.
example
House.ini
-> type0
-> id name height witdh length price_based_on_dimensions
-> id1 name1 height witdh length price_based_on_dimensions
These data should be saved to a config object named config.house. The tricky part is that a different config file, can have its type = type0 but with a different number of attributtes.
I realise that there is no simply solution to this, but any help and or guides to create a dynamic parser is welcome
I'm not really clear on the output you want to produce, but a Java INI parsing library might be a good place to start. For that, you should use ini4j.
Other then ini4j (which is a really good library) I personally prefer to use xml config files. To me they are easier to use and allow for easier configuration

Categories

Resources