P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package foundation.ai;
 
import java.io.File;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import foundation.util.MapList;
 
public class AICenter {
 
    private static Logger logger;
    private static AICenter instance;
    private static MapList<String, AIProvider> providers;
    private static ActionBucket actionBucket;
    
    static {
        logger = LogManager.getLogger(AICenter.class);
        providers = new MapList<String, AIProvider>();
        actionBucket = new ActionBucket();
        instance = createInstance();
    }
    
    private AICenter() {
        
    }
    
    public static AICenter createInstance() {
        return new AICenter();
    }
    
    public synchronized static AICenter getInstance() {
        if (instance == null) {
            instance = createInstance();
        }
        
        return instance;
    }
    
    public static OCRResult execOCR(Operator operator, File file) throws Exception {
        if (Operator.NotKnown == operator) {
            return null;
        }
        
        Action action = actionBucket.get(operator);
        
        if (action == null) {
            logger.error("can find action: {}", operator.toChinese());
            return null;
        }
        
        return action.exec(file);
    }
    
    public static OCRResult execOCR(Operator operator, Object paramObject) throws Exception {
        if (Operator.NotKnown == operator) {
            return null;
        }
        
        Action action = actionBucket.get(operator);
        
        if (action == null) {
            logger.error("can find action: {}", operator.toChinese());
            return null;
        }
        
        return action.exec(paramObject);
    }    
    
    public static void execOCR(String code, File file) throws Exception {
        Operator operator = Operator.parse(code);
        execOCR(operator, file);
    }
    
    public void activate() {
        AICenter.instance = this;
    }
 
    public static void registerOneAction(Operator operator, AIProvider provider) {
        Action action = new Action(operator, provider);
        actionBucket.loadOneAction(operator, action);
    }
 
    public void addOneProvider(AIProvider provider) {
        providers.add(provider.getName(), provider);
    }
    
}