<commit_before>package eu.socialsensor.clustering;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import eu.socialsensor.graphdatabases.GraphDatabase;
import eu.socialsensor.graphdatabases.Neo4jGraphDatabase;
import eu.socialsensor.main.GraphDatabaseBenchmark;
import eu.socialsensor.utils.Metrics;
import eu.socialsensor.utils.Utils;

/**
 * Implementation of Louvain Method on top of graph databases. Gephi Toolkit (https://gephi.org/toolkit/) 
 * java implementation was used as guide. 
 * 
 * @author sotbeis
 * @email <EMAIL>
 */
public class LouvainMethod {
	
    boolean isRandomized;
    private double resolution = 1.0;
    private double graphWeightSum;
    private int N;
    private List<Double> communityWeights;
    public int counter = 0;
    private boolean communityUpdate = false;
    
    GraphDatabase graphDatabase;
    Cache cache;
    
    public static int CACHE_SIZE = 1000;
        
	public static void main(String args[]) throws ExecutionException {
		
//		GraphDatabase neo4jGraphDatabase = new Neo4jGraphDatabase();
		
//		neo4jGraphDatabase.delete(GraphDatabaseBenchmark.NEO4JDB_PATH);
		
//		neo4jGraphDatabase.createGraphForMassiveLoad(GraphDatabaseBenchmark.NEO4JDB_PATH);
//		neo4jGraphDatabase.massiveModeLoading("./data/network.dat");
//		neo4jGraphDatabase.shutdownMassiveGraph();

		
		GraphDatabase neo4jGraphDatabase = new Neo4jGraphDatabase();
		neo4jGraphDatabase.open(GraphDatabaseBenchmark.NEO4JDB_PATH);
		neo4jGraphDatabase.setClusteringWorkload(true);
		
		for(int i = 0; i < 5; i++) {
			long start = System.currentTimeMillis();
			System.out.println("Graph Database: Neo4j, Dataset: graph5000, Cache Size: 250");				
			LouvainMethod louvainMethodCache = new LouvainMethod(neo4jGraphDatabase, 250, false);
			louvainMethodCache.computeModularity();
			double neo4jTime = (System.currentTimeMillis() - start) / 1000.0;
			System.out.println(neo4jTime);
			
			//evaluation with NMI
			Map<Integer, List<Integer>> predictedCommunities = neo4jGraphDatabase.mapCommunities(louvainMethodCache.getN());
			Utils utils = new Utils();
			Map<Integer, List<Integer>> actualCommunities = utils.mapNodesToCommunities("./data/community.dat");
			Metrics metrics = new Metrics();
			double NMI = metrics.normalizedMutualInformation(5000, actualCommunities, predictedCommunities);
			System.out.println("NMI value: " + NMI);
			System.out.println();
		}

		neo4jGraphDatabase.shutdown();
		
	}
	
	public LouvainMethod(GraphDatabase graphDatabase, int cacheSize, boolean isRandomized) throws ExecutionException {
		this.graphDatabase = graphDatabase;
		this.isRandomized = isRandomized;
		CACHE_SIZE = cacheSize;
		initilize();
		cache = new Cache(graphDatabase, cacheSize);
	}
	
	private void initilize() {
		this.N = this.graphDatabase.getNodeCount();
		this.graphWeightSum = this.graphDatabase.getGraphWeightSum() / 2;
		
		this.communityWeights = new ArrayList<Double>(this.N);
		for(int i = 0; i < this.N; i++) {
			this.communityWeights.add(0.0);
		}
		
		this.graphDatabase.initCommunityProperty();		
	}
	<commit_msg>minor changes for testing <commit_after>package eu.socialsensor.clustering;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import eu.socialsensor.graphdatabases.GraphDatabase;

/**
 * Implementation of Louvain Method on top of graph databases. Gephi Toolkit (https://gephi.org/toolkit/) 
 * java implementation was used as guide. 
 * 
 * @author sotbeis
 * @email <EMAIL>
 */
public class LouvainMethod {
	
    boolean isRandomized;
    private double resolution = 1.0;
    private double graphWeightSum;
    private int N;
    private List<Double> communityWeights;
    public int counter = 0;
    private boolean communityUpdate = false;
    
    GraphDatabase graphDatabase;
    Cache cache;
    
    public static int CACHE_SIZE = 1000;
        
	public static void main(String args[]) throws ExecutionException {
		
	}
	
	public LouvainMethod(GraphDatabase graphDatabase, int cacheSize, boolean isRandomized) throws ExecutionException {
		this.graphDatabase = graphDatabase;
		this.isRandomized = isRandomized;
		CACHE_SIZE = cacheSize;
		initilize();
		cache = new Cache(graphDatabase, cacheSize);
	}
	
	private void initilize() {
		this.N = this.graphDatabase.getNodeCount();
		this.graphWeightSum = this.graphDatabase.getGraphWeightSum() / 2;
		
		this.communityWeights = new ArrayList<Double>(this.N);
		for(int i = 0; i < this.N; i++) {
			this.communityWeights.add(0.0);
		}
		
		this.graphDatabase.initCommunityProperty();		
	}
	
{'fraction_non_alphanumeric': 0.1007834003811137, 'fraction_numerical': 0.013338979462206225, 'mean_word_length': 4.38654503990878, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6265046', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1423, 'n_words': 321}