/// <summary> /// Perform an ANN search on the class' world, given a vector, returning the (approximate) k-best results. /// </summary> /// <param name="queryVector">The query vector.</param> /// <param name="kBest">How many results should be returned (K-Value).</param> /// <returns>A <see cref="QueryResult"/> object containing the K best results.</returns> public QueryResult RunANNQuery(NamedFeatureVector queryVector, int kBest) { QueryResult queryresult = new QueryResult(queryVector.Name); IList <SmallWorld <NamedFeatureVector, double> .KNNSearchResult> kBestResults = world.KNNSearch(queryVector, kBest); foreach (SmallWorld <NamedFeatureVector, double> .KNNSearchResult queryitem in kBestResults) { queryresult.AddItem(new QueryItem(queryitem.Item.Name, queryitem.Distance)); } return(queryresult); }
/// <summary> /// Reads a queryresult file, given a streamreader. /// </summary> /// <param name="reader">The streamreader.</param> /// <returns>The array with queryresult.</returns> public QueryResult[] ConvertFile(StreamReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } List <QueryResult> results = new List <QueryResult>(); using (CsvReader csv = CsvReader(reader)) { // Csv syntax for reading headers. csv.Read(); csv.ReadHeader(); // Read the header, to see which measures there are. string[] kNames = FilterHeader(csv); // Find the individual values. while (csv.Read()) { // Check to see if there is an entry here. if (!csv.TryGetField(MeshName, out string name)) { break; } QueryResult query = new QueryResult(name); foreach (string kName in kNames) { if (csv.TryGetField(kName, out string serialised) && QueryItem.TryParse(serialised, out QueryItem item)) { query.AddItem(item); } } //else break; results.Add(query); } } return(results.ToArray()); }