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; }
/// <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); } }