From d356125db4c999d9e1b820dd600828fb29006b77 Mon Sep 17 00:00:00 2001 From: Jason Baldridge Date: Mon, 22 Jul 2013 12:08:27 -0500 Subject: [PATCH] #18 progress: added StringAnalysisFunction and StringAnalysisComponent to simplify the type signature for common cases. --- src/main/scala/chalk/slab/AnalysisEngine.scala | 7 +++++-- src/main/scala/chalk/slab/AnalysisFunction.scala | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/scala/chalk/slab/AnalysisEngine.scala b/src/main/scala/chalk/slab/AnalysisEngine.scala index 0591806..c3e3749 100644 --- a/src/main/scala/chalk/slab/AnalysisEngine.scala +++ b/src/main/scala/chalk/slab/AnalysisEngine.scala @@ -25,16 +25,19 @@ object AnalysisComponent { case class Process[C,B,I<:B](slab: Slab[C,B,I]) } +trait StringAnalysisComponent[I<:StringAnnotation,O<:StringAnnotation] + extends AnalysisComponent[String,StringAnnotation,I,O] + /** * An actor that uses SentenceSegmenter. */ class SentenceSegmenterActor extends SentenceSegmenter[StringAnnotation] - with AnalysisComponent[String,StringAnnotation,StringAnnotation,Sentence] + with StringAnalysisComponent[StringAnnotation,Sentence] /** * An actor that uses Tokenizer. */ -class TokenizerActor extends AnalysisComponent[String, StringAnnotation, Sentence, Token] with Tokenizer[Sentence] +class TokenizerActor extends Tokenizer[Sentence] with StringAnalysisComponent[Sentence, Token] /** diff --git a/src/main/scala/chalk/slab/AnalysisFunction.scala b/src/main/scala/chalk/slab/AnalysisFunction.scala index fa7b325..b1d4fd4 100644 --- a/src/main/scala/chalk/slab/AnalysisFunction.scala +++ b/src/main/scala/chalk/slab/AnalysisFunction.scala @@ -12,14 +12,16 @@ package chalk.slab */ trait AnalysisFunction[C,B,I<:B,O<:B] extends (Slab[C,B,I] => Slab[C,B,B with I with O]) -object StringIdentityAnalyzer extends AnalysisFunction[String, StringAnnotation, StringAnnotation, StringAnnotation] { +trait StringAnalysisFunction[I<:StringAnnotation,O<:StringAnnotation] extends (Slab[String,StringAnnotation,I] => Slab[String,StringAnnotation,StringAnnotation with I with O]) + +object StringIdentityAnalyzer extends StringAnalysisFunction[StringAnnotation, StringAnnotation] { def apply(slab: Slab[String, StringAnnotation, StringAnnotation]) = slab } /** * A simple regex sentence segmenter. */ -trait SentenceSegmenter[I <: StringAnnotation] extends AnalysisFunction[String, StringAnnotation, I, Sentence] { +trait SentenceSegmenter[I <: StringAnnotation] extends StringAnalysisFunction[I, Sentence] { def apply(slab: Slab[String, StringAnnotation, I]) = // the [Sentence] is required because of https://issues.scala-lang.org/browse/SI-7647 slab.++[Sentence]("[^\\s.!?]+[^.!?]+[.!?]".r.findAllMatchIn(slab.content).map(m => Sentence(m.start, m.end))) @@ -28,7 +30,7 @@ trait SentenceSegmenter[I <: StringAnnotation] extends AnalysisFunction[String, /** * A simple regex tokenizer. */ -trait Tokenizer[I <: Sentence] extends AnalysisFunction[String, StringAnnotation, I, Token] { +trait Tokenizer[I <: Sentence] extends StringAnalysisFunction[I, Token] { def apply(slab: Slab[String, StringAnnotation, I]) = // the [Token] is required because of https://issues.scala-lang.org/browse/SI-7647 slab.++[Token](slab.iterator[Sentence].flatMap(sentence =>