コード例 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string term1 = null;
            string term2 = null;

            if (!DA.GetData(0, ref term1) || !DA.GetData(1, ref term2))
            {
                return;
            }

            // If the retrieved data is Nothing, we need to abort.
            // We're also going to abort on a zero-length String.
            if ((term1 == null) || (term2 == null))
            {
                return;
            }
            if ((term1.Length == 0) || (term2.Length == 0))
            {
                return;
            }



            // relations as string
            var conceptRelations = wrapper.GetConceptRelationsAsString(term1);

            // Return terms related to the term
            var relatedTerms = wrapper.GetRelatedTerms("Tea Kettle");

            // Return the relations between these two terms
            // var result3 = wrapper.GetConceptNetResults("dog", "bark");

            // Return the relations between these two terms as comma separated string
            var termsRelations = wrapper.GetConceptRelationsAsString(term1, term2);

            // Return the relations between these two terms in data table format
            // var result5 = wrapper.GetConceptRelationsAsDataTable("dog", "bark");

            // If you just want to see how related term1 (e.g., "tea kettle") is to term2 (e.g., "coffee pot") **
            var howTermsRelated = wrapper.GetHowTermsRelated(term1, term2);

            // Return the relation score
            var relationScore = wrapper.GetRelationScore(term1, term2);

            // Get results based on query (comma seperated string )
            // var result9 = wrapper.GetConceptNetQueryResults("node=/c/en/dog,other=/c/en/bark");

            DA.SetData(0, conceptRelations);
            DA.SetData(1, relatedTerms);
            DA.SetData(2, termsRelations);
            DA.SetData(3, howTermsRelated);
            DA.SetData(4, relationScore);
        }
コード例 #2
0
ファイル: TailoredRepository.cs プロジェクト: bhylak/newscape
    public ScoredSearchResult Search(string searchTerm)
    {
        double           bestScore     = double.MinValue;
        string           bestAssetTerm = "";
        TailoredResponse bestResponse  = null;

        foreach (var potentialResponse in _availableResponses)
        {
            foreach (string assetTerm in potentialResponse.matchingTerms)
            {
                double score = _conceptNet.GetRelationScore(searchTerm, assetTerm);

                if (score > bestScore)
                {
                    bestAssetTerm = assetTerm;
                    bestResponse  = potentialResponse;
                    bestScore     = score;
                }
            }
        }

        if (bestResponse == null)
        {
            return(new ScoredSearchResult());
        }
        else if (bestScore == 1)
        {
            bestScore = 1.75;
        }
        else if (bestScore > .65f)
        {
            bestScore = 1;
        }

        Debug.Log("Best tailored response for " + searchTerm + ": " + bestAssetTerm + " (" + bestScore + ")");

        if (bestScore < 0.15)
        {
            bestScore = 0;
        }
        else if (bestScore < 0.5)
        {
            bestScore = 0.1;
        }

        return(new ScoredSearchResult(bestResponse.equivalentModels[0], bestScore, bestAssetTerm));
    }
コード例 #3
0
ファイル: NewsScript.cs プロジェクト: bhylak/newscape
    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);
    }