public void insertAndIndexDocument(Document doc) throws IOException,
			ClassNotFoundException {
		Node currentNode = null;
		Node previousNode = null;
		int sentenceNumber = 0;
		int wordNumber = 0;
		Transaction tx = graphDb.beginTx();
		try {
			ArrayList<Sentence> sentences = doc.getSentences();
			for (Sentence sentence : sentences) { // iterate over sentences
				wordNumber = 0;
				ArrayList<Word> words = sentence.getWords();
				for (Word word : words) { // iterate over words of sentence
					currentNode = findNodeByProperty(Neo4jNode.WORD_PROPERTY, word.getContent());
					if (currentNode == null) { // word not found in the index (new word)
						Neo4jNode newNode = new Neo4jNode(word.getContent());
						ArrayList<String> documentEntity = new ArrayList<String>();
						documentEntity.add("1");
						documentEntity.add(String.valueOf(sentenceNumber) + "_" + String.valueOf(wordNumber));
						newNode.addToDocumentTable(doc.getId(), documentEntity);
						insertAndIndexNode(newNode);
						currentNode = findNodeByProperty(Neo4jNode.WORD_PROPERTY,word.getContent());
					} else { // word exists
						Neo4jNode existingNode = convertToNeo4jNode(currentNode);
						if (existingNode.isInDocumentTable(doc.getId())) { // if the word was seen before in the current document
							ArrayList<String> documentEntity = existingNode.getDocumentEntity(doc.getId());
							int tf = Integer.parseInt(documentEntity.get(0)) + 1;
							documentEntity.set(0, String.valueOf(tf));
							documentEntity.add(String.valueOf(sentenceNumber) + "_" + String.valueOf(wordNumber));
							existingNode.addToDocumentTable(doc.getId(), documentEntity);
						} else { // if it's the first time to see the current word in the current document
							ArrayList<String> documentEntity = new ArrayList<String>();
							documentEntity.add("1");
							documentEntity.add(String.valueOf(sentenceNumber) + "_"	+ String.valueOf(wordNumber));
							existingNode.addToDocumentTable(doc.getId(), documentEntity);
						}// end if
						modifyAndIndexNode(existingNode, currentNode);
						currentNode = findNodeByProperty(Neo4jNode.WORD_PROPERTY, 	word.getContent());
					} // end if
					if (currentNode != null && previousNode != null && !doesRelationsExist(previousNode, currentNode, "document_" + doc.getId() ) ) {
						createRelationship(previousNode, currentNode, "document_" + doc.getId());
					}
					previousNode = currentNode;
					wordNumber++;
				}// end loop for words
				sentenceNumber++;
			}// end loop for sentences
			tx.success();
		} finally {
			tx.finish();
		}
	}