net.java.sen
Class ReadingProcessor

java.lang.Object
  extended by net.java.sen.ReadingProcessor

public class ReadingProcessor
extends Object

A text processor that builds reading data suitable for application as furigana. ReadingFilters can be used to refine and customise the output

See examples.ReadingProcessorDemo in the Sen source for an example of how to use this class

Thread Safety: Objects of this class are NOT thread safe and should not be accessed simultaneously by multiple threads. Note that creating additional instances using SenFactory is relatively cheap in both memory and time


Nested Class Summary
static class ReadingProcessor.ReadingResult
          The result of reading processing.
 
Constructor Summary
ReadingProcessor(Tokenizer tokenizer)
           
 
Method Summary
 void addFilter(int priority, ReadingFilter filter)
          Adds a reading filter to be applied during processing
 void clearFilters()
          Removes any previously set reading filters
 List<Reading> getDisplayReadings()
          Returns a list of readings generated from the current text.
 Map<Integer,ReadingFilter> getFilters()
          Returns the complete set of reading filters currently applied during processing
 Reading getReadingConstraint(int position)
          Gets a reading constraint set on the currently analysed text
 ReadingProcessor.ReadingResult process()
          Performs full reading processing and returns a ReadingProcessor.ReadingResult object isolated from further changes to the reading processor
 void removeFilter(int priority)
          Removes the filter with the given priority, if it exists
 void removeReadingConstraint(int position)
          Remove the reading constraint at the given position
 void setFilters(Map<Integer,ReadingFilter> filters)
          Sets all reading filters to be applied during processing.
 void setReadingConstraint(Reading constraint)
          Sets a reading constraint on the currently analysed text.
 void setText(String text)
          Sets the currently analysed text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadingProcessor

public ReadingProcessor(Tokenizer tokenizer)
Parameters:
tokenizer - The Tokenizer to use
Method Detail

setText

public void setText(String text)
Sets the currently analysed text. The reset() method will be invoked on any currently set filters in order to clear sentence specific state

Parameters:
text - The text to analyse

addFilter

public void addFilter(int priority,
                      ReadingFilter filter)
Adds a reading filter to be applied during processing

Parameters:
priority - The precedence of the filter. Lower numbered filters are applied first. If a filter is added with the same priority as an existing filter, the existing filter will be overwritten
filter - The filter to add

removeFilter

public void removeFilter(int priority)
Removes the filter with the given priority, if it exists

Parameters:
priority - The priority of the filter to remove

setFilters

public void setFilters(Map<Integer,ReadingFilter> filters)
Sets all reading filters to be applied during processing. Any existing filters are discarded

Parameters:
filters - The filters to use

clearFilters

public void clearFilters()
Removes any previously set reading filters


getFilters

public Map<Integer,ReadingFilter> getFilters()
Returns the complete set of reading filters currently applied during processing

Returns:
The reading filters

getReadingConstraint

public Reading getReadingConstraint(int position)
Gets a reading constraint set on the currently analysed text

Parameters:
position - The index within the sentence to get the constraint at
Returns:
The constraint

setReadingConstraint

public void setReadingConstraint(Reading constraint)
Sets a reading constraint on the currently analysed text.
Note: In contrast to constraints set directly on a Viterbi instance, there is no need to pass the constraint in katakana; the exact reading text supplied will appear in the analysed readings

Parameters:
constraint -

removeReadingConstraint

public void removeReadingConstraint(int position)
Remove the reading constraint at the given position

Parameters:
position - The position from which to remove the constraint

getDisplayReadings

public List<Reading> getDisplayReadings()
Returns a list of readings generated from the current text. If all you need is the readings, this will be marginally quicker than calling process() and then ReadingProcessor.ReadingResult.getDisplayReadings()

Returns:
The readings

process

public ReadingProcessor.ReadingResult process()
Performs full reading processing and returns a ReadingProcessor.ReadingResult object isolated from further changes to the reading processor

Returns:
An object containing the results of processing


Copyright © 2012. All Rights Reserved.