Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.

Commit

Permalink
#18 progress: added StringAnalysisFunction and StringAnalysisComponen…
Browse files Browse the repository at this point in the history
…t to simplify the type signature for common cases.
  • Loading branch information
jasonbaldridge committed Jul 22, 2013
1 parent e10526d commit d356125
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/main/scala/chalk/slab/AnalysisEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]


/**
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/chalk/slab/AnalysisFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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 =>
Expand Down

0 comments on commit d356125

Please sign in to comment.