Sg2.9
Java bridge sample code
Recent RSS
Java bridge sample code
Date:  23. September 2006, 19:04

Since there isn't much sample code out there that demonstrates how you can use Java libraries, I thought I would post some!

This code make use of LingPipe, a java library for Natural Language Processing.. This code splits a piece of text into sentences..

To install, download LingPipe, drop the .jar files into java->lib in the plug-ins folder of Illustrator..

The code I converted to javascript: SentenceChunkerDemo.java

importPackage(Packages.com.aliasi.sentences, Packages.com.aliasi.tokenizer, Packages.com.aliasi.chunk);
var text= new java.lang.String("This text is a test text. It's function is to be tested. What do you think of that, mr. test text? "I don't mind." said the test text.");
var ca= text.toCharArray();

var TokenizerFactory=new IndoEuropeanTokenizerFactory;
var SentenceModel = new MedlineSentenceModel;
var SentenceChunka = new SentenceChunker(TokenizerFactory,SentenceModel)
var chunking = SentenceChunka.chunk(ca,0,text.length());
var sentences=chunking.chunkSet();
var slice = chunking.charSequence().toString();
var i=1;
for(var it = sentences.iterator(); it.hasNext(); ){
	var sentence = it.next();
	var start = sentence.start();
	var end = sentence.end();
	print("SENTENCE "+(i++)+":");
	print(slice.substring(start,end))
}

This script produces:
SENTENCE 1:
This text is a test text.
SENTENCE 2:
It's function is to be tested.
SENTENCE 3:
What do you think of that, mr. test text?
SENTENCE 4:
"I don't mind." said the test text.

Re: Java bridge sample code
Date:  23. September 2006, 21:51

Hah.. Well when you get it figured out reliably with String.split (with less code), let me know.. Natural Language Processing comes rife with problems such as decimal points, mid sentence quotes, abbrevs etc etc.

Re: Java bridge sample code
From:  Dan
Date:  24. September 2006, 12:52

does the lingpipe code produce statistical analysis? might be fun for doing auto-generative artwork depending on the text input.. but that's just sunday morning blue sky gazing. and its raining.

Re: Java bridge sample code
Date:  24. September 2006, 13:12

It does all kinds of interesting things.. Check out the tutorials section on their site..

btw there are lots of other NLP libraries out there.. check their competition page

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Stroke Input 09.03.09