shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.walker.openocr.vehicle;
 
import com.walker.openocr.AbstractValueParser;
import com.walker.openocr.util.TableConfigUtils;
import com.walker.openocr.util.TextUtils;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 车辆类型属性值解析实现。
 * @author 时克英
 * @date 2022-09-27
 */
public class CarTypeValueParser extends AbstractValueParser<String> {
 
    private List<String> standardTypeSet = new ArrayList<>(12);
 
    public CarTypeValueParser(){
        this.standardTypeSet.add("微型轿车");
        this.standardTypeSet.add("小型轿车");
        this.standardTypeSet.add("中型轿车");
        this.standardTypeSet.add("大型轿车");
        this.standardTypeSet.add("小型普通客车");
        this.standardTypeSet.add("小型越野客车");
        this.standardTypeSet.add("小型专用客车");
        this.standardTypeSet.add("微型普通客车");
        this.standardTypeSet.add("微型越野客车");
    }
 
    @Override
    public String getValue(Object input) {
        if(TextUtils.isEmpty(input)){
            return null;
        }
        String text = input.toString();
        double maxScore = 0;
        double currentScore = 0;
        int maxIndex = 0;
        for(int i=0; i<this.standardTypeSet.size(); i++){
            currentScore = TableConfigUtils.getSimpleSimilarScore(this.standardTypeSet.get(i), text);
            if(currentScore > maxScore){
                maxScore = currentScore;
                maxIndex = i;
            }
        }
        if(maxScore >= 0.7){
            logger.debug("maxScore = " + maxScore + ", index = " + maxIndex);
            return this.standardTypeSet.get(maxIndex);
        }
        return null;
    }
 
    @Override
    public boolean isTypeValue(Object input) {
        return this.getValue(input) != null;
    }
 
}