private void updateModel(DirectedWeightedMultigraph<Node, LabeledLink> treeModel) {
if (treeModel == null)
return;
Model m = new Model("model");
HashMap<String, Argument> vertexIdToArgument = new HashMap<String, Argument>();
List<Attribute> attributeList = new ArrayList<Attribute>();
// get the column name associated to the hNodeIds to assign to attribute names
// set the rdf ids of all the vertices.
for (Node n : treeModel.vertexSet()) {
if (n instanceof ColumnNode) {
logger.debug("Vertex " + n.getLocalId() + " is a column node.");
String hNodeId = ((ColumnNode)n).getHNodeId();
String attId = "att" + String.valueOf(attributeList.size() + 1);
Attribute att = new Attribute(attId, this.getUri(), n.getLabel().getLocalName(), IOType.NONE, AttributeRequirement.NONE);
att.sethNodeId(hNodeId);
attributeList.add(att);
vertexIdToArgument.put(n.getId(), new Argument(att.getId(), att.getId(), ArgumentType.ATTRIBUTE));
} else {
logger.debug("Vertex " + n.getLocalId() + " is an intermediate node.");
String variableId = "v" + String.valueOf(variables.size() + 1);
this.variables.add(variableId);
vertexIdToArgument.put(n.getId(), new Argument(variableId, variableId, ArgumentType.VARIABLE));
}
}
for (Node n : treeModel.vertexSet()) {
if (n instanceof ColumnNode || n instanceof LiteralNode)
continue;
if (vertexIdToArgument.get(n.getId()) == null)
continue;
Label classPredicate = new Label(n.getLabel().getUri(), n.getLabel().getNs(), n.getLabel().getPrefix());
ClassAtom classAtom = new ClassAtom(classPredicate, vertexIdToArgument.get(n.getId()));
m.getAtoms().add(classAtom);
}
for (LabeledLink e : treeModel.edgeSet()) {
if (vertexIdToArgument.get(e.getSource().getId()) == null ||
vertexIdToArgument.get(e.getTarget().getId()) == null)
continue;
Label propertyPredicate = new Label(e.getLabel().getUri(), e.getLabel().getNs(), e.getLabel().getPrefix());
IndividualPropertyAtom propertyAtom = null;
// has_subclass is from source to target, we substitute this with a rdfs:subClassOf from target to source
// if (propertyPredicate.getUriString().equalsIgnoreCase(ModelingParams.HAS_SUBCLASS_URI)){
// Label subClassPredicate = new Label(ModelingParams.SUBCLASS_URI, Namespaces.OWL, Prefixes.OWL);
// propertyAtom = new IndividualPropertyAtom(subClassPredicate,
// vertexIdToArgument.get(e.getTarget().getId()),
// vertexIdToArgument.get(e.getSource().getId()));
// } else {
propertyAtom = new IndividualPropertyAtom(propertyPredicate,
vertexIdToArgument.get(e.getSource().getId()),
vertexIdToArgument.get(e.getTarget().getId()));
// }
m.getAtoms().add(propertyAtom);
}
// will update the hashmap.
setAttributes(attributeList);
this.setModel(m);