public Command createCommand(JSONArray inputJson, Workspace workspace)
throws JSONException, KarmaException {
String worksheetId = HistoryJsonUtil.getStringValue(
Arguments.worksheetId.name(), inputJson);
Worksheet worksheet = workspace.getWorksheet(worksheetId);
AutoOntology autoOntology = new AutoOntology(worksheet);
String path = ServletContextParameterMap
.getParameterValue(ContextParameter.PRELOADED_ONTOLOGY_DIRECTORY)
+ worksheet.getTitle() + ".owl";
try {
autoOntology.Build(path);
} catch (IOException e) {
logger.error("Error occured while creating auto model!", e);
}
OntologyManager ontMgr = workspace.getOntologyManager();
File autoOtologyFile = new File(path);
logger.info("Loading ontology: " + autoOtologyFile.getAbsolutePath());
String encoding = EncodingDetector.detect(autoOtologyFile);
try {
ontMgr.doImportAndUpdateCache(autoOtologyFile, encoding);
logger.info("Done loading ontology: "
+ autoOtologyFile.getAbsolutePath());
} catch(Exception e) {
logger.error("Error importing auto ontology file: " + autoOtologyFile.getAbsolutePath());
}
SuggestAutoModelCommand comm = new SuggestAutoModelCommand(
getNewId(workspace), worksheet.getId());
// Add the semantic types that have saved into the history
for (int i = 2; i < inputJson.length(); i++) {
JSONObject hnodeObj = (JSONObject) inputJson.get(i);
String hNodeId = (String) hnodeObj.get(ClientJsonKeys.value
.name());
JSONObject typeObj = (JSONObject) inputJson.get(++i);
JSONObject value = (JSONObject) typeObj
.get(ClientJsonKeys.value.name());
SemanticType type = null;
String domain = (String) value
.get(SemanticType.ClientJsonKeys.DomainUri.name());
String fullType = (String) value
.get(SemanticType.ClientJsonKeys.FullType.name());
Label typeName = ontMgr.getUriLabel(fullType);
Label domainName = null;
if (domain != null && !domain.trim().equals(""))
domainName = ontMgr.getUriLabel(domain);
if (typeName != null) {
type = new SemanticType(hNodeId, typeName, domainName,
Origin.User, 1.00);
worksheet.getSemanticTypes().addType(type);
}
}
return comm;
}