@Override
    public Double documentRank(List<String> document, List<String> query) {
        
        if(iDFMatrix != null) return documentRankIDFWeighted(document, query, iDFMatrix);
        if(document.isEmpty() && query.isEmpty()) return 1.0;
        if(document.isEmpty() && !query.isEmpty()) return 0.0;
        if(query.isEmpty() && !document.isEmpty()) return 0.0;
        
        FrequencyMatrix documentFrequencyMatrix = new FrequencyMatrix(document);
        FrequencyMatrix queryFrequencyMatrix = new FrequencyMatrix(query);
        double denominator;
        int numerator = 0;
        int aMagnitudeTotal = 0;
        int bMagnitudeTotal = 0;
        
        for(String word : document)
        {
            numerator += documentFrequencyMatrix.getFreq(word) * queryFrequencyMatrix.getFreq(word);
            aMagnitudeTotal += Math.pow(documentFrequencyMatrix.getFreq(word), 2);
        }
        for(String word : query)
            bMagnitudeTotal += Math.pow(queryFrequencyMatrix.getFreq(word), 2);
        
        denominator = Math.sqrt(aMagnitudeTotal) * Math.sqrt(bMagnitudeTotal);
        
        double sim = (double)numerator / denominator;
        return sim;
    }