コード例 #1
0
        public Dictionary<string, AlchemyWeightedData> GetResponse(string SearchParam, string Category)
        {
            var sherlockRankList = new List<AlchemyWeightedData>();
            var aggDict = new Dictionary<string, AlchemyWeightedData>();
            try
            {
                //call google to get the search results - URL
                GoogleHelper gHelp = new GoogleHelper();
                IList<GoogleSearchResult> googleresultList = gHelp.GetSearchResults(SearchParam);

                IList<AlchemyWeightedData> aggrgAlchemyWeight = new List<AlchemyWeightedData>();

                //iterate through the GoogleSearchResult and pass each URL to Alchemy to get a weihted score
                foreach (var googleResult in googleresultList)
                {
                    var alchWtData = CallGetRankedNamedEntities(googleResult.GSearchResultURL, Category);
                    foreach (var alchResponse in alchWtData)
                    {
                        //if (null != aggDict[alchResponse.TextResponse])
                        if (aggDict.ContainsKey(alchResponse.TextResponse))
                        {
                            //key already exists - modify
                            var toModifyAlchemyWtData = aggDict[alchResponse.TextResponse];
                            toModifyAlchemyWtData.RelevanceScore = (toModifyAlchemyWtData.RelevanceScore + alchResponse.RelevanceScore) / 2;
                            aggDict[alchResponse.TextResponse] = toModifyAlchemyWtData;
                        }
                        else
                        {
                            //new key, just add
                            if(aggDict.Count<3)
                                aggDict.Add(alchResponse.TextResponse, alchResponse);
                        }
                    }

                }
            }
            catch (Exception e)
            { }

            return aggDict;
        }
コード例 #2
0
        public Dictionary<string, AlchemyWeightedData> GetResponse(string SearchParam, string Category, bool userIronIO)
        {
            var sherlockRankList = new List<AlchemyWeightedData>();
            var aggDict = new Dictionary<string, AlchemyWeightedData>();
            try
            {

                //call google to get the search results - URL
                GoogleHelper gHelp = new GoogleHelper();
                IList<GoogleSearchResult> googleresultList = gHelp.GetSearchResults(SearchParam);

                IList<AlchemyWeightedData> aggrgAlchemyWeight = new List<AlchemyWeightedData>();
                IronMQHelper iron = new IronMQHelper();
                var tasksToBeQueued = new QueueTaskRequest();
                var listOfTasks = new List<QueueTaskRequest.Task>();

                var response1 = iron.CreateIronMQ("SherlockMQProd", IronIOAuthToken, IronIOProjectID);

                //iterate through the GoogleSearchResult and pass each URL to Alchemy to get a weihted score
                foreach (var googleResult in googleresultList)
                {
                    //distribute the Alchemi calls to different IronIO worker threads.

                    //IronMQHelper iron = new IronMQHelper();
                    var payload = new AlchemyPayloadToIron { Url = googleResult.GSearchResultURL, Category = Category };

                    var taskToIron = new QueueTaskRequest.Task()
                    {
                        code_name = "alchemy",
                        payload = JsonConvert.SerializeObject(payload)
                    };
                    listOfTasks.Add(taskToIron);
                    tasksToBeQueued.tasks = listOfTasks;
                    //var alchWtData = CallGetRankedNamedEntities(googleResult.GSearchResultURL, Category);
                }
                QueueTaskResponse response = iron.queue_tasks(IronIOProjectID, IronIOAuthToken, tasksToBeQueued);

                foreach (var ironTask in response.tasks)
                {
                    string responseFromIronTask = iron.GetTaskResponse(IronIOProjectID, ironTask.id, IronIOAuthToken);
                    IList<AlchemyWeightedData> alchWtData = JsonConvert.DeserializeObject<IList<AlchemyWeightedData>>(responseFromIronTask);
                    foreach (var alchResponse in alchWtData)
                    {
                        if (aggDict.ContainsKey(alchResponse.TextResponse))
                        {
                            //key already exists - modify
                            var toModifyAlchemyWtData = aggDict[alchResponse.TextResponse];
                            toModifyAlchemyWtData.RelevanceScore = (toModifyAlchemyWtData.RelevanceScore + alchResponse.RelevanceScore) / 2;
                            aggDict[alchResponse.TextResponse] = toModifyAlchemyWtData;
                        }
                        else
                        {
                            //new key, just add
                            if (aggDict.Count < 3)
                                aggDict.Add(alchResponse.TextResponse, alchResponse);
                        }
                    }
                }

                //get output from workers and aggregate the data

            }
            catch (Exception e)
            { }

            return aggDict;
        }