public static double analyseTextForLanguageSet(
			HashMap<Integer, HashMap<Character, Integer>> languageFreqMap,
			HashMap<Character, Integer> charCountMap) {

		double expectedCount = 0;
		double tempSum = 0;
		double currentSum = Integer.MAX_VALUE;

		// iterate through the map created of character instances found in the
		// text being examined
		for (int k = 0; k < charCountMap.size(); k++) {
			double totalCharacterCountFromText = sumUpMapValues(charCountMap);

			// for each map of potential character expectations (i.e.
			// english/spanish/etc) examine the text's accuracy to the key.
			for (int i = 0; i < languageFreqMap.size(); i++) {
				double actualCount;
				HashMap<Character, Integer> expectedFreqChart = languageFreqMap
						.get(i);

				Iterator<Character> it = expectedFreqChart.keySet().iterator();
				while (it.hasNext()) {
					char c = it.next();
					if (charCountMap.get(c) != null)
						actualCount = charCountMap.get(c);
					else
						actualCount = 0;

					expectedCount = ((double) expectedFreqChart.get(c) / 100)
							* totalCharacterCountFromText;

					tempSum += Math.abs(expectedCount - actualCount)
							* Math.abs(expectedCount - actualCount);

				}

				// in the case where a character was expected, but not seen in
				// text, update the error
				Iterator<Character> itTwo = charCountMap.keySet().iterator();
				while (itTwo.hasNext()) {
					char ch = itTwo.next();
					if (expectedFreqChart.get(ch) == null) {
						tempSum += charCountMap.get(ch) * charCountMap.get(ch);
					}
				}

				// keep track of the current lowest deviation from an expected
				// set in order to decide which
				// of the language frequency charts is closest to the text at
				// hand.
				if (tempSum < currentSum) {
					currentSum = tempSum;
				}

				// Reset tempSum for next loop.
				tempSum = 0;
			}

		}

		return currentSum;
	}