public void ConstructorTest_Artifacts() { string inputData = Settings.Default.SimpleCorpusDir; string outputData = Path.Combine(inputData, "TermDocumentMatrix"); TermDocumentMatrix matrix = new TermDocumentMatrix(Artifacts.ImportFile(Path.Combine(inputData, "target.txt"))); TermDocumentMatrix answer = TermDocumentMatrix.Load(Path.Combine(outputData, "output.txt")); // counts Assert.AreEqual(matrix.NumDocs, answer.NumDocs); Assert.AreEqual(matrix.NumTerms, answer.NumTerms); // matrix for (int i = 0; i < answer.NumDocs; i++) { Assert.AreEqual(matrix.GetDocumentName(i), answer.GetDocumentName(i)); Assert.AreEqual(matrix.GetDocument(i).Length, answer.NumTerms); for (int j = 0; j < answer.NumTerms; j++) { Assert.AreEqual(matrix.GetTermName(j), answer.GetTermName(j)); Assert.AreEqual(matrix[i, j], answer[i, j], 0.0); } } }
public void BooleanQueriesAndTFIDFCorpusTest() { string inputData = Settings.Default.SimpleCorpusDir; string outputData = Path.Combine(inputData, "VSM"); TLArtifactsCollection source = Artifacts.ImportFile(Path.Combine(inputData, "source.txt")); TLArtifactsCollection target = Artifacts.ImportFile(Path.Combine(inputData, "target.txt")); TLSimilarityMatrix testsims = VSM.Compute(source, target, VSMWeightEnum.BooleanQueriesAndTFIDFCorpus); TLSimilarityMatrix realsims = Similarities.Import(Path.Combine(outputData, "output.txt")); Assert.AreEqual(testsims.Count, realsims.Count); TLLinksList testlinks = testsims.AllLinks; TLLinksList reallinks = realsims.AllLinks; testlinks.Sort(); reallinks.Sort(); for (int i = 0; i < reallinks.Count; i++) { Assert.AreEqual(testlinks[i].SourceArtifactId, reallinks[i].SourceArtifactId); Assert.AreEqual(testlinks[i].TargetArtifactId, reallinks[i].TargetArtifactId); Assert.AreEqual(testlinks[i].Score, reallinks[i].Score, Settings.Default.DoublePrecision); } }