public static String labeledGraphToString(Graph<Node, LabeledLink> 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 (LabeledLink edge : graph.edgeSet()) { sb.append("("); sb.append(edge.getId()); sb.append(" - status=" + edge.getStatus().name()); sb.append(" - w=" + edge.getWeight()); sb.append(" - type=" + edge.getType().name()); sb.append("\n"); } //sb.append("------------------------------------------"); return sb.toString(); }
public void changeLinkStatus(LabeledLink link, LinkStatus newStatus) { if (link == null) return; LabeledLink graphLink = this.getIdToLinkMap().get(link.getId()); // use the graph link, not the tree link sent by the alignment (steiner tree has a copy of the graph link) if (graphLink == null) return; LinkStatus oldStatus = graphLink.getStatus(); if (newStatus == oldStatus) return; graphLink.setStatus(newStatus); link.setStatus(newStatus); this.changeLinkWeight(graphLink, computeWeight(graphLink)); Set<LabeledLink> linksWithOldStatus = this.statusToLinksMap.get(oldStatus); if (linksWithOldStatus != null) linksWithOldStatus.remove(graphLink); if (newStatus == LinkStatus.Normal) // we don't need to index normal links return; Set<LabeledLink> linksWithNewStatus = this.statusToLinksMap.get(newStatus); if (linksWithNewStatus == null) { linksWithNewStatus = new HashSet<>(); statusToLinksMap.put(newStatus, linksWithNewStatus); } linksWithNewStatus.add(graphLink); }
private void updateLinksPreferredByUI() { if (this.steinerTree == null) return; // Change the status of previously preferred links to normal Set<LabeledLink> linksInPreviousTree = this.getLinksByStatus(LinkStatus.PreferredByUI); Set<LabeledLink> linksForcedByUser = this.getLinksByStatus(LinkStatus.ForcedByUser); if (linksInPreviousTree != null) { LabeledLink[] links = linksInPreviousTree.toArray(new LabeledLink[0]); for (LabeledLink link : links) this.graphBuilder.changeLinkStatus(link, LinkStatus.Normal); } for (LabeledLink link: this.steinerTree.edgeSet()) { if (linksForcedByUser == null || !linksForcedByUser.contains(link)) { this.graphBuilder.changeLinkStatus(link, LinkStatus.PreferredByUI); logger.debug("link " + link.getId() + " has been added to preferred UI links."); } } }
private LabeledLink getSpecializationLinkIfExists(LabeledLink link, Node sourceNode) { Set<LabeledLink> outgoingEdges = this.alignmentGraph.outgoingEdgesOf(sourceNode); for (LabeledLink olink:outgoingEdges) { // Check for the object property specialization if (olink instanceof ObjectPropertySpecializationLink ) { String splLinkId = ((ObjectPropertySpecializationLink) olink).getSpecializedLinkId(); if (splLinkId.equals(link.getId())) return olink; } // Check for the data property specialization else if (olink instanceof DataPropertyOfColumnLink) { DataPropertyOfColumnLink dlink = (DataPropertyOfColumnLink) olink; Node target = link.getTarget(); if (target instanceof ColumnNode) { ColumnNode cnode = (ColumnNode) target; if (dlink.getSpecializedColumnHNodeId().equals(cnode.getId())) return dlink; } } } return null; }
if (this.getLinksByStatus(LinkStatus.ForcedByUser) != null) { for (LabeledLink link: this.getLinksByStatus(LinkStatus.ForcedByUser)) logger.debug("\t" + link.getId());
edgeObj.put(JsonKeys.id.name(), link.getId());
if (currentIncomingLinks != null) for (LabeledLink l : currentIncomingLinks) currentLinkIds.add(l.getId()); if (currentOutgoingLinks != null) for (LabeledLink l : currentOutgoingLinks) currentLinkIds.add(l.getId()); for (LabeledLink e : this.steinerTree.edgeSet()) { LabeledLink l = this.getLinkById(e.getId()); continue; if (currentLinkIds.contains(l.getId())) continue; AlignmentScore a = new AlignmentScore(l, currentScore); alignmentScores.add(a);
public boolean removeNode(String nodeId) { Node node = this.getNodeById(nodeId); if (node != null) { node.setForced(false); this.graphBuilder.getForcedNodes().remove(node); if (this.steinerTree != null && this.steinerTree.containsVertex(node)) { Set<LabeledLink> links = this.steinerTree.edgesOf(node); if (links != null) { for (LabeledLink l : links) { this.changeLinkStatus(l.getId(), LinkStatus.Normal); } } this.steinerTree.removeVertex(node); return true; } } logger.debug("Cannot find the link " + nodeId + " in the graph."); return false; }
public boolean contains(DirectedWeightedMultigraph<Node, LabeledLink> graph) { if (graph == null || this.graphBuilder == null || this.graphBuilder.getGraph() == null) return false; Set<String> commonModelIds = null; LabeledLink matchedLink = null; boolean firstVisit = true; for (LabeledLink l : graph.edgeSet()) { matchedLink = this.graphBuilder.getIdToLinkMap().get(l.getId()); if (matchedLink == null) return false; if (firstVisit) { commonModelIds = matchedLink.getModelIds(); firstVisit = false; } else { if (commonModelIds == null || matchedLink.getModelIds() == null) return false; commonModelIds = Sets.intersection(matchedLink.getModelIds(), commonModelIds); if (commonModelIds.isEmpty()) // no intersection return false; } } return true; } }
public void changeLinkStatus(LabeledLink link, LinkStatus status) { super.changeLinkStatus(link, status); if (status == LinkStatus.PreferredByUI) return; 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()); if (getTopKGraph().get(n2).remove(e)) { if (link instanceof LabeledLink) { e.setModelIds(((LabeledLink)link).getModelIds()); e.setForced(status == LinkStatus.ForcedByUser); } getTopKGraph().get(n2).add(e); } }
Node target = l.getTarget(); if (!this.graphBuilder.addLink(source, target, l)) { LabeledLink existingLink = this.graphBuilder.getIdToLinkMap().get(l.getId()); if (existingLink != null) { // the link already exist, but it may not be forced by user this.graphBuilder.changeLinkStatus(existingLink, LinkStatus.ForcedByUser);
if (inputModelEdges.indexOf(e.getId()) != -1) continue;
inputModelEdges.add(e.getId());
for (LabeledLink currentLink: currentLinks) { alignment.changeLinkStatus(currentLink.getId(), LinkStatus.Normal);
Set<LabeledLink> alignmentEdges = alignment.getCurrentIncomingLinksToNode(hNodeId); for(LabeledLink edge: alignmentEdges) { String linkId = edge.getId(); SemanticType type = semanticIdMap.get(linkId); types.removeType(type);
Predicate pred = new Predicate(olink.getId()+"+inverse"); pred.getTemplate().addTemplateTermToSet( new StringTemplateTerm(inversePropLabel.getUri(), true)); Predicate pred = new Predicate(olink.getId()+"+inverseOf"); pred.getTemplate().addTemplateTermToSet( new StringTemplateTerm(inverseOfPropLabel.getUri(), true));