Skip to content

Commit 2469cc9

Browse files
author
tabish
committed
Updated nodeDistanceFilter. Just query database once to get filtered sites and loop through nodes to remove nodes with non matching sites.
1 parent 57f3d4a commit 2469cc9

2 files changed

Lines changed: 15 additions & 26 deletions

File tree

src/main/java/edu/uiowa/slis/graphtaglib/Graph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void removeNode(GraphNode node) {
8080
}
8181

8282
// removing the node and its edges from the vectors and the hash
83-
log.debug("edge hash size: " + edgeHash.size() + " vector size: " + edges.size());
83+
log.trace("edge hash size: " + edgeHash.size() + " vector size: " + edges.size());
8484
nodes.remove(node);
8585
nodeHash.remove(node.getUri());
8686

@@ -147,7 +147,7 @@ void pruneOrphans() {
147147
void resetNodeIDs() {
148148
maxScore = 0;
149149
for (int i = 0; i < nodes.size(); i++) {
150-
log.debug(nodes.elementAt(i).getUri() + " " + i);
150+
log.trace(nodes.elementAt(i).getUri() + " " + i);
151151
nodes.elementAt(i).setID(i);
152152
maxScore = Math.max(nodes.elementAt(i).getScore(), maxScore);
153153
}

src/main/java/edu/uiowa/slis/graphtaglib/filters/NodeDistance.java

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,16 @@ public void filterNodes(Graph theGraph, String selectedNode, int radius) {
4949
edges = theGraph.edges;
5050
String uri = null;
5151
Hashtable<String, String> visitedHash = new Hashtable<String, String>();
52+
Hashtable<Integer, String> sites_hash =new Hashtable<Integer, String>();
5253
String sites = "";
53-
54+
5455
try {
5556
theDataSource = (DataSource) new InitialContext().lookup(dataSource);
5657
logger.debug("nodeDistanceFilter with node = " + selectedNode + " radius = " + String.valueOf(radius));
5758

5859
conn = theDataSource.getConnection();
5960
// Get co-authors for node and add edge to graph only if that
6061
// neighbor is within our radius
61-
62-
// we have uri -> coauthors.uri -> site
63-
// PreparedStatement theStmt =
64-
// conn.prepareStatement("select candidate.*,person.uri from vivo_aggregated.person, vivo_aggregated.site_loc as candidate, vivo_aggregated.site_loc as center where center.id=person.id and center.id=? and circle(center.position,(?/111.0)) @> candidate.position");
6562
PreparedStatement theStmt = conn
6663
.prepareStatement("select candidate.* from vivo_aggregated.site_loc as candidate, vivo_aggregated.site_loc as center where center.id=? and circle(center.position,(?/111.0)) @> candidate.position");
6764

@@ -71,37 +68,29 @@ public void filterNodes(Graph theGraph, String selectedNode, int radius) {
7168
ResultSet rs = theStmt.executeQuery();
7269
while (rs.next()) {
7370
logger.trace(rs.getString(1) + ' ' + rs.getString(2) + ' ' + rs.getString(3));
74-
sites += rs.getString(1) + ",";
71+
sites += rs.getString(1) + " ";
72+
sites_hash.put(rs.getInt(1), rs.getString(2));
7573
}
7674

77-
logger.debug("Sites within our search radius are " + sites);
75+
logger.debug("Sites within our search radius are " + sites + "size of hashtable " + sites_hash.size());
7876
rs.close();
7977
theStmt.close();
8078
logger.debug("Before Filter: Number of nodes=" + nodes.size() + " Number of edges=" + edges.size());
79+
8180
// keep nodes belonging to site above and remove others
82-
theStmt = conn.prepareStatement("select person.uri from vivo_aggregated.person where person.id not in (" + sites.substring(0, sites.length() - 1) + ")");
83-
logger.debug("Query:: " + theStmt.toString());
84-
rs = theStmt.executeQuery();
85-
while (rs.next()) {
86-
uri = rs.getString(1);
87-
GraphNode node = theGraph.getNode(uri);
88-
if (node != null) {
89-
theGraph.removeNode(node);
90-
try {
91-
if (theGraph.getNode(uri) != null) {
92-
logger.debug("Something is wrong");
93-
}
94-
} catch (Exception e) {
95-
e.printStackTrace();
96-
}
81+
for (int x = nodes.size() - 1; x >= 0; x--) {
82+
GraphNode n = nodes.elementAt(x);
83+
if (!sites_hash.containsKey(n.getGroup("site"))){
84+
logger.trace("Current node :" + n.getLabel() + " does not match the filter criteria with site:"+ n.getGroup("site"));
85+
theGraph.removeNode(n);
86+
}
9787
}
98-
}
9988
logger.debug("After Filter: Number of nodes=" + nodes.size() + " Number of edges=" + edges.size());
10089

10190
rs.close();
10291
theStmt.close();
103-
10492
conn.close();
93+
10594
} catch (Exception e) {
10695
e.printStackTrace();
10796
logger.debug(selectedNode + ' ' + radius);

0 commit comments

Comments
 (0)