if(ontMgr.isEmpty())
return new UpdateContainer(new ErrorUpdate("No ontology loaded."));
String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
if (alignment == null) {
alignment = new Alignment(ontMgr);
AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
}
String ns = Namespaces.KARMA;
// Create the internal node for worksheet
Label internalNodeLabel = new Label(ns + worksheet.getTitle().trim().replaceAll(" ", "_"), ns, "karma");
Node classNode = alignment.addInternalNode(internalNodeLabel);
// Create column nodes for all columns
List<HNode> sortedLeafHNodes = new ArrayList<HNode>();
worksheet.getHeaders().getSortedLeafHNodes(sortedLeafHNodes);
for (HNode hNode : sortedLeafHNodes){
String columnName = hNode.getColumnName().trim().replaceAll(" ", "_");
ColumnNode columnNode = alignment.getColumnNodeByHNodeId(hNode.getId());
List<LabeledLink> columnNodeIncomingLinks = alignment.getIncomingLinks(columnNode.getId());
if (columnNodeIncomingLinks == null || columnNodeIncomingLinks.isEmpty()) { // SemanticType not yet assigned
Label propertyLabel = new Label(ns + columnName, ns, "karma");
alignment.addDataPropertyLink(classNode, columnNode, propertyLabel);
// Create a semantic type object
SemanticType type = new SemanticType(hNode.getId(), propertyLabel, internalNodeLabel, SemanticType.Origin.User, 1.0);
worksheet.getSemanticTypes().addType(type);
columnNode.setUserSelectedSemanticType(type);
} else {
// User-defined: do nothing
}
}
if(!this.isExecutedInBatch())
alignment.align();
try {
// Save the semantic types in the input parameter JSON
saveSemanticTypesInformation(worksheet, workspace, worksheet.getSemanticTypes().getListOfTypes());