private async void FindBestAssetForTerms(Dictionary <string, double> termScores, Dictionary <string, bool> termIsPersonMap) { double bestScore = double.MinValue; ScoredSearchResult bestAssetForTerm = new ScoredSearchResult(); string bestTerm = ""; Dictionary <string, Task <ScoredSearchResult> > polyLookupTasks = termScores.Keys.ToDictionary(x => x, x => SearchPoly(x)); await new WaitForBackgroundThread(); await Task.WhenAll(polyLookupTasks.Values.AsEnumerable()); for (int i = 0; i < termScores.Keys.Count; i++) { string term = termScores.Keys.ElementAt(i); var polyAssetResult = await polyLookupTasks[term]; var tailoredAssetResult = TailoredRepository.Search(term); bool termIsPerson = false; termIsPersonMap.TryGetValue(term, out termIsPerson); ScoredSearchResult termSearchResult = termIsPerson || tailoredAssetResult.score > polyAssetResult.score ? tailoredAssetResult : polyAssetResult; //search tailored source, choose Debug.Log(String.Format("Word: {0} Weight: {1}", term, termScores[term])); //TODO: handle the fact that the best could be either poly or tailored termScores[term] *= Math.Pow(termSearchResult.score, 2); if (termScores[term] > bestScore) { bestTerm = term; bestAssetForTerm = termSearchResult; bestScore = termScores[term]; } } //priority queue of words and weights //three options for finding models // 1. Search through keywords until a model accuracy threhsold (e.g. .7) is surpassed // 2. Find highest combination of term relevancy and model accuracy // 3. Combine both? (Find highest in first 4 words, then if they don't pass threshold, continue) // 2 probably makes the most sense, given that this process doesn't need much optimizaition await new WaitForUpdate(); if (bestAssetForTerm.searchType == ScoredSearchResult.SearchType.POLY) { //todo convert to await AddFromPoly(bestAssetForTerm.polyAsset); } else { var gameObject = GameObject.Instantiate(bestAssetForTerm.tailoredAsset); gameObject.name = bestAssetForTerm.name; gameObject.transform.position = Vector3.zero; } //GetComponent<GameManager>().lastSearchKeywords = bestAssetForTerm.name; Debug.Log("Best word: " + bestTerm); }
private void ApplyScoringModifiers(string search, ScoredSearchResult ssr) { var canonicalPath = ssr.Entry.CanonicalPath; var namePath = ssr.Entry.NamePath; foreach (var scoreBoost in Settings.Instance.ScoreBoosts) { if (scoreBoost.Matcher.Match(canonicalPath) || scoreBoost.Matcher.Match(namePath)) ssr.Score += scoreBoost.Score; } FrecencyEntry frecencyEntry = null; if(frecencyEntries.TryGetValue(canonicalPath, out frecencyEntry)) { ssr.Score += (int)Math.Ceiling(Math.Sqrt(frecencyEntry.NLaunched) * 15); } if (namePath.ToLowerInvariant().StartsWith(search.ToLowerInvariant())) ssr.Score += 15; }
public async Task <ScoredSearchResult> SearchPoly(string term) { Debug.Log("Searching Poly for term: " + term); var request = new PolyListAssetsRequest(); request.orderBy = PolyOrderBy.BEST; request.keywords = term; request.curated = true; PolyListAssetsResult result = null; bool error = false; PolyApi.ListAssets(request, response => { if (response.Ok) { result = response.Value; } else { error = true; } }); while (result == null && !error) //TODO: Add Timeout to avoid infinite loop! { await Task.Delay(50); } await new WaitForBackgroundThread(); PolyAsset bestAsset = null; double bestScore = double.MinValue; if (result != null) { foreach (var asset in result.assets) { //get how related it is to the search term //if doesn't exist in concept net, only accept exact matches (or lev dists <2) //made by poly is * 1.5 multiplier (can tweak) double score = -1; if (asset.displayName.ToLower().Equals(term)) { score = 1; } else { score = _conceptNet.GetRelationScore(asset.displayName.ToLower(), term); } Debug.Log(asset.displayName + " by: " + asset.authorName + " (" + score + ") ");; if (asset.authorName.Contains("Google")) { score = score * 1.75; } if (score > bestScore) { bestScore = score; bestAsset = asset; } } } if (bestAsset != null) { Debug.Log( String.Format("Term: {0}, Asset: {1}, Score: {2}", term, bestAsset.displayName + " by: " + bestAsset.authorName, bestScore)); } else { Debug.Log("No results for term: " + term); } var bestResult = new ScoredSearchResult(); bestResult.score = bestScore; bestResult.polyAsset = bestAsset; await new WaitForUpdate(); return(bestResult); }