// if this is a tripleMap, then add all its RefObjects to the queue
// for the predicates, add only the ones that satisfy the criteria of being <...hasValue>
if (currentObj instanceof TriplesMap) {
String var = "x"+var_count;
TriplesMap triple = (TriplesMap)currentObj;
boolean foundHasValue = false;
List<PredicateObjectMap> predicates = triple.getPredicateObjectMaps();
for (PredicateObjectMap p_map : predicates) {
if(p_map.getObject().hasRefObjectMap()) {
RefObjectMap objMap = p_map.getObject().getRefObjectMap();
queue.add(objMap.getParentTriplesMap());
logger.info(triple.getSubject().getId() + " ---> " + objMap.getParentTriplesMap().getSubject().getId());
// maintain a list of mapping properties between triples
ParentMapingInfoList.put(objMap.getParentTriplesMap().getSubject().getId(),
new ParentMapingInfo(triple, p_map.getPredicate()));
} else {
queue.add(p_map.getPredicate());
predicateList.put(p_map.getPredicate(), var);
foundHasValue = true;
}
}
// if this triple is marked to be included in the query,
// we add it to the markedTriples list and add to the query string
// for its class type Eg.
// Prefix pref1: <.../.../Input>
// x2 a pref1:
if (foundHasValue) {
markedTriples.put(triple, var);
String rdfsTypes = triple.getSubject().getRdfsType().get(0).toString();
this.prefix_list.put("pref"+var_count, rdfsTypes);
query.append(" ?"+var + " a pref"+var_count+": .");
// if the parent of this triple is also marked for the query
// then we add the relation to between triples to the query. Eg.
// TriplesMap parentTriple = parent.get(triple.getSubject().getId());
ParentMapingInfo parentTriple = ParentMapingInfoList.get(triple.getSubject().getId());
// from the current node, keep poping out till we reach the last node in the
// parent map to see if any of the parents are connected
if(parentTriple != null) {
String sq = checkParentMarked(triple, markedTriples, var);
if (sq.length() > 1) {
query.append(sq);
}
}
// if( parentTriple != null && markedTriples.containsKey(parentTriple.parent)) {
// String predicate = parentTriple.predicate.getTemplate().toString();
//// PredicateObjectMap parentPredicate = getPredicateBetweenTriples(triple, parentTriple);
// if(predicate != null) {
// query.append(" ?" + markedTriples.get(parentTriple.parent) + " " +
// predicate + " ?"+var + " . ");
// } else {
// System.out.println("predicate is null from parent : " + triple.getSubject().getRdfsType().toString());
// }
// }
}
var_count++;
}
// if it is a predicate Object, create a variable in in the query string
else if (currentObj instanceof Predicate) {
Predicate predicate = (Predicate)currentObj;
String k = predicate.getTemplate().toString();
k = k.replace('<', ' ').replace('>', ' ').trim();
if(columns != null && columns.size() > 0) {
// if(columnList.containsKey(k)) {
if(columnList.containsValue(k)) {
Iterator<String> itr = columnList.keySet().iterator();
while(itr.hasNext()) {
String cName = itr.next();
if(columnList.get(cName).equals(k) && !visited_columns.contains(cName)) {
// get the column name from the end of this url - either the last '/' or the '#'
query.append(" ?" + predicateList.get(predicate))
.append(" ")
.append(predicate.getTemplate())
.append(" ?")
.append(cName + " . ");
//columnList.remove(cName);
visited_columns.add(cName);
var_count++;
break;
}
}
// get the column name from the end of this url - either the last '/' or the '#'
// query.append(" ?" + predicateList.get(predicate))
// .append(" ")
// .append(predicate.getTemplate())
// .append(" ?")
// .append(columnList.get(k) + " . ");
// var_count++;
} else {
logger.info("ColumnList does not contain : " + k + " " + currentObj);
}
} else {
int index = 0;
if(k.indexOf("#") > 0) {
index = k.lastIndexOf('#')+1;
} else if(k.indexOf("/") > 0) {
index = k.lastIndexOf('/')+1;
}
query.append(" ?" + predicateList.get(predicate))
.append(" ")
.append(predicate.getTemplate())
.append(" ?").append(k.substring(index, k.length()))
.append(" .");
var_count++;
}
}
// if this is a RefObject add the Child Triple to the queue
else if (currentObj instanceof RefObjectMap) {
RefObjectMap refObj = (RefObjectMap)currentObj;
TriplesMap t = refObj.getParentTriplesMap();
queue.add(t);
}
}