// Path: src/main/java/org/latna/msw/documents/DocumentFileFactory.java
// public class DocumentFileFactory implements MetricElementFactory {
//     public String testDataDirPath="C:/msw/MetricSpaceLibrary/dbs/documents/short";
//     private int maxDoc; 
// 
//     @Override
//     public List<MetricElement> getElements() {
//         List <MetricElement> docList = new ArrayList();
//         File dir = new File(testDataDirPath);
//         int i = 0;
//         for (File file: dir.listFiles() ) {
//             if (i >  maxDoc)  break;
//             
//             Scanner sc = null;
//             try {
//                  sc = new Scanner(file);
//                  Document newDoc = new Document(file.getName());
// 
//                  while (sc.hasNext()) {
//                      String termId = sc.next();
//                      String d = sc.next();
//                      double value = new Double(d);
// 
//                      newDoc.addTerm(termId, value);
//                  }
//                  docList.add(newDoc);
//             } catch (FileNotFoundException ex) {
//                 System.out.println(ex);
//             } finally {
//                 sc.close();
//             }            
//             i++;
//         }
//         System.out.println(i+ " documents readed");
//         return docList;
//     }
//     /**
//      * DocumentFileFactory get two parameters: [dir="filePath"] - path to directory 
//      * which contains set of documents presented by frequence term vector and 
//      * [maxDoc=d+] - the restriction on the number returned documents. 
//      * if you want do not restrict the number of documents set maxDoc=0
//      * @param param 
//      */
//     @Override
//     public void setParameterString(String param) {
//          Scanner s = new Scanner(new StringReader(param));
//             s.findInLine("dir=(.+); maxDoc=(\\d+)");
//             MatchResult matchResult = s.match();
// 
//             for (int i=1; i<=matchResult.groupCount(); i++)
//                 System.out.println(matchResult.group(i));
// 
//             s.close();
// 
//           testDataDirPath = matchResult.group(1);
//           maxDoc = Integer.valueOf(matchResult.group(2));
//           
//           if (maxDoc == 0) maxDoc =  Integer.MAX_VALUE;
//         
//     }
// 
// }


import org.latna.msw.documents.DocumentFileFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package org.latna.msw;


/**
 * This is a simple example of building MetrizedSmallWorld over the set of 
 * document objects from the trec-3 collection.
 * Any document or query is represented by term frequency vector.
 * The test is divided into the three stages.
 * 
 * The first stage - reading data set to the memory (documents and queries), 
 * configuring algorithms and building the data structure.   
 * 
 * The second stage - to obtain the true nearest neighbor element for every
 * query by the use sequentially scan
 * 
 * The third stage - a search in metric data structure with several number
 * of attempts, validate the search result.
 */
public class PowerLawTestTrec3 {
    /**
     * Scans input string and runs the test
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        int nn = 7; //number of nearest neighbors used in construction algorithm to approximate voronoi neighbor
        int k = 5; //number of k-closest elements for the knn search
        int initAttempts = 5; //number of search attempts used during the contruction of the structure
        int minAttempts = 1 ; //minimum number of attempts used during the test search 
        int maxAttempts = 10; //maximum number of attempts 
  //      int dataBaseSize = 1000; 
        int dataBaseSize = 0; //the restriction on the number of elements in the data structure. To set no restriction set value = 0
        int querySetSize = 50; //the restriction on the number of quleries. To set no restriction set value = 0
        int testSeqSize = 30; //number elements in the random selected subset used to verify accuracy of the search. 
        String dataPath = "C:/msw/MetricSpaceLibrary/dbs/documents/short"; //Path to directory documents from Trec-3 collection. See Metric Space Library 
        String queryPath = "C:/msw/MetricSpaceLibrary/dbs/documents/shortQueries"; //Path to queries 
       

       /* int nn = Integer.valueOf(args[0]);
        int k = Integer.valueOf(args[1]);
        int initAttempts = Integer.valueOf(args[2]);
        int minAttempts = Integer.valueOf(args[3]);
        int maxAttempts = Integer.valueOf(args[4]);
        int dataBaseSize = Integer.valueOf(args[5]);
        int querySetSize = Integer.valueOf(args[6]);
        int testSeqSize = Integer.valueOf(args[7]);
        String dataPath = args[8];
        String queryPath = args[9];
*/
    
