if (classNodeLabel == null) {
String errorMessage = "Error while setting a classLink. MetaPropertyUri '"
+ metaPropertyUri
+ "' should be in the Ontology Manager, but it is not.";
logger.error(errorMessage);
return new UpdateContainer(new ErrorUpdate(errorMessage));
}
classNode = alignment.addInternalNode(classNodeLabel);
}
LabeledLink newLink = alignment.addClassInstanceLink(classNode, columnNode,
LinkKeyInfo.UriOfInstance);
alignment.changeLinkStatus(newLink.getId(),
LinkStatus.ForcedByUser);
// Create the semantic type object
newType = new SemanticType(hNodeId,
ClassInstanceLink.getFixedLabel(), classNode.getLabel(),
SemanticType.Origin.User, 1.0);
} else if (metaPropertyName
.equals(METAPROPERTY_NAME.isSpecializationForEdge)) {
LabeledLink propertyLink = alignment.getLinkById(metaPropertyId);
if (propertyLink == null) {
String errorMessage = "Error while specializing a link. The DefaultLink '"
+ metaPropertyId
+ "' should already be in the alignment, but it is not.";
logger.error(errorMessage);
return new UpdateContainer(new ErrorUpdate(errorMessage));
}
Node classInstanceNode = alignment.getNodeById(LinkIdFactory
.getLinkSourceId(metaPropertyId));
if (semanticTypeAlreadyExists) {
clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
oldDomainNode, alignment, classInstanceNode);
}
if (propertyLink instanceof DataPropertyLink) {
String targetHNodeId = ((ColumnNode) propertyLink.getTarget())
.getHNodeId();
LabeledLink newLink = alignment.addDataPropertyOfColumnLink(classInstanceNode,
columnNode, targetHNodeId, propertyLink.getId());
alignment.changeLinkStatus(newLink.getId(),
LinkStatus.ForcedByUser);
// Create the semantic type object
newType = new SemanticType(hNodeId,
DataPropertyOfColumnLink.getFixedLabel(),
classInstanceNode.getLabel(), SemanticType.Origin.User,
1.0);
} else if (propertyLink instanceof ObjectPropertyLink) {
LabeledLink newLink = alignment.addObjectPropertySpecializationLink(
classInstanceNode, columnNode, propertyLink.getId());
alignment.changeLinkStatus(newLink.getId(),
LinkStatus.ForcedByUser);
// Create the semantic type object
newType = new SemanticType(hNodeId,
ObjectPropertySpecializationLink.getFixedLabel(),
classInstanceNode.getLabel(), SemanticType.Origin.User,
1.0);
}
} else if (metaPropertyName.equals(METAPROPERTY_NAME.isSubclassOfClass)) {
Node classNode = alignment.getNodeById(metaPropertyId);
if (semanticTypeAlreadyExists) {
clearOldSemanticTypeLink(oldIncomingLinkToColumnNode,
oldDomainNode, alignment, classNode);
}
if (classNode == null) {
Label classNodeLabel = ontMgr.getUriLabel(metaPropertyUri);
if (classNodeLabel == null) {
String errorMessage = "Error while setting an advances subclass. MetaPropertyValue '"
+ metaPropertyUri
+ "' should be in the Ontology Manager, but it is not.";
logger.error(errorMessage);
return new UpdateContainer(new ErrorUpdate(errorMessage));
}
classNode = alignment.addInternalNode(classNodeLabel);
}
LabeledLink newLink = alignment.addColumnSubClassOfLink(classNode, columnNode);
alignment.changeLinkStatus(newLink.getId(),
LinkStatus.ForcedByUser);
// Create the semantic type object
newType = new SemanticType(hNodeId,
ColumnSubClassLink.getFixedLabel(), classNode.getLabel(),
SemanticType.Origin.User, 1.0);
}
columnNode.setUserSelectedSemanticType(newType);
// Update the alignment
if(!this.isExecutedInBatch())
alignment.align();
UpdateContainer c = new UpdateContainer();
// Save the old SemanticType object and CRF Model for undo
oldType = worksheet.getSemanticTypes().getSemanticTypeForHNodeId(
hNodeId);
oldSynonymTypes = worksheet.getSemanticTypes()
.getSynonymTypesForHNodeId(newType.getHNodeId());
// Update the SemanticTypes data structure for the worksheet
worksheet.getSemanticTypes().addType(newType);
// Update the synonym semanticTypes
// worksheet.getSemanticTypes().addSynonymTypesForHNodeId(newType.getHNodeId(),
// newSynonymTypes);
if (trainAndShowUpdates) {
new SemanticTypeUtil().trainOnColumn(workspace, worksheet, newType, selection);
}
c.add(new SemanticTypesUpdate(worksheet, worksheetId, alignment));
c.add(new AlignmentSVGVisualizationUpdate(worksheetId,
alignment));
return c;
}