if (steinerNodes == null || steinerNodes.isEmpty())
return null;
int maxNumberOfSteinerNodes = steinerNodes.size() * 2;
CandidateSteinerSets candidateSteinerSets = new CandidateSteinerSets(maxNumberOfSteinerNodes);
if (addedNodes == null)
addedNodes = new HashSet<Node>();
Set<SemanticTypeMapping> tempSemanticTypeMappings;
HashMap<ColumnNode, List<SemanticType>> columnSemanticTypes = new HashMap<ColumnNode, List<SemanticType>>();
HashMap<String, Integer> semanticTypesCount = new HashMap<String, Integer>();
List<SemanticType> candidateSemanticTypes;
String domainUri = "", propertyUri = "";
for (Node n : steinerNodes) {
ColumnNode cn = null;
if (n instanceof ColumnNode)
cn = (ColumnNode)n;
else
continue;
candidateSemanticTypes = getCandidateSemanticTypes(cn, useCorrectTypes, numberOfCandidates);
columnSemanticTypes.put(cn, candidateSemanticTypes);
for (SemanticType semanticType: candidateSemanticTypes) {
if (semanticType == null ||
semanticType.getDomain() == null ||
semanticType.getType() == null) continue;
domainUri = semanticType.getDomain().getUri();
propertyUri = semanticType.getType().getUri();
Integer count = semanticTypesCount.get(domainUri + propertyUri);
if (count == null) semanticTypesCount.put(domainUri + propertyUri, 1);
else semanticTypesCount.put(domainUri + propertyUri, count.intValue() + 1);
}
}
long numOfMappings = 1;
for (Node n : steinerNodes) {
if (n instanceof InternalNode)
continue;
ColumnNode cn = null;
if (n instanceof ColumnNode)
cn = (ColumnNode)n;
else
continue;
candidateSemanticTypes = columnSemanticTypes.get(n);
if (candidateSemanticTypes == null) continue;
logger.info("===== Column: " + cn.getColumnName());
Set<SemanticTypeMapping> semanticTypeMappings = new HashSet<SemanticTypeMapping>();
for (SemanticType semanticType: candidateSemanticTypes) {
logger.info("\t" + semanticType.getConfidenceScore() + " :" + semanticType.getModelLabelString());
if (semanticType == null ||
semanticType.getDomain() == null ||
semanticType.getType() == null) continue;
domainUri = semanticType.getDomain().getUri();
propertyUri = semanticType.getType().getUri();
Integer countOfSemanticType = semanticTypesCount.get(domainUri + propertyUri);
logger.debug("count of semantic type: " + countOfSemanticType);
if (cn.getDomainNode() != null) {
SemanticTypeMapping mp = new SemanticTypeMapping(cn, semanticType, cn.getDomainNode(), cn.getDomainLink(), cn);
semanticTypeMappings.add(mp);
} else {
tempSemanticTypeMappings = findSemanticTypeInGraph(cn, semanticType, semanticTypesCount, addedNodes);
logger.debug("number of matches for semantic type: " +
+ (tempSemanticTypeMappings == null ? 0 : tempSemanticTypeMappings.size()));
if (tempSemanticTypeMappings != null)
semanticTypeMappings.addAll(tempSemanticTypeMappings);
int countOfMatches = tempSemanticTypeMappings == null ? 0 : tempSemanticTypeMappings.size();
if (countOfMatches < countOfSemanticType)
// if (countOfMatches == 0) // No struct in graph is matched with the semantic type, we add a new struct to the graph
{
SemanticTypeMapping mp = addSemanticTypeStruct(cn, semanticType, addedNodes);
if (mp != null)
semanticTypeMappings.add(mp);
}
}
}
// System.out.println("number of matches for column " + n.getColumnName() +
// ": " + (semanticTypeMappings == null ? 0 : semanticTypeMappings.size()));
logger.debug("number of matches for column " + cn.getColumnName() +
": " + (semanticTypeMappings == null ? 0 : semanticTypeMappings.size()));
numOfMappings *= (semanticTypeMappings == null || semanticTypeMappings.isEmpty() ? 1 : semanticTypeMappings.size());
logger.debug("number of candidate steiner sets before update: " + candidateSteinerSets.getSteinerSets().size());
candidateSteinerSets.updateSteinerSets(semanticTypeMappings);
logger.debug("number of candidate steiner sets after update: " + candidateSteinerSets.getSteinerSets().size());
}
for (Node n : steinerNodes) {
if (n instanceof InternalNode) {
candidateSteinerSets.updateSteinerSets((InternalNode)n);
}
}
// System.out.println("number of possible mappings: " + numOfMappings);
logger.info("number of possible mappings: " + numOfMappings);