Visualizing binary trees in Java and C++ - java

Is there any way I could visualize a binary tree in java and C++? It could be a plugin for eclipse or VC++(although I dont think a plugin would be capable) or, it could be a library that enables you to draw them. I want to do this with the minimum amount of work possible. I can do it now with C++ and Win32 but that isn't an option because it requires too much time to code the damned thing. I also know that there might not be quite a simple solution to this, but I am looking for the best possible one out there, for both languages. The BST structure I talk of here will be custom, not a library one.
Thanks!

I think AT&T graphviz and its dot.exe is as easy as it gets to use. You can all it from inside Java if you must.

If you can output your binary tree in DOT format, it's pretty easy to visualize it. DOT is a super simple language which you should be able to emit in just a few lines of code. An example looks like this:
digraph graphname {
a -> b -> c;
b -> d;
}
Which generates http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/DotLanguageDirected.svg/168px-DotLanguageDirected.svg.png
Wikipedia has more: http://en.wikipedia.org/wiki/DOT_language

If you just want to visualize it for debugging and are using a Unix-like operating system, you can try ddd.

Related

Discrete Wavelet Transform (DWT) and Stationary Wavelet Transform (SWT) in Java

I want to apply DWT and SWT to images in Java but can't find code, pseudocode or libraries for that. Until now, I only found existing code in other languages like C, C++ or Python but I need it in Java and I'm not able to change the code from one to another language on my own.
Does anyone know a library or another way I could use to solve this problem?
Thanks in advance!
Detailed description of the problem:
I want to apply DWT or SWT to an image and then do some further calculations with specific DWT/SWT subbands e.g. applying Discrete Cosine Function (DCT) to the LL-subband. If possible, I want to work with BufferedImages.

defining linear equations in Java

I am trying to implement a paper and I am facing problem while representing linear equations mentioned in the paper. I am using LPsolve (linear problem solver) to solve the equations. But not able to represent some equations in Java so that LPSOLVE can resolve. Anyone with expertise in this please do help me.
paper i am trying to implement is http://www.cs.cmu.edu/~dshahaf/kdd2010-shahaf-guestrin.pdf and equations are mentioned in section 2.2.1
Based on what I can tell, you seem to have trouble figuring out o implementing some functions that would represent how certain mathematical functions work. It doesn't sound like you've run into an error, so I'll write down a few tips I can think of.
First off, check if the functions you are looking for already exist in the basic library by taking a look in the documentation. Maybe it doesn't state it exactly like you want, but perhaps some of the functionality is there.
http://lpsolve.sourceforge.net/5.5/Java/docs/api/
If you can't find everything you want, then you've got two options. One is to program the functions you desire yourself, and the other is to use another fleshed out Java library such as Colt which has many features.
http://dst.lbl.gov/ACSSoftware/colt/

Tool for creating own rules for word lemmatization and similar tasks

