/// <summary> /// Manage the build command /// </summary> /// <param name="args"> /// Argument in command line syntax (--key value) /// </param> public static void Build(IEnumerable<string> args) { string indexclass = null; string spaceclass = null; string indexname = null; bool forcebuild = false; var op = new OptionSet () { {"indexclass=", "Build an index of class 'indexclass'", v => indexclass = v}, {"indexname|index=", "Index name", v => indexname = v}, {"spaceclass=", "Space's class", v => spaceclass = v}, {"force", "Force to build", v => forcebuild = true} }; op.Parse (args); if (indexclass == null || spaceclass == null || indexname == null) { Console.WriteLine ("--build options:"); op.WriteOptionDescriptions (Console.Out); Console.WriteLine (); Console.WriteLine ("** The indexclass value must be one of the following: "); foreach (string iname in IndexLoader.IndexFactory.Keys) { Console.WriteLine ("{0}", iname); } List<IndexAttribute> Iattr = new List<IndexAttribute> (); List<SpaceAttribute> Sattr = new List<SpaceAttribute> (); foreach (Type E in typeof(Commands).Assembly.GetTypes()) { foreach (IndexAttribute itemI in E.GetCustomAttributes(typeof(IndexAttribute), true)) { Iattr.Add (itemI); } foreach (SpaceAttribute itemS in E.GetCustomAttributes(typeof(SpaceAttribute), true)) { Sattr.Add (itemS); } } Console.WriteLine (); Console.WriteLine ("** The spaceclass value must be one of the following: "); foreach (string iname in SpaceCache.SpaceFactory.Keys) { Console.WriteLine ("{0}", iname); } Console.WriteLine (); Console.WriteLine ("If you don't see the desired index or space, please ensure "); Console.WriteLine ("that there's a handler for it and to be in the plug-in path"); throw new ArgumentException ("Some mandatory arguments were not given"); } var C = new Chronos (); if (forcebuild || !File.Exists (indexname)) { Console.WriteLine ("Building {0}", indexname); Index idx = IndexLoader.Create (indexclass, spaceclass, null); C.Begin (); idx.Build (args); C.End (); Console.WriteLine ("=== Build time {0}", indexname); C.PrintStats ("build-time-"); } else { Console.WriteLine ("Skipping {0} because already exists (--force to force build)", indexname); } }
public static ResultTies Search1(IList<byte> qext, Dictionary<int,double> acc, int numqgrams, LSC<IList<byte>> I, double probabilidad) { Chronos time = new Chronos(); var aspace = (AudioSpace)I.MainSpace; int numsampleq = numqgrams; int skip = numqgrams/numsampleq; Random r = new Random(); time.Begin(); for(int sindex=0; sindex <numsampleq; sindex++){ int qindex = sindex * skip; BinQGram qgram = new BinQGram(qext, qindex * aspace.SymbolSize, aspace.Q); IResult R = new Result(int.MaxValue, false); if(r.NextDouble() > probabilidad){ continue; } I.KNNSearch(qgram,-1,R); HashSet<int> docId = new HashSet<int>(); foreach (var u in R){ docId.Add(aspace.GetDocIdFromBlockId(u.docid)); } foreach (var d in docId){ double dist; if(!acc.TryGetValue(d ,out dist)){ acc[d] = -1; } else{ acc[d]--; } } } time.End(); //time.PrintStats("Tiempo de busqueda"); var Rf = new ResultTies(100 , false); foreach (var u in acc){ Rf.Push(u.Key, u.Value); } return Rf; }
public void CreateSketch(IList<IList<int>> invindex, int maxvalue) { // after PermSortByFreq the invindex is permutated too var L = new IList<int>[invindex.Count]; for (int i = 0; i < L.Length; i++) { L [i] = invindex [i]; } this.PermSortByFreq (L, maxvalue); this.Sketch = new ListSDiff64 (); Console.WriteLine ("Creating sketch of the text"); Chronos C = new Chronos (); C.Start (); var S = new InvIndexSketchBuilder (L, this.N); S.Build (this.Sketch, this.AlphabetBlock); C.End (); C.PrintStats (); }
public static void testLSHV(string listname, string qlist, int Q, int S) { int porcen=0; int numconsult=0; Console.WriteLine("<-- Building LSH Multiple Tables -->"); string indexName = string.Format("Index.LSC.Prueba.xml"); HammingMLSC I; if (!File.Exists(indexName)) { I = new HammingMLSC(); I.SeqBuilder = SequenceBuilders.GetSeqXLB_SArray64 (16); if (! (File.Exists(listname + ".header"))) { var A = new AudioSpace(); A.Build(listname, 30*3, 3); } I.Build(indexName,"audio-space",listname,20,1); } I = IndexLoader.Load(indexName) as HammingMLSC; Console.WriteLine("<-- Searching first object -->"); var aspace = (AudioSpace)I.MainSpace; Chronos tiempo = new Chronos(); foreach (var qname in (new QueryStream(qlist)).Iterate()) { numconsult++; Console.WriteLine ("<<<--- Inizializing query --->>>"); tiempo.Start(); var R = SearchAudio (qname, aspace,I); tiempo.End(); if(R.Count>0){ porcen++; } Console.WriteLine ("qname: {0}",qname.QRaw); tiempo.PrintStats("****Tiempo de consulta****"); var qext = BinaryHammingSpace.ParseAndLoadFromFile(qname.QRaw,false); foreach ( var p in R){ Console.WriteLine ("docid: {0}, dist: {1}, name: {2}",p.docid, p.dist, aspace.GetNameFromDocId(p.docid)); var audio = aspace.GetAudio(p.docid); var distanciaHamming = BinaryHammingSpace.DistMinHamming(audio,qext,aspace.SymbolSize); Console.WriteLine ("***********DocId: {0}, Distancia BinaryHamming: {1}***************",p.docid, distanciaHamming); Console.WriteLine ("***********Error: {0}%",distanciaHamming/(qext.Count/aspace.SymbolSize * 24)*100); } Console.WriteLine ("<<<--- Finalizing query --->>>"); } Console.WriteLine("Porcentaje de respuesta: {0}%",porcen*100/numconsult); }