From: Sascha Effert on
Hello,

I am implementing a key/value store, which maps Strings to Strings.
This store needs some kind of filters. These filters have to support
regular expressions, but they also have to be able to interpret the
key as a number (if it is one) to get ranges.

I would like to support awk as filter language as it can do anything I
want. I know there is jawk[1] as an Java implementation of awk. My
Problem is that the homepage only describes how to use it from the
command line, not how to use out of Java code. I would like to use the
library and give it the skript and the Input as String or as
InputStream and I would like to get the output as OutputStream or
String. Is here anybody who used jawk and can give me a hint how to do
it?

[1] http://jawk.sourceforge.net/

bests

Sascha Effert
From: Lew on
Sascha Effert wrote:
> I am implementing a key/value store, which maps Strings to Strings.
> This store needs some kind of filters. These filters have to support
> regular expressions, but they also have to be able to interpret the
> key as a number (if it is one) to get ranges.
>
> I would like to support awk as filter language as it can do anything I
>

So can Java.

> want. I know there is jawk[1] as an Java implementation of awk. My
> Problem is that the homepage only describes how to use it from the
> command line, not how to use out of Java code. I would like to use the
> library and give it the skript and the Input as String or as
> InputStream and I would like to get the output as OutputStream or
> String. Is here anybody who used jawk and can give me a hint how to do
> it?
>

What would the filter do, exactly, and why is Java not good for that?

--
Lew

From: Tom Anderson on
On Tue, 6 Jul 2010, Sascha Effert wrote:

> I am implementing a key/value store, which maps Strings to Strings. This
> store needs some kind of filters. These filters have to support regular
> expressions, but they also have to be able to interpret the key as a
> number (if it is one) to get ranges.
>
> I would like to support awk as filter language as it can do anything I
> want. I know there is jawk[1] as an Java implementation of awk. My
> Problem is that the homepage only describes how to use it from the
> command line, not how to use out of Java code. I would like to use the
> library and give it the skript and the Input as String or as InputStream
> and I would like to get the output as OutputStream or String. Is here
> anybody who used jawk and can give me a hint how to do it?

Not me. But you can get the source, so get it, and figure out how the main
class does it, then do that yourself.

I've had a quick look, and it doesn't look easy: the
central interpreter class is org.jawk.backend.AVM, and its only real
entrypoint is a method:

public int interpret(AwkTuples tuples)

Which has no obvious way to return a value - it's the moral equivalent of
'main'. If you delve a bit deeper, you find things like the PRINT opcode
being hardwired to System.out; this is clearly not code that was designed
for embedding.

I'm not saying you can't do it, just that it's going to require some major
hackery to wrap it in a facade that will let you use it as a filter.

I strongly suspect writing something far simpler from scratch (ie a
language which can express regular expressions and integer ranges) will be
an easier way of getting to the goal that is important to you.

tom

--
I DO IT WRONG!!!
From: John B. Matthews on
In article
<b02dd8ff-f992-49d5-bab4-16779d88703b(a)d37g2000yqm.googlegroups.com>,
Sascha Effert <fermat(a)uni-paderborn.de> wrote:

> I am implementing a key/value store, which maps Strings to Strings.
> This store needs some kind of filters. These filters have to support
> regular expressions, but they also have to be able to interpret the
> key as a number (if it is one) to get ranges.
>
> I would like to support awk as filter language as it can do anything
> I want. I know there is jawk[1] as an Java implementation of awk. My
> Problem is that the homepage only describes how to use it from the
> command line, not how to use out of Java code. I would like to use
> the library and give it the skript and the Input as String or as
> InputStream and I would like to get the output as OutputStream or
> String. Is here anybody who used jawk and can give me a hint how to
> do it?
>
> [1] http://jawk.sourceforge.net/

I have to agree with Tom: the home page says "Jawk can be invoked via
the JSR 223 scripting API (J2SE 6)." Awkwardly, I don't see the manifest
entries required by the JAR Service Provider specification:

<http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/>

I have to agree with Lew: You haven't mentioned anything that can't be
done with Java.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Daniel Pitts on
On 7/6/2010 5:46 AM, Sascha Effert wrote:
> Hello,
>
> I am implementing a key/value store, which maps Strings to Strings.
> This store needs some kind of filters. These filters have to support
> regular expressions, but they also have to be able to interpret the
> key as a number (if it is one) to get ranges.
Lucene handles this by converting numbers into a zero padded string.
That way, the strings lexical order is isomorphic to the numeric order.

Which brings up the point, why are you implementing this, why not use
existing libraries such as lucene?


--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>