        System.out.println("nn=" + nn + " k=" + k + " initAttemps="+initAttempts + " minAttempts=" + minAttempts + " maxAttempts=" +
                maxAttempts + " dataBaseSize=" + dataBaseSize + " querySetSize=" + querySetSize + " testSeqSize=" + testSeqSize);

// Path: src/main/java/org/latna/msw/documents/DocumentFileFactory.java
// public class DocumentFileFactory implements MetricElementFactory {
//     public String testDataDirPath="C:/msw/MetricSpaceLibrary/dbs/documents/short";
//     private int maxDoc; 
// 
//     @Override
//     public List<MetricElement> getElements() {
//         List <MetricElement> docList = new ArrayList();
//         File dir = new File(testDataDirPath);
//         int i = 0;
//         for (File file: dir.listFiles() ) {
//             if (i >  maxDoc)  break;
//             
//             Scanner sc = null;
//             try {
//                  sc = new Scanner(file);
//                  Document newDoc = new Document(file.getName());
// 
//                  while (sc.hasNext()) {
//                      String termId = sc.next();
//                      String d = sc.next();
//                      double value = new Double(d);
// 
//                      newDoc.addTerm(termId, value);
//                  }
//                  docList.add(newDoc);
//             } catch (FileNotFoundException ex) {
//                 System.out.println(ex);
//             } finally {
//                 sc.close();
//             }            
//             i++;
//         }
//         System.out.println(i+ " documents readed");
//         return docList;
//     }
//     /**
//      * DocumentFileFactory get two parameters: [dir="filePath"] - path to directory 
//      * which contains set of documents presented by frequence term vector and 
//      * [maxDoc=d+] - the restriction on the number returned documents. 
//      * if you want do not restrict the number of documents set maxDoc=0
//      * @param param 
//      */
//     @Override
//     public void setParameterString(String param) {
//          Scanner s = new Scanner(new StringReader(param));
//             s.findInLine("dir=(.+); maxDoc=(\\d+)");
//             MatchResult matchResult = s.match();
// 
//             for (int i=1; i<=matchResult.groupCount(); i++)
//                 System.out.println(matchResult.group(i));
// 
//             s.close();
// 
//           testDataDirPath = matchResult.group(1);
//           maxDoc = Integer.valueOf(matchResult.group(2));
//           
//           if (maxDoc == 0) maxDoc =  Integer.MAX_VALUE;
//         
//     }
// 
// }


// Path: src/main/java/org/latna/msw/PowerLawTestTrec3.java
import org.latna.msw.documents.DocumentFileFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

package org.latna.msw;


/**
 * This is a simple example of building MetrizedSmallWorld over the set of 
 * document objects from the trec-3 collection.
 * Any document or query is represented by term frequency vector.
 * The test is divided into the three stages.
 * 
 * The first stage - reading data set to the memory (documents and queries), 
 * configuring algorithms and building the data structure.   
 * 
 * The second stage - to obtain the true nearest neighbor element for every
 * query by the use sequentially scan
 * 
 * The third stage - a search in metric data structure with several number
 * of attempts, validate the search result.
 */
public class PowerLawTestTrec3 {
    /**
     * Scans input string and runs the test
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        int nn = 7; //number of nearest neighbors used in construction algorithm to approximate voronoi neighbor
        int k = 5; //number of k-closest elements for the knn search
        int initAttempts = 5; //number of search attempts used during the contruction of the structure
        int minAttempts = 1 ; //minimum number of attempts used during the test search 
        int maxAttempts = 10; //maximum number of attempts 
  //      int dataBaseSize = 1000; 
        int dataBaseSize = 0; //the restriction on the number of elements in the data structure. To set no restriction set value = 0
        int querySetSize = 50; //the restriction on the number of quleries. To set no restriction set value = 0
        int testSeqSize = 30; //number elements in the random selected subset used to verify accuracy of the search. 
        String dataPath = "C:/msw/MetricSpaceLibrary/dbs/documents/short"; //Path to directory documents from Trec-3 collection. See Metric Space Library 
        String queryPath = "C:/msw/MetricSpaceLibrary/dbs/documents/shortQueries"; //Path to queries 
       

       /* int nn = Integer.valueOf(args[0]);
        int k = Integer.valueOf(args[1]);
        int initAttempts = Integer.valueOf(args[2]);
        int minAttempts = Integer.valueOf(args[3]);
        int maxAttempts = Integer.valueOf(args[4]);
        int dataBaseSize = Integer.valueOf(args[5]);
        int querySetSize = Integer.valueOf(args[6]);
        int testSeqSize = Integer.valueOf(args[7]);
        String dataPath = args[8];
        String queryPath = args[9];
*/
    
        System.out.println("nn=" + nn + " k=" + k + " initAttemps="+initAttempts + " minAttempts=" + minAttempts + " maxAttempts=" +
                maxAttempts + " dataBaseSize=" + dataBaseSize + " querySetSize=" + querySetSize + " testSeqSize=" + testSeqSize);

        MetricElementFactory elementFactory= new DocumentFileFactory();