Java Code Examples for org.apdplat.word.segmentation.SegmentationAlgorithm#valueOf()

The following examples show how to use org.apdplat.word.segmentation.SegmentationAlgorithm#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WordTokenizer.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
public WordTokenizer(String segmentationAlgorithm) {
    try {
        SegmentationAlgorithm sa = SegmentationAlgorithm.valueOf(segmentationAlgorithm);
        this.segmentation = SegmentationFactory.getSegmentation(sa);
    } catch (Exception e) {
        this.segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.BidirectionalMinimumMatching);
    }
}
 
Example 2
Source File: WordTokenizerFactory.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
public WordTokenizerFactory(Map<String, String> configuration) {
    super(configuration);
    if (configuration != null) {
        String conf = configuration.get("conf");
        if (conf != null) {
            // 强制覆盖默认配置
            WordConfTools.forceOverride(conf);
        } else {
            LOGGER.info("没有指定conf参数");
        }
        String algorithm = configuration.get("segAlgorithm");
        if (algorithm != null) {
            try {
                SegmentationAlgorithm segmentationAlgorithm = SegmentationAlgorithm.valueOf(algorithm);
                segmentation = SegmentationFactory.getSegmentation(segmentationAlgorithm);
                LOGGER.info("使用指定分词算法:" + algorithm);
            } catch (Exception e) {
                LOGGER.error("参数segAlgorithm指定的值错误:" + algorithm);
                LOGGER.error("参数segAlgorithm可指定的值有:");
                for (SegmentationAlgorithm sa : SegmentationAlgorithm.values()) {
                    LOGGER.error("\t" + sa.name());
                }
            }
        } else {
            LOGGER.info("没有指定segAlgorithm参数");
        }
    }
    if (segmentation == null) {
        segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.BidirectionalMaximumMatching);
        LOGGER.info("使用默认分词算法:" + SegmentationAlgorithm.BidirectionalMaximumMatching);
    }
}
 
Example 3
Source File: WordAnalyzer.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
public WordAnalyzer(String segmentationAlgorithm) {
    try {
        SegmentationAlgorithm sa = SegmentationAlgorithm.valueOf(segmentationAlgorithm);
        this.segmentation = SegmentationFactory.getSegmentation(sa);
    } catch (Exception e) {
        this.segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.BidirectionalMinimumMatching);
    }
}
 
Example 4
Source File: WordAnalyzer.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public WordAnalyzer(String mode) {
    try {
        this.algorithm = SegmentationAlgorithm.valueOf(mode);
    } catch (Exception e) {
        throw new ConfigException(
                  "Unsupported segment mode '%s' for word analyzer, " +
                  "the available values are %s", e, mode, SUPPORT_MODES);
    }
}
 
Example 5
Source File: ChineseWordAnalyzer.java    From word with Apache License 2.0 5 votes vote down vote up
public ChineseWordAnalyzer(String segmentationAlgorithm) {
    try{
        SegmentationAlgorithm sa = SegmentationAlgorithm.valueOf(segmentationAlgorithm);
        this.segmentation = SegmentationFactory.getSegmentation(sa);
    }catch(Exception e){
        this.segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.BidirectionalMinimumMatching);
    }
}
 
Example 6
Source File: ChineseWordTokenizer.java    From word with Apache License 2.0 5 votes vote down vote up
public ChineseWordTokenizer(String segmentationAlgorithm) {
    try{
        SegmentationAlgorithm sa = SegmentationAlgorithm.valueOf(segmentationAlgorithm);
        this.segmentation = SegmentationFactory.getSegmentation(sa);
    }catch(Exception e){
        this.segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.BidirectionalMinimumMatching);
    }
}
 
Example 7
Source File: ChineseWordTokenizerFactory.java    From word with Apache License 2.0 5 votes vote down vote up
public ChineseWordTokenizerFactory(Map<String, String> args){
    super(args);
    if(args != null){
        String conf = args.get("conf");
        if(conf != null){
            //强制覆盖默认配置
            WordConfTools.forceOverride(conf);
        }else{
            LOGGER.info("没有指定conf参数");
        }
        String algorithm = args.get("segAlgorithm");
        if(algorithm != null){
            try{
                SegmentationAlgorithm segmentationAlgorithm = SegmentationAlgorithm.valueOf(algorithm);
                segmentation = SegmentationFactory.getSegmentation(segmentationAlgorithm);
                LOGGER.info("使用指定分词算法:"+algorithm);
            }catch(Exception e){
                LOGGER.error("参数segAlgorithm指定的值错误:"+algorithm);
                LOGGER.error("参数segAlgorithm可指定的值有:");
                for(SegmentationAlgorithm sa : SegmentationAlgorithm.values()){
                    LOGGER.error("\t"+sa.name());
                }
            }
        }else{
            LOGGER.info("没有指定segAlgorithm参数");
        }
    }
    if(segmentation == null){
        segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.BidirectionalMaximumMatching);
        LOGGER.info("使用默认分词算法:"+SegmentationAlgorithm.BidirectionalMaximumMatching);
    }
}