/// <summary> /// Checks whether the supplied question is a duplicate of another post. /// </summary> /// <param name="q">The questions to check.</param> /// <param name="matcherAlgo">The matching algorithm to use.</param> /// <returns> /// The match results from the specified matcher algo /// if the question is a duplicate, otherwise null. /// </returns> public MatchResults IsDupe(Question q, MatcherAlgo matcherAlgo) { if (q == null) throw new ArgumentNullException(nameof(q)); //var testQ = PostFetcher.GetQuestion("https://stackoverflow.com/questions/15735570"); var matcher = matchers.Single(x => x.Algo == matcherAlgo); var res = matcher.Match(q); // Any number between 0 and 1. // 0.5 seems like a good start. if (res.MatchScore > 0.5) return res; else return null; }
public MatchResults Match(Question q) { if (q == null) throw new ArgumentNullException(nameof(q)); var questionSearchRes = SeApiAccessor.Search(q.Title, q.Tags); var bow = new BagOfWordsBeta(); foreach (var question in questionSearchRes) { if (question.ID == q.ID) continue; var tf = pos.GetModel(question.Body); bow.AddDocument(question.ID, tf); } var qModel = pos.GetModel(q.Body); var match = bow.GetSimilarity(qModel, 1); return new MatchResults { LinkToDupeTarget = $"http://stackoverflow.com/q/{match.Keys.First()}", MatchScore = match.Values.First() }; }