@Override protected void originateCommunity(Node node) { super.originateCommunity(node); // Correct the original community score for the Leung algorithm node.setAttribute(marker + ".score", 1.0); }
private void defaultVisit(CFrame frame) { MultiGraph graph = this.view.getGraph(); graph.getNodeSet().clear(); graph.getEdgeSet().clear(); // this.baseIRIList = new HashSet<String>(); // Получение всех элементов и формирование из них визуального части. for (OWLNamedIndividual owlName : frame.getContent().getConcepts()) { String label = this.model.getLabel(owlName); if (label.equals("_EMPTY_")) { label = owlName.getIRI().getFragment().toString(); } Node node = graph.addNode(owlName.getIRI().toString()); node.addAttribute("OWLNamedIndividual", owlName); node.addAttribute("ui.label", label); if (owlName.getIRI().equals(frame.getTrgConcept().getIRI())) { node.setAttribute("ui.class", "concept"); } } // Связывает все элементы линиями. for (Branch br : frame.getContent().getBranches()) { Node nodeSub = null; Node nodeObj = null; for (Node node : graph.getNodeSet()) { if (node.getId().equals(br.getSubject().getIRI().toString())) { nodeSub = node; continue; } else { if (node.getId().equals(br.getObject().getIRI().toString())) { nodeObj = node; continue; } } if (nodeSub != null && nodeObj != null) { break; } } // Создает элемент линия для двух node. Edge edge = graph.addEdge(br.getBrachIndIRI().toString(), nodeSub, nodeObj, true); String labelEdge = this.model.getAnnotationValue(br.getPrp().getIRI()); if (labelEdge.equals("_EMPTY_")) { labelEdge = br.getPrp().getIRI().getFragment().toString(); } edge.addAttribute("ui.label", labelEdge); } }
@Override public void computeNode(Node node) { /* * Recall and update the node current community and previous score */ Object previousCommunity = node.getAttribute(marker); Double previousScore = (Double) node.getAttribute(marker + ".score"); super.computeNode(node); /* * Update the node label score */ // Handle first iteration if (previousCommunity == null) { previousCommunity = node.getAttribute(marker); previousScore = (Double) node.getAttribute(marker + ".score"); } /* * The node is the originator of the community and hasn't changed * community at this iteration (or we are at the first simulation step): * keep the maximum label score */ if ((node.getAttribute(marker).equals(previousCommunity)) && (previousScore.equals(1.0))) node.setAttribute(marker + ".score", 1.0); /* * Otherwise search for the highest score amongst neighbors and reduce * it by decreasing factor */ else { Double maxLabelScore = Double.NEGATIVE_INFINITY; for (Edge e : node.getEnteringEdgeSet()) { Node v = e.getOpposite(node); if (v.hasAttribute(marker) && v.getAttribute(marker).equals(node.getAttribute(marker))) { if ((Double) v.getAttribute(marker + ".score") > maxLabelScore) maxLabelScore = (Double) v.getAttribute(marker + ".score"); } } node.setAttribute(marker + ".score", maxLabelScore - delta); } }
/* * (non-Javadoc) * * @see org.graphstream.algorithm.Algorithm#compute() */ public void compute() { float min = Float.MAX_VALUE; HashSet<Node> centroid = new HashSet<Node>(); for (Node node : graph.getEachNode()) { float m = 0; APSP.APSPInfo info = node.getAttribute(apspInfoAttribute); if (info == null) System.err.printf("APSPInfo missing. Did you compute APSP before ?\n"); for (Node other : graph.getEachNode()) { if (node != other) { double d = info.getLengthTo(other.getId()); if (d < 0) System.err.printf( "Found a negative length value in centroid algorithm. " + "Is graph connected ?\n"); else m += d; } } if (m < min) { centroid.clear(); centroid.add(node); min = m; } else if (m == min) { centroid.add(node); } } for (Node node : graph.getEachNode()) node.setAttribute( centroidAttribute, centroid.contains(node) ? isInCentroid : isNotInCentroid); centroid.clear(); }