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
package com.walker.openocr;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.List;
 
public abstract class AbstractTextResolver<T,C> implements TextResolver<T,C>{
 
    protected final transient Logger logger = LoggerFactory.getLogger(this.getClass());
 
    private OcrType ocrType = null;
 
    @Override
    public T resolve(List<TextBlock> dataList, List<C> configList) {
        if(dataList == null || dataList.size() == 0){
            return null;
        }
        if(this.ocrType == OcrType.TextGeneric){
            return this.doResolveGeneric(dataList, configList);
        } else if(this.ocrType == OcrType.TextTable){
            return this.doResolveTable(dataList, configList);
        } else if(this.ocrType == OcrType.TextIdCard){
            return this.doResolveIdCard(dataList, configList);
        } else {
            throw new UnsupportedOperationException("暂未实现解析类型:" + this.ocrType.getIndex());
        }
    }
 
    @Override
    public void setOcrType(OcrType ocrType) {
        if(ocrType == null){
            logger.error("ocrType is null!");
            return;
        }
        this.ocrType = ocrType;
    }
 
    @Override
    public OcrType getOcrType() {
        return this.ocrType;
    }
 
    protected abstract T doResolveGeneric(List<TextBlock> dataList, List<C> configList);
 
    protected abstract T doResolveTable(List<TextBlock> dataList, List<C> configList);
 
    protected abstract T doResolveIdCard(List<TextBlock> dataList, List<C> configList);
}