Re: String wrapper that supports meta-data...

2013-01-27 Thread Stuart Sierra
On Wednesday, January 9, 2013 4:23:06 PM UTC-5, Jim foo.bar wrote:

 hehehe...I'm really stupid aren't I?:-[ 


Not at all. :) It takes time to get used to all the different ways things 
can be used, for example the fact that records support metadata.

-S
 

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en




String wrapper that supports meta-data...

2013-01-09 Thread Jim foo.bar

Hi all,

I often find myself wanting to attach meta-data to built-in Java classes 
and particularly to the 'String' class.  In a text-mining and NLP 
context, it is very useful for example to have a dictionary of strings 
where each string 'knows' its synonyms...Of course one can get around 
that by having a giant map from entities to synonyms. However, this adds 
an extra preprocessing step and also Java programmers enjoy this sort of 
encapsulation. Being able to store the synonyms as meta-data in the 
String object itself, essentially means that the object can be queried 
individually with no fuss...I'm not advocating any universally correct 
approaches here... I'm just sharing my experiences and where they led 
me...:-)

Both approaches (map-based, metadata-based) worked just fine...

In case anyone else is struggling to attach meta-data to any built-in 
Java type, here is what I did for the String class (file attached). It 
is very straight forward...basically you need to wrap the object in 
question and implement IObj...


Voila! Now MString instances support meta-data...YAY!

Jim

--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=enpackage PAnnotator.java;

import clojure.lang.IPersistentMap;
import clojure.lang.IObj;

//a wrapper around the String class that supports Clojure maps as meta-data
public final class MString implements IObj {

	private final String value;
	private final IPersistentMap meta;

	public MString(IPersistentMap meta, String value) {
		this.meta = meta;
		this.value = value;
	}
	public MString(String value) {
		this(null, value);
	}
	
	public String getString(){
	return value;
	}

	public IObj withMeta(IPersistentMap meta) {
		return new MString(meta, value);
	}

	public IPersistentMap meta() {
		return meta;
	}
}


Re: String wrapper that supports meta-data...

2013-01-09 Thread Stuart Sierra
You could also do:

(defrecord MString [string])

-S

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: String wrapper that supports meta-data...

2013-01-09 Thread Jim - FooBar();

hehehe...I'm really stupid aren't I?:-[

thanks Stuart...

Jim

On 09/01/13 21:11, Stuart Sierra wrote:

You could also do:

(defrecord MString [string])

-S
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient 
with your first post.

To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en 


--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en