public void clusterDocument(Document doc) throws Exception{
		Transaction tx = graphDb.beginTx();
		try {

		ArrayList<Sentence> sentencesList = doc.getSentences();
		// these tables will be used to calculate the similarity between the new document and existing cluster
		Hashtable<String, Double> clusterSimilairtyTableForWords = new Hashtable<String, Double>();
		Hashtable<String, Double> clusterSimilairtyTableForEdges = new Hashtable<String, Double>();
		double documentMagnitude = 0.0;
		double edgesMagnitude = 0.0;
		int numberOfEgdesOfDocument = 0;
		//
		//Loop for each sentence of the document
		for (int sentenceIndex = 0; sentenceIndex < sentencesList.size(); sentenceIndex++) {
			Sentence currentSentence = sentencesList.get(sentenceIndex);
			ArrayList<Word> currentSentenceWords = currentSentence.getWords();
			//Loop for the words of the current sentence
			Word previousWord = null;
			Word currentWord = null;
			Node previousNodeInTheGraph = null;
			Node currentNodeInGraph = null;
			for (int wordIndex = 0; wordIndex < currentSentenceWords.size(); wordIndex++) {
			  currentWord = currentSentenceWords.get(wordIndex);
			  currentNodeInGraph = nodeIndex.get(Neo4jNode.WORD_PROPERTY, currentWord.getContent()).getSingle();				
				double wordValueForTheDocument = calculateWordValue(doc, currentWord);
				documentMagnitude +=  Math.pow(wordValueForTheDocument, 2);
				// start handling the word
				if(currentNodeInGraph != null){ // currentWord exists in the graph
					updateWordsClusterImportanceTable(clusterSimilairtyTableForWords, currentNodeInGraph, wordValueForTheDocument);
				}else{ // currentWord is a new word 
					currentNodeInGraph = createNewWord(currentWord);
				}
				// done handling the nodes
				// start handling the edges
				if((previousNodeInTheGraph != null) && (currentNodeInGraph != null)){
					numberOfEgdesOfDocument++;
					edgesMagnitude++;
					String edgeID = previousWord.getContent()+"_"+currentWord.getContent();
					Relationship edge = edgesIndex.get("edge", edgeID).getSingle();
					if(edge !=  null){ //edge exists
						updateEdgesClusterImportanceTable(clusterSimilairtyTableForEdges, edge, 1);
					}else{ // create new edge
						createNewEdge(previousNodeInTheGraph, currentNodeInGraph, edgeID);
					}
				}
				// done handling the edges
				previousNodeInTheGraph = currentNodeInGraph;
				previousWord = currentWord;
			}// end loop for words of the current sentence
		}// end loop of sentence of the document
		
		// Evaluate the document to the matched clusters
		String closestCluster = getClosestCluster(doc, documentMagnitude, numberOfEgdesOfDocument ,clusterSimilairtyTableForWords, clusterSimilairtyTableForEdges);
		if(closestCluster.equalsIgnoreCase("")){ //create new cluster
			closestCluster = String.valueOf(clusterCounter);
			Neo4jCluster c = new Neo4jCluster(closestCluster);
			c.incrementMagnitude(documentMagnitude);
			c.incrementEdgesMagnitude(edgesMagnitude);
			this.clustersList.put(c.getId(), c);
			c.addDcoument(doc.getId());
			this.clusterCounter++;
			updateTheGraph(doc, closestCluster);
		}else{
			Neo4jCluster c = this.clustersList.get(closestCluster);
			c.incrementMagnitude(documentMagnitude);
			c.incrementEdgesMagnitude(edgesMagnitude);
			c.addDcoument(doc.getId());
			updateTheGraph(doc, closestCluster);
		}
		tx.success();
		} finally {
			tx.finish();
		}
	}