public List<KeyValuePair<string, double>> RankedResults() { List<Document> documents = new List<Document>(); HashSet<string> dataSet = new HashSet<string>(); foreach (var result in results) { Document d = new Document(result); documents.Add(d); foreach (var term in d.tokens()){ dataSet.Add(term); } } //Build Document Vectors Dictionary<string, Vector> documentVectors = new Dictionary<string, Vector>(); foreach (var document in documents) { documentVectors.Add(document.ToString(), new Vector(dataSet, document)); } //Build Query Vector Query query = new Query(queryString); Vector queryVector = new Vector(dataSet, query); Dictionary<string, double> relevance = new Dictionary<string, double>(); foreach (var documentVector in documentVectors) { relevance.Add(documentVector.Key, Vector.GetSimilarityScore(queryVector, documentVector.Value)); } //Sort result by most relevant List<KeyValuePair<string, double>> myList = relevance.ToList(); return myList; }
public Vector(HashSet<string> dataSet, Query query) { this.dataSet = dataSet; vectorRep = query.GetVector(dataSet); }