<div dir="ltr"><div><div><div><div><div><div><div>Hello,<br></div><br>I had been thinking about how to write tests that help us come up with the public API that will be used for clustering and I'd just like to describe two tests and the way I am thinking about the API. I'd like to know whether I'm on the right path or how this can be improved.<br><br></div>1) Testcase to check euclidian similarity of document vectors<br><br></div>DEFINE_TESTCASE(euclidian, backend)<br>{<br>    Xapian::Database db(get_database("euclidian"));<br></div>    //Make this file contain two sentences which are identical and treated as two diff docs<br></div>    //Get MSet containing two docs<br></div>    Document doc1 = mset[0].get_document();<br></div>    Document doc2 = mset[1].get_document();<br>    DocSim d;<br>    int sim = d.get_distance(doc1.termlist_begin(), doc1.termlist_end(), doc2.termlist_begin(), doc2.termlist_end(), SIMILARITY_OPTION /* (in this case, euclidian) */ );<br>    TEST( sim == 0)<br><div><div><div><div><div><div><div>}<br><div><br></div><div>The creation of TF-IDF vectors from the termlists of the documents will be done inside the DocSim class. The get_distance() function calculates the distance and we can support many similarity measures later on. The default can be euclidian distance<br><br></div><div>2) Test case to check whether clusters are valid by checking whether any cluster is empty<br><br></div><div>DEFINE_TESTCASE(custer1, backend)<br>{<br>    Xapian::Database db(get_database("cluster_api"));<br></div><div>    //Get Mset against a query, MSet -> matches<br></div><div>    Xapian::Cluster c;<br>    Xapian::ClusterSet cset = c.cluster(matches,k);<br>    if (cset != NULL)<br>    {<br>        for(Xapian::ClusterSetIterator i=cset.begin(); i!=cset.end(); i++)<br>        {<br>            Xapian::DocumentSet d = i.get_clusterdocs();<br>            TEST(d.size() != 0)<br>        }<br>    }<br></div><div>}<br><br></div><div>Xapian::Cluster class will contain the main clustering functionality which will cluster the documents and store the results in a class Xapian:ClusterSet, which is returned by Xapian::Cluster::cluster(). This will also contain a vector of the cluster IDs and a map of document IDs and its associated cluster ID.<br><br></div><div>Xapian::ClusterSet contains the cluster ID and vector of documents belonging to that cluster. Xapian::ClusterSetIterator can be used to go through the ClusterSet objects<br><br></div><div>The documents belonging to a certain cluster can be retrieved by a function which returns documents to a DocumentSet. This can again be made iterable but I don't know how productive making a DocumentSet would be.<br><br></div><div>This is a very rough way of how I think the API would be. I'd like to know if there are places where I am going wrong so I can improve on them before the coding period starts.<br><br></div><div>Also, I apologize for not being too responsive on the mailing list, but I've been having exams going on. They'll be getting over on the 26th of this month, after which I can concentrate on the project completely.<br><br></div><div>Thanks,<br></div><div>Richhiey<br></div><div><br></div></div></div></div></div></div></div></div></div>