/** Check if a semantic type already exists for the column **/
ColumnNode columnNode = alignment.getColumnNodeByHNodeId(hNodeId);
columnNode.setRdfLiteralType(rdfLiteralType);
boolean semanticTypeAlreadyExists = false;
LabeledLink oldIncomingLinkToColumnNode = null;
Node oldDomainNode = null;
List<LabeledLink> columnNodeIncomingLinks = alignment
.getIncomingLinks(columnNode.getId());
if (columnNodeIncomingLinks != null
&& !columnNodeIncomingLinks.isEmpty()) { // SemanticType already
// assigned
semanticTypeAlreadyExists = true;
oldIncomingLinkToColumnNode = columnNodeIncomingLinks.get(0);
oldDomainNode = oldIncomingLinkToColumnNode.getSource();
}
if(metaPropertyId.endsWith(" (add)"))
metaPropertyId = metaPropertyId.substring(0, metaPropertyId.length()-5).trim();
if (metaPropertyName.equals(METAPROPERTY_NAME.isUriOfClass)) {
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 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);