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);
|
}
|
|
}
|