UpdateContainer c = new UpdateContainer();
Worksheet worksheet = workspace.getWorksheet(worksheetId);
SuperSelection selection = getSuperSelection(worksheet);
OntologyManager ontologyManager = workspace.getOntologyManager();
if(ontologyManager.isEmpty())
return new UpdateContainer(new ErrorUpdate("No ontology loaded."));
worksheetName = worksheet.getTitle();
String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
Alignment alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), worksheetId, ontologyManager);
if (alignment == null) {
logger.info("Alignment is NULL for " + worksheetId);
return new UpdateContainer(new ErrorUpdate(
"Alignment is NULL for " + worksheetId));
}
if (initialAlignment == null)
{
initialAlignment = alignment.getAlignmentClone();
initialGraph = (DirectedWeightedMultigraph<Node, DefaultLink>)alignment.getGraph().clone();
List<HNode> orderedNodeIds = new ArrayList<HNode>();
worksheet.getHeaders().getSortedLeafHNodes(orderedNodeIds);
if (orderedNodeIds != null) {
for (int i = 0; i < orderedNodeIds.size(); i++)
{
String hNodeId = orderedNodeIds.get(i).getId();
ColumnNode cn = alignment.getColumnNodeByHNodeId(hNodeId);
if (!cn.hasUserType())
{
worksheet.getSemanticTypes().unassignColumnSemanticType(hNodeId);
List<SemanticType> suggestedSemanticTypes =
new SemanticTypeUtil().getColumnSemanticSuggestions(workspace, worksheet, cn, 4, selection);
cn.setSuggestedSemanticTypes(suggestedSemanticTypes);
}
}
}
} else {
// Replace the current alignment with the old alignment
alignment = initialAlignment;
alignment.setGraph(initialGraph);
if(!this.isExecutedInBatch())
alignment.align();
AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
}
steinerNodes = alignment.computeSteinerNodes();
ModelLearner modelLearner = null;
if (ModelingConfiguration.isLearnAlignmentEnabled())
modelLearner = new ModelLearner(alignment.getGraphBuilder(), steinerNodes);
else
modelLearner = new ModelLearner(ontologyManager, alignment.getLinksByStatus(LinkStatus.ForcedByUser), steinerNodes);
// logger.info(GraphUtil.defaultGraphToString(ModelLearningGraph.getInstance(ontologyManager, ModelLearningGraphType.Compact).getGraphBuilder().getGraph()));
SemanticModel model = modelLearner.getModel();
if (model == null) {
logger.error("could not learn any model for this source!");
return new UpdateContainer(new ErrorUpdate(
"Error occured while generating a semantic model for the source."));
}
// logger.info(GraphUtil.labeledGraphToString(model.getGraph()));
List<SemanticType> semanticTypes = new LinkedList<SemanticType>();
alignment.updateAlignment(model, semanticTypes);
// Set<ColumnNode> alignmentColumnNodes = alignment.getSourceColumnNodes();
// if (alignmentColumnNodes != null) {
// for (ColumnNode cn : alignmentColumnNodes) {
// worksheet.getSemanticTypes().unassignColumnSemanticType(cn.getHNodeId());
// }
// }
// if (semanticTypes != null) {
// for (SemanticType st : semanticTypes)
// worksheet.getSemanticTypes().addType(st);
// }
try {
// Save the semantic types in the input parameter JSON
saveSemanticTypesInformation(worksheet, workspace, worksheet.getSemanticTypes().getListOfTypes());
// Add the visualization update
c.add(new SemanticTypesUpdate(worksheet, worksheetId, alignment));
c.add(new AlignmentSVGVisualizationUpdate(
worksheetId, alignment));
} catch (Exception e) {
logger.error("Error occured while generating the model Reason:.", e);
return new UpdateContainer(new ErrorUpdate(
"Error occured while generating the model for the source."));
}
c.add(new TagsUpdate());
return c;