private String getNewObjectMapId(int objectMapCounter) {
return "ObjectMap" + objectMapCounter;
}
private SubjectMap addSubjectMapForTripleMap(Resource trMapRes, KR2RMLMapping kr2rmlMapping, List<Resource> subjectMapResources) throws JSONException {
SubjectMap subjMap = null;
Property subjMapProp = model.getProperty(Uris.RR_SUBJECTMAP_URI);
Property templateProp = model.getProperty(Uris.RR_TEMPLATE_URI);
Property rdfTypeProp = model.getProperty(Uris.RDF_TYPE_URI);
Property rrClassProp = model.getProperty(Uris.RR_CLASS_URI);
Resource steinerTreeRootNodeRes = model.getResource(Uris.KM_STEINER_TREE_ROOT_NODE);
NodeIterator subjMapsItr = model.listObjectsOfProperty(trMapRes, subjMapProp);
while (subjMapsItr.hasNext()){
Resource subjMapBlankRes = subjMapsItr.next().asResource();
subjectMapResources.add(subjMapBlankRes);
String subjMapId = subjMapBlankRes.getId().getLabelString();
subjMap = new SubjectMap(subjMapId);
kr2rmlMapping.getSubjectMapIndex().put(subjMapId, subjMap);
// Get the subject template
NodeIterator templateItr = model.listObjectsOfProperty(subjMapBlankRes, templateProp);
TemplateTermSet subjTemplTermSet = null;
while (templateItr.hasNext()) {
RDFNode templNode = templateItr.next();
String template = templNode.toString();
subjTemplTermSet = TemplateTermSetBuilder.constructTemplateTermSetFromR2rmlTemplateString(
template, kr2rmlMapping.getColumnNameFormatter());
List<String> columnsCovered = new LinkedList<String>();
for(TemplateTerm term : subjTemplTermSet.getAllColumnNameTermElements())
{
columnsCovered.add(term.getTemplateTermValue());
}
kr2rmlMapping.getAuxInfo().getSubjectMapIdToTemplateAnchor().put(subjMap.getId(), KR2RMLMappingAuxillaryInformation.findSubjectMapTemplateAnchor(columnsCovered));
}
subjMap.setTemplate(subjTemplTermSet);
// Get the subject type
NodeIterator rdfTypesItr = model.listObjectsOfProperty(subjMapBlankRes, rrClassProp);
while (rdfTypesItr.hasNext()) {
RDFNode typeNode = rdfTypesItr.next();
if (typeNode.isAnon()) {
NodeIterator typeTemplItr = model.listObjectsOfProperty(typeNode.asResource(),
templateProp);
while (typeTemplItr.hasNext()) {
RDFNode templNode = typeTemplItr.next();
String template = templNode.toString();
TemplateTermSet typeTermSet = TemplateTermSetBuilder.
constructTemplateTermSetFromR2rmlTemplateString(
template);
subjMap.addRdfsType(typeTermSet);
}
continue;
}
if (typeNode instanceof Resource) {
// Skip the steiner tree root type
if(((Resource) typeNode).getURI().equals(Uris.KM_STEINER_TREE_ROOT_NODE))
continue;
StringTemplateTerm uriTerm = new StringTemplateTerm(
((Resource) typeNode).getURI(), true);
TemplateTermSet typeTermSet = new TemplateTermSet();
typeTermSet.addTemplateTermToSet(uriTerm);
subjMap.addRdfsType(typeTermSet);
} else {
TemplateTermSet typeTermSet = TemplateTermSetBuilder.
constructTemplateTermSetFromR2rmlTemplateString(
typeNode.toString());
subjMap.addRdfsType(typeTermSet);
}
}
// Check if it is as the Steiner tree root node
if (model.contains(subjMapBlankRes, rdfTypeProp, steinerTreeRootNodeRes)) {
subjMap.setAsSteinerTreeRootNode(true);
}
}
return subjMap;
}