This repository has been archived by the owner on May 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Quick start
Generall edited this page Jul 20, 2016
·
4 revisions
Relevant only for version 1.2.0 and older.
Here's an example to do sentence detection.
$ echo "Pierre Vinken, 61 years old, will join the board as a nonexecutive director Nov. 29. Mr. Vinken is chairman of Elsevier N.V., the Dutch publishing group. Rudolph Agnew, 55 years old and former chairman of Consolidated Gold Fields PLC, was named a director of this British industrial conglomerate." > input.txt
$ wget http://opennlp.sourceforge.net/models-1.5/en-sent.bin
$ chalk cli SentenceDetector en-sent.bin < input.txt
Loading Sentence Detector model ... done (0.099s)
Pierre Vinken, 61 years old, will join the board as a nonexecutive director Nov. 29.
Mr. Vinken is chairman of Elsevier N.V., the Dutch publishing group.
Rudolph Agnew, 55 years old and former chairman of Consolidated Gold Fields PLC, was named a director of this British industrial conglomerate.
Average: 1500.0 sent/s
Total: 3 sent
Runtime: 0.0020s
Here's an example of doing sentence detection via the API by using the Scala console in SBT.
$ cd /tmp
$ wget http://opennlp.sourceforge.net/models-1.5/en-sent.bin
$ cd $CHALK_DIR
$ ./build
> console
scala> import java.io.FileInputStream
import java.io.FileInputStream
scala> import chalk.tools.sentdetect._
import chalk.tools.sentdetect._
scala> val sdetector = new SentenceDetectorME(new SentenceModel(new FileInputStream("/tmp/en-sent.bin")))
sdetector: chalk.tools.sentdetect.SentenceDetectorME = chalk.tools.sentdetect.SentenceDetectorME@74dd590f
scala> val sentences = sdetector.sentDetect("Here is a sentence. Here is another with Mr. Brown in it. Hurrah.")
sentences: Array[java.lang.String] = Array(Here is a sentence., Here is another with Mr. Brown in it., Hurrah.)
scala> sentences.foreach(println)
Here is a sentence.
Here is another with Mr. Brown in it.
Hurrah.
Note also that in general, you should be able to follow the OpenNLP documentation, but you'll need to substitute 'chalk cli' for 'opennlp' in that manual.