Resource pomBlankNode = predObjItr.next().asResource();
// Create the PredicateObjectMap object for current POM
PredicateObjectMap pom = new PredicateObjectMap(pomBlankNode.getURI(), trMap);
// Get the predicate for the POM
Predicate pred = null;
NodeIterator pomPredItr = model.listObjectsOfProperty(pomBlankNode, predProp);
while (pomPredItr.hasNext()) {
RDFNode pomPredNode = pomPredItr.next();
pred = new Predicate(pomPredNode.toString() + "-" + predicateIdCounter++);
// Check if the predicate value is a URI or a literal (such as column name)
if (pomPredNode instanceof Resource) {
pred.getTemplate().addTemplateTermToSet(
new StringTemplateTerm(((Resource) pomPredNode).getURI(), true));
} else {
pred.setTemplate(TemplateTermSetBuilder.
constructTemplateTermSetFromR2rmlTemplateString(
pomPredNode.toString(), formatter));
}
}
pom.setPredicate(pred);
// Get the object for the POM
ObjectMap objMap = null;
NodeIterator pomObjItr = model.listObjectsOfProperty(pomBlankNode, objectMapProp);
while (pomObjItr.hasNext()) {
Resource objNode = pomObjItr.next().asResource();
/** Check if objBlankNode is a RefObjectMap or a normal object map with column **/
if (model.contains(objNode, rdfTypeProp, rfObjClassUri)) {
NodeIterator parentTripleMapItr = model.listObjectsOfProperty(objNode,
parentTriplesMapProp);
while (parentTripleMapItr.hasNext()) {
Resource parentTripleRes = parentTripleMapItr.next().asResource();
TriplesMap parentTM = kr2rmlMapping.getTriplesMapIndex().get(parentTripleRes.getURI());
// Create a RefObjectMap
RefObjectMap rfMap = new RefObjectMap(objNode.getURI(), parentTM);
objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++), rfMap);
// Add the link between triple maps in the auxInfo
TriplesMapLink link = new TriplesMapLink(trMap, parentTM, pom);
kr2rmlMapping.getAuxInfo().getTriplesMapGraph().addLink(link);
}
} else {
NodeIterator objMapColStmts = model.listObjectsOfProperty(objNode, columnProp);
// RDF Literal Type
Statement objMapRdfLiteralTypeStmt = model.getProperty(objNode, rdfLiteralTypeProp);
TemplateTermSet rdfLiteralTypeTermSet = null;
if (objMapRdfLiteralTypeStmt != null && objMapRdfLiteralTypeStmt.getObject().isLiteral()) {
StringTemplateTerm rdfLiteralTypeTerm =
new StringTemplateTerm(objMapRdfLiteralTypeStmt.getObject().toString(), true);
rdfLiteralTypeTermSet = new TemplateTermSet();
rdfLiteralTypeTermSet.addTemplateTermToSet(rdfLiteralTypeTerm);
}
while (objMapColStmts.hasNext()) {
RDFNode colNode = objMapColStmts.next();
objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++),
TemplateTermSetBuilder.constructTemplateTermSetFromR2rmlColumnString(
colNode.toString(), formatter), rdfLiteralTypeTermSet);
}
if(objMap == null)
{
NodeIterator templateItr = model.listObjectsOfProperty(objNode, templateProp);
//try a literal/constant node
if(templateItr == null || !templateItr.hasNext()){
templateItr = model.listObjectsOfProperty(objNode, constantProp);
}
TemplateTermSet objTemplTermSet = null;
while (templateItr.hasNext()) {
RDFNode templNode = templateItr.next();
String template = templNode.toString();
boolean isUri = !templNode.isLiteral();
objTemplTermSet = TemplateTermSetBuilder.constructTemplateTermSetFromR2rmlTemplateString(
template, isUri, kr2rmlMapping.getColumnNameFormatter());
}
objMap = new ObjectMap(getNewObjectMapId(objectMapCounter++),
objTemplTermSet, rdfLiteralTypeTermSet);
}
// Check if anything needs to be added to the columnNameToPredicateObjectMap Map
if(objMap != null)
addColumnNameToPredObjectMapLink(objMap, pom, kr2rmlMapping);
}
}
pom.setObject(objMap);
trMap.addPredicateObjectMap(pom);
}
// Try to add template to pom
TemplateTermSet subjTemplTermSet = trMap.getSubject().getTemplate();
if(subjTemplTermSet != null)
{
List<TemplateTerm> terms = subjTemplTermSet.getAllTerms();
if(isValidTemplate(terms))
{
PredicateObjectMap pom = new PredicateObjectMap(PredicateObjectMap.getNewId(),trMap);
Predicate pred = new Predicate(Uris.CLASS_INSTANCE_LINK_URI + "-" + predicateIdCounter++);
pred.getTemplate().addTemplateTermToSet(
new StringTemplateTerm(Uris.CLASS_INSTANCE_LINK_URI, true));
pom.setPredicate(pred);
StringTemplateTerm rdfLiteralTypeTerm = new StringTemplateTerm("", true);
TemplateTermSet rdfLiteralTypeTermSet = new TemplateTermSet();
rdfLiteralTypeTermSet.addTemplateTermToSet(rdfLiteralTypeTerm);