public boolean removeLink(DefaultLink link) { if (super.removeLink(link)) { SteinerNode n1 = new SteinerNode(link.getSource().getId()); SteinerNode n2 = new SteinerNode(link.getTarget().getId()); SteinerEdge e = new SteinerEdge(n1, link.getId(), n2, (float)link.getWeight()); // getTopKGraph().get(n1).remove(e); getTopKGraph().get(n2).remove(e); return true; } else return false; }
public DefaultLink() { super(); this.init(); }
public String toString() { String key = ""; if (this.edgeList.isEmpty()) return key; if (this.startNode != null) key += this.startNode.getLocalId(); for (DefaultLink l : this.edgeList) { key += "<"; key += l.getUri(); key += ">"; if (l.getTarget() != null) key += l.getTarget().getLocalId(); } return key; } }
if (incomingLinks != null) { for (DefaultLink l : incomingLinks) { source = l.getSource(); if (source instanceof ColumnNode) continue; target = newNode; newId = LinkIdFactory.getLinkId(l.getUri(), source.getId(), target.getId()); DefaultLink copyLink = l.getCopy(newId); this.addLink(source, target, copyLink, l.getWeight()); for (DefaultLink l : outgoingLinks) { source = newNode; target = l.getTarget(); if (!copyLinksToColumnNodes && target instanceof ColumnNode) continue; // skip links to column nodes newId = LinkIdFactory.getLinkId(l.getUri(), source.getId(), target.getId()); DefaultLink copyLink = l.getCopy(newId); this.addLink(source, target, copyLink, l.getWeight());
public static void printLabeledGraph(Graph<Node, LabeledLink> graph) { if (graph == null) { logger.debug("graph is null."); return; } StringBuffer sb = new StringBuffer(); sb.append("*** Nodes ***\n"); for (Node n : graph.vertexSet()) { sb.append(n.getLocalId()); sb.append("\n"); } sb.append("*** Links ***\n"); for (DefaultLink link : graph.edgeSet()) { sb.append(link.getId()); sb.append(", "); sb.append(link.getType().toString()); sb.append(", "); sb.append(link.getWeight()); sb.append("\n"); } // sb.append("------------------------------------------"); logger.debug(sb.toString()); }
public void changeLinkWeight(DefaultLink link, double weight) { super.changeLinkWeight(link, weight); SteinerNode n1 = new SteinerNode(link.getSource().getId()); SteinerNode n2 = new SteinerNode(link.getTarget().getId()); SteinerEdge e = new SteinerEdge(n1, link.getId(), n2, (float)weight); if (getTopKGraph().get(n2).remove(e)) { if (link instanceof LabeledLink) { e.setModelIds(((LabeledLink)link).getModelIds()); e.setForced(((LabeledLink)link).getStatus() == LinkStatus.ForcedByUser); } getTopKGraph().get(n2).add(e); } }
sourceId = link.getSource().getId(); targetId = link.getTarget().getId(); tree.addEdge(link.getSource(), link.getTarget(), newLink); tree.setEdgeWeight(newLink, link.getWeight()); if (allowedChangingGraph) this.graphBuilder.addLink(link.getSource(), link.getTarget(), newLink); logger.error("Something is going wrong. " + "There should be at least one possible object property between " + link.getSource().getLabel().getUri() + " and " + link.getTarget().getLabel().getUri()); return;
public static String defaultGraphToString(Graph<Node, DefaultLink> graph) { if (graph == null) { logger.debug("The input graph is null."); return ""; } StringBuffer sb = new StringBuffer(); sb.append("*** Nodes ***\n"); for (Node n : graph.vertexSet()) { sb.append(n.getLocalId()); sb.append("\n"); } sb.append("*** Links ***\n"); for (DefaultLink edge : graph.edgeSet()) { sb.append("("); sb.append(edge.getId()); sb.append(" - w=" + edge.getWeight()); sb.append("\n"); } //sb.append("------------------------------------------"); return sb.toString(); }
public static HashMap<SemanticType, LabeledLink> getDomainLinks(DirectedGraph<Node, DefaultLink> g, ColumnNode n, List<SemanticType> semanticTypes) { HashMap<SemanticType, LabeledLink> domainLinks = new HashMap<>(); if (g == null || n == null || semanticTypes == null || !g.vertexSet().contains(n)) return domainLinks; Set<DefaultLink> incomingLinks = g.incomingEdgesOf(n); if (incomingLinks != null) { for (SemanticType st : semanticTypes) { for (DefaultLink l : incomingLinks) { if (st.getDomain().getUri().equalsIgnoreCase(l.getSource().getUri()) && st.getType().getUri().equalsIgnoreCase(l.getUri())) { if (l instanceof LabeledLink) domainLinks.put(st, (LabeledLink)l); } } } } return domainLinks; }
if (this.idToLinkMap.containsKey(link.getId())) { logger.debug("The link with id=" + link.getId() + " already exists in the graph"); return false; String uri = link.getUri(); Label label = this.ontologyManager.getUriLabel(uri); if (label == null) { String key = source.getId() + link.getUri(); Integer count = this.nodeDataPropertyCount.get(key); if (count == null) this.nodeDataPropertyCount.put(key, 1); key = source.getUri() + link.getUri(); Set<SemanticTypeMapping> SemanticTypeMappings = this.semanticTypeMatches.get(key); if (SemanticTypeMappings == null) {
@Override public int compareTo(DefaultLink link) { //compare id return this.id.compareTo(link.getId()); }
public static Set<Node> getInNeighbors(DirectedGraph<Node, DefaultLink> g, Node n) { Set<Node> neighbors = new HashSet<>(); if (g == null || n == null || !g.vertexSet().contains(n)) return neighbors; Set<DefaultLink> incomingLinks = g.incomingEdgesOf(n); if (incomingLinks != null) { for (DefaultLink l : incomingLinks) { neighbors.add(l.getSource()); } } return neighbors; }
public static Set<Node> getOutNeighbors(DirectedGraph<Node, DefaultLink> g, Node n) { Set<Node> neighbors = new HashSet<>(); if (g == null || n == null || !g.vertexSet().contains(n)) return neighbors; Set<DefaultLink> outgoingLinks = g.outgoingEdgesOf(n); if (outgoingLinks != null) { for (DefaultLink l : outgoingLinks) { neighbors.add(l.getTarget()); } } return neighbors; }
public DefaultLink getCopy(String newId) { if (this instanceof LabeledLink) return ((LabeledLink)this).copy(newId); else if (this instanceof CompactLink) return ((CompactLink)this).copy(newId); else { logger.error("cannot instanciate a link from the type: " + this.getType().toString()); return null; } } }
continue; DefaultLink e = new DefaultLink(); g.addEdge(n1, n2, e); g.setEdgeWeight(e, path.getCost(n2));
for (DefaultLink dl : outLinks) { if (dl instanceof LabeledLink && dl.getUri().equalsIgnoreCase(linkUri)) { sortedMatchedNodes.remove(0); okLink = false; for (DefaultLink dl : inLinks) { if (dl instanceof LabeledLink && dl.getUri().equalsIgnoreCase(linkUri)) { sortedMatchedNodes.remove(0); okLink = false;
public static void printGraph(Graph<Node, DefaultLink> graph) { if (graph == null) { logger.debug("graph is null."); return; } StringBuffer sb = new StringBuffer(); sb.append("*** Nodes ***\n"); for (Node n : graph.vertexSet()) { sb.append(n.getLocalId()); sb.append("\n"); } sb.append("*** Links ***\n"); for (DefaultLink link : graph.edgeSet()) { sb.append(link.getId()); sb.append(", "); sb.append(link.getType().toString()); sb.append(", "); sb.append(link.getWeight()); sb.append("\n"); } // sb.append("------------------------------------------"); logger.debug(sb.toString()); }