I'm doing a lot of natural language processing with a bit unsusual requirements. Often I get tasks similar to lemmatization - given a word (or just piece of text) I need to find some patterns and transform the word somehow. For example, I may need to correct misspellings, e.g. given word "eatin" I need to transform it to "eating". Or I may need to transform words "ahahaha", "ahahahaha", etc. to just "ahaha" and so on.
So I'm looking for some generic tool that allows to define transormation rules for such cases. Rules may look something like this:
{w}in -> {w}ing
aha(ha)+ -> ahaha
That is I need to be able to use captured patterns from the left side on the right side.
I work with linguists who don't know programming at all, so ideally this tool should use external files and simple language for rules.
I'm doing this project in Clojure, so ideally this tool should be a library for one of JVM languages (Java, Scala, Clojure), but other languages or command line tools are ok too.
There are several very cool NLP projects, including GATE, Stanford CoreNLP, NLTK and others, and I'm not expert in all of them, so I could miss the tool I need there. If so, please let me know.
Note, that I'm working with several languages and perform very different tasks, so concrete lemmatizers, stemmers, misspelling correctors and so on for concrete languages do not fit my needs - I really need more generic tool.
UPD. It seems like I need to give some more details/examples of what I need.
Basically, I need a function for replacing text by some kind of regex (similar to Java's String.replaceAll()) but with possibility to use caught text in replacement string. For example, in real world text people often repeat characters to make emphasis on particular word, e.g. someoone may write "This film is soooo boooring...". I need to be able to replace these repetitive "oooo" with only single character. So there may be a rule like this (in syntax similar to what I used earlier in this post):
{chars1}<char>+{chars2}? -> {chars1}<char>{chars2}
that is, replace word starting with some chars (chars1), at least 3 chars and possibly ending with some other chars (chars2) with similar string, but with only a single . Key point here is that we catch on a left side of a rule and use it on a right side.
I am not an expert in NLP, but I believe Snowball might be of interest to you. Its a language to represent stemming algorithms. Its stemmer is used in the Lucene search engine.
I've found http://userguide.icu-project.org/transforms/general to be useful as well for some general pattern/transform tasks like this, ignore the stuff about transliteration, its nice for doing a lot of things.
You can just load up rules from a file into a String and register them, etc.
http://userguide.icu-project.org/transforms/general/rules

What is a language for sound control

I'm trying to make a program that roughly does the following:
produceBeepSound(double loudness);
can I do such a thing in Java? I need it to be very precise. What about matlab? Which language would be best for this task. The language must have a GUI component.
You can use Java Media Framework to produce sound but it is not necessary because you can work with javax.sound.sampled package and integrate it with Java Swing.
In python take a look at pyaudio library and also take a look at PythonInMusic it has a whole lot of collection of various A/V module.
Also, take a look at Beeper.
It is a GUI program, using only J2SE classes, that can produce a sound
of configurable tone & duration, and (with a bit of tweaking) at
different raw volumes
Thanks to #Andrew for once again correcting me.
In MATLAB, just use the SOUND function:
http://www.mathworks.com/help/techdoc/ref/sound.html
You can specify a vector which represents your signal, and the amplitude on that vector will determine loudness, so its a matter of simple scaling.
you can try Csound. There is API for java.
You should also check this wiki page: http://en.wikipedia.org/wiki/Comparison_of_audio_synthesis_environments.
But if you need somthing simple you can try:
java.awt.Toolkit.beep();
or
System.out.println((char)7);
But you won't have volume control.
Probably my favourite approach would be HTML 5 audio api - https://wiki.mozilla.org/Audio_Data_API#Writing_Audio
on windows actually any language can emit a sound just outputting ascii character "\007". Here is a nice article about how to do it in java.

How do I make my own parser for java/jsf code?

Hi I'd like to make my own 'parser', e.g: computing (4+(3-4^2))*2 or
parsing java,jsf,html code.
In fact I did something like this but I feel it's not good.
Is there anything good for me? I've tried to read more, but I'm bit confused, LL, LR, AST,BNF,javacc yacc etc :). I'm not sure which way to go, when I would like to compute 4+...
or if I'd like to parse java,jsf code and produce something from this(another java code)
Is there anything generaly good enough like ast? or something which I can use for both?
thank you for help.
Before anything else, you have to understand that everything about parsing is based on grammars.
Grammars describe the language you want to implement in terms of how to decompose the text in basic units and how to stack those units in some meaning ful way. You may also want to look for the token, non-terminal, terminal concepts.
Differences between LL and LR can be of two kinds: implementation differences, and grammar writing differences. If you use a standard tool you only need to understand the second part.
I usually use LL (top-down) grammars. They are simpler to write and to implement even using custom code.
LR grammars theoretically cover more kinds of languages but in a normal situation they are just a hindrance when you need some correct error detection.
Some random pointers:
javacc (java, LL),
antlr (java, LL),
yepp (smarteiffel, LL),
bison (C, LR, GNU version of the venerable yacc)
Parsers can be pretty intense to write. The standard tools are bison or yacc for the grammar, and flex for the syntax. These all output code in C or C++.
ANTLR is probably the way to go for java. It is a little intense, the book is apparently very good (I have only struggled with the online docs).
If you can stretch to other languages, then lex/yacc (or flex/bison) is the standard for C although I wouldn't particularly recommend either of those combinations (steep learning curve, showing their age a little now).
Python has about a million parsers available (SimpleParse, Yapps) or there is TreeTop for Ruby - the developer even has a demo that does simple calculations as in your question - but note that this won't do everything that a LALR parser can accomplish.
If it is a learning exercise, try starting with a top-down parser -- they are simple to write and don't require including/learning any other tools. Best place to research the basics is probably wikipedia or code-project.
ANTLR, but make sure you read The Definitive ANTLR Reference, which will walk you through the creation of parsers. ANTLR does top-down, LL parsers, so the book doesn't address LALR and other types.
JavaCC, Yacc, are SableCC are more traditional lexer/parser generators, and you'll find that they're a little more primitive and have steeper learning curves. ANTLR is equally powerful, but you don't have to learn it all at once. Wikipedia offers a comprehensive comparison of parser generators.
BNF is a syntax for specifying the grammar; ANTLR uses its own, which I find more aesthetic but which others often don't.
You might want to check out http://antlr.org/. It will output java code. If I recall, one of their samples is pretty much what you want.
You might want to check out Building Parsers With Java by Steven John Metsker. The book seems to cover exactly what you are looking to do.
Using tools which generate Lexers and Parsers is generally far easier than writing your own from scratch.
In addition to whats already been listed, you could use things like JLex with CUP to create a simple interpreter for things like arithmetic expressions very easily.

Categories