You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by je...@apache.org on 2022/11/15 13:07:57 UTC

[incubator-hugegraph] branch master updated: Adding try-with-resources block around PredictionTraverser (#2016)

This is an automated email from the ASF dual-hosted git repository.

jermy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


The following commit(s) were added to refs/heads/master by this push:
     new b79a690cd Adding try-with-resources block around PredictionTraverser (#2016)
b79a690cd is described below

commit b79a690cd4832696a92ebfd4251ebc9910ef7bf9
Author: vamossagar12 <sa...@gmail.com>
AuthorDate: Tue Nov 15 18:37:51 2022 +0530

    Adding try-with-resources block around PredictionTraverser (#2016)
    
    Co-authored-by: Sagar Rao <sa...@Sagars-MacBook-Pro.local>
---
 .../com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java     |  9 +++++----
 .../baidu/hugegraph/api/traversers/ResourceAllocationAPI.java | 11 ++++++-----
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java
index 2f3dc115e..efd74cab2 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPI.java
@@ -80,9 +80,10 @@ public class AdamicAdarAPI extends API {
         Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
 
         HugeGraph g = graph(manager, graph);
-        PredictionTraverser traverser = new PredictionTraverser(g);
-        double score = traverser.adamicAdar(sourceId, targetId, dir,
-                                            edgeLabel, maxDegree, limit);
-        return JsonUtil.toJson(ImmutableMap.of("adamic_adar", score));
+        try (PredictionTraverser traverser = new PredictionTraverser(g)) {
+            double score = traverser.adamicAdar(sourceId, targetId, dir,
+                                                edgeLabel, maxDegree, limit);
+            return JsonUtil.toJson(ImmutableMap.of("adamic_adar", score));
+        }
     }
 }
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPI.java
index ed729ad1c..1705c2c84 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPI.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPI.java
@@ -80,10 +80,11 @@ public class ResourceAllocationAPI extends API {
         Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
 
         HugeGraph g = graph(manager, graph);
-        PredictionTraverser traverser = new PredictionTraverser(g);
-        double score = traverser.resourceAllocation(sourceId, targetId, dir,
-                                                    edgeLabel, maxDegree,
-                                                    limit);
-        return JsonUtil.toJson(ImmutableMap.of("resource_allocation", score));
+        try (PredictionTraverser traverser = new PredictionTraverser(g)) {
+            double score = traverser.resourceAllocation(sourceId, targetId, dir,
+                                                        edgeLabel, maxDegree,
+                                                        limit);
+            return JsonUtil.toJson(ImmutableMap.of("resource_allocation", score));
+        }
     }
 }