public double CalculateDistance(ITermWeightRepresentation termWeightRepresentation, TermsCollection termsCollection) { double sum = 0; foreach (string term in termsCollection.Terms) { sum += Math.Pow(termWeightRepresentation.TermWeight(term), 2); } return Math.Sqrt(sum); }
public double CalculateProbability(ITermWeightRepresentation queryRepresentation, ITermWeightRepresentation documentRepresentation, TermsCollection termsCollection) { double queryDistance = _distanceCalculator.CalculateDistance(queryRepresentation, termsCollection); double documentDistance = _distanceCalculator.CalculateDistance(documentRepresentation, termsCollection); double sum = 0; foreach (string term in termsCollection.Terms) { sum += queryRepresentation.TermWeight(term)*documentRepresentation.TermWeight(term); } return sum/(queryDistance*documentDistance); }
/// <summary> /// /// </summary> /// <param name="termWeightRepresentation">should be instance of <see cref="Tf"/></param> /// <param name="idf"></param> public TfIdf(ITermWeightRepresentation termWeightRepresentation, IIdf idf) { _termWeightRepresentation = termWeightRepresentation; _idf = idf; }