I was looking through this page on how to summarize a text using cosine similarity: https://www.kaggle.com/neomatrix369/summariser-cosine-class. I stopped at the following three lines:
sentence_similarity_graph= networkx.from_numpy_array(sentence_similarity_martix)
scores = networkx.pagerank(sentence_similarity_graph)
rankedSentences = sorted(((scores[index],sentence) for index, sentence in enumerate(sentences)), reverse=True)
I have recently started learning and coding in Java, so my question is: Is there a way of translating these three lines into Java (assuming that we have the double sentence_similarity_matrix[n][n])? I did quite an extensive search for Java libraries and I found JUNG2 but I am not quite sure on how to use it in a Java Project. Any help?
JUNG has a PageRank algorithm implementation, as well as a number of related algorithms: https://jrtom.github.io/jung/javadoc/edu/uci/ics/jung/algorithms/scoring/package-summary.html
You should be pretty trivially able to build a JUNG Graph by iterating over the elements of your matrix/array and adding an edge for each (non-zero) entry; see the JUNG sample code for examples: https://jrtom.github.io/jung/javadoc/edu/uci/ics/jung/samples/package-summary.html