Class ArabicSegmenter
- java.lang.Object
-
- edu.stanford.nlp.international.arabic.process.ArabicSegmenter
-
- All Implemented Interfaces:
WordSegmenter,ThreadsafeProcessor<String,String>,Serializable
public class ArabicSegmenter extends Object implements WordSegmenter, ThreadsafeProcessor<String,String>
Arabic word segmentation model based on conditional random fields (CRF). This is a re-implementation (with extensions) of the model described in (Green and DeNero, 2012). This package includes a JFlex-based orthographic normalization package that runs on the input prior to processing by the CRF-based segmentation model. The normalization options are configurable, but must be consistent for both training and test data.- Author:
- Spence Green
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ArabicSegmenter(ArabicSegmenter other)Copy constructor.ArabicSegmenter(Properties props)Make an Arabic Segmenter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinishTraining()static ArabicSegmentergetSegmenter(Properties options)Train a new segmenter or load an trained model from file.voidinitializeTraining(double numTrees)voidloadSegmenter(String filename)voidloadSegmenter(String filename, Properties p)static voidmain(String[] args)ThreadsafeProcessor<String,String>newInstance()Return a new threadsafe instance.Stringprocess(String nextInput)Set the input item that will be processed when a thread is allocated to this processor.longsegment(BufferedReader br, PrintWriter pwOut)Segment all strings from an input.List<HasWord>segment(String line)StringsegmentString(String line)List<CoreLabel>segmentStringToTokenList(String line)voidserializeSegmenter(String filename)voidtrain()Train a segmenter from raw text.voidtrain(Tree tree)voidtrain(Collection<Tree> trees)voidtrain(List<TaggedWord> sentence)
-
-
-
Constructor Detail
-
ArabicSegmenter
public ArabicSegmenter(Properties props)
Make an Arabic Segmenter.- Parameters:
props- Options for how to tokenize. See the main method ofArabicTokenizerfor details
-
ArabicSegmenter
public ArabicSegmenter(ArabicSegmenter other)
Copy constructor.- Parameters:
other-
-
-
Method Detail
-
initializeTraining
public void initializeTraining(double numTrees)
- Specified by:
initializeTrainingin interfaceWordSegmenter
-
train
public void train(Collection<Tree> trees)
- Specified by:
trainin interfaceWordSegmenter
-
train
public void train(Tree tree)
- Specified by:
trainin interfaceWordSegmenter
-
train
public void train(List<TaggedWord> sentence)
- Specified by:
trainin interfaceWordSegmenter
-
finishTraining
public void finishTraining()
- Specified by:
finishTrainingin interfaceWordSegmenter
-
process
public String process(String nextInput)
Description copied from interface:ThreadsafeProcessorSet the input item that will be processed when a thread is allocated to this processor.- Specified by:
processin interfaceThreadsafeProcessor<String,String>- Parameters:
nextInput- the object to be processed- Returns:
- the result of the processing
-
newInstance
public ThreadsafeProcessor<String,String> newInstance()
Description copied from interface:ThreadsafeProcessorReturn a new threadsafe instance.- Specified by:
newInstancein interfaceThreadsafeProcessor<String,String>
-
segment
public List<HasWord> segment(String line)
- Specified by:
segmentin interfaceWordSegmenter
-
segment
public long segment(BufferedReader br, PrintWriter pwOut)
Segment all strings from an input.- Parameters:
br- -- input stream to segmentpwOut- -- output stream to write the segmenter text- Returns:
- number of input characters segmented
-
train
public void train()
Train a segmenter from raw text. Gold segmentation markers are required.
-
serializeSegmenter
public void serializeSegmenter(String filename)
-
loadSegmenter
public void loadSegmenter(String filename, Properties p)
-
loadSegmenter
public void loadSegmenter(String filename)
- Specified by:
loadSegmenterin interfaceWordSegmenter
-
main
public static void main(String[] args)
- Parameters:
args-
-
getSegmenter
public static ArabicSegmenter getSegmenter(Properties options)
Train a new segmenter or load an trained model from file. First checks to see if there is a "model" or "loadClassifier" flag to load from, and if not tries to run training using the given options.- Parameters:
options- Properties to specify segmenter behavior- Returns:
- the trained or loaded model
-
-