Esempio n. 1
0
        public string AnalyzeText(string text)
        {
            if (text == null || text.Length < 5)
            {
                text = "empty";
            }

            text = text.Replace("%20", " ");

            var response = CallAlchemyApiAnalysisOnText(text);

            if (response == null || response.Keywords == null || !response.Keywords.Any())
            {
                return(BlankModelUrn);
            }

            var defaultResult = new FileUrnWithRelevancy()
            {
                Relevancy = 0, URN = BlankModelUrn
            };
            var matchedTagsAndRelevancy = new List <FileUrnWithRelevancy> {
                defaultResult
            };

            foreach (var model in RenderedModelsRepository.ModelList.Models)
            {
                var tags            = model.Tags.Replace(" ", "").Split(',');
                var keywordsStrings = response.Keywords.Select(k => k.Text);

                var intersectTagsWithKeywords = tags.Intersect(keywordsStrings);
                if (intersectTagsWithKeywords.Any())
                {
                    var relevancy = response.Keywords.First(k => k.Text == intersectTagsWithKeywords.First()).Relevance;
                    var urn       = model.FileUrn;

                    matchedTagsAndRelevancy.Add(new FileUrnWithRelevancy()
                    {
                        Relevancy = Convert.ToDouble(relevancy), URN = urn
                    });
                }
            }

            var result = defaultResult;

            foreach (var fileUrnWithRelevancy in matchedTagsAndRelevancy)
            {
                if (fileUrnWithRelevancy.Relevancy > result.Relevancy)
                {
                    result = fileUrnWithRelevancy;
                }
            }

            return(result.URN);
        }
        public string AnalyzeText(string text)
        {
            if (text == null || text.Length < 5)
              {
            text = "empty";
              }

              text = text.Replace("%20", " ");

              var response = CallAlchemyApiAnalysisOnText(text);

              if (response == null || response.Keywords == null || !response.Keywords.Any())
              {
            return BlankModelUrn;
              }

              var defaultResult = new FileUrnWithRelevancy() {Relevancy = 0, URN = BlankModelUrn};
              var matchedTagsAndRelevancy = new List<FileUrnWithRelevancy> {defaultResult};

              foreach (var model in RenderedModelsRepository.ModelList.Models)
              {
            var tags = model.Tags.Replace(" ", "").Split(',');
            var keywordsStrings = response.Keywords.Select(k => k.Text);

            var intersectTagsWithKeywords = tags.Intersect(keywordsStrings);
            if (intersectTagsWithKeywords.Any())
            {
              var relevancy = response.Keywords.First(k => k.Text == intersectTagsWithKeywords.First()).Relevance;
              var urn = model.FileUrn;

              matchedTagsAndRelevancy.Add(new FileUrnWithRelevancy(){Relevancy = Convert.ToDouble(relevancy), URN = urn});
            }
              }

              var result = defaultResult;
              foreach (var fileUrnWithRelevancy in matchedTagsAndRelevancy)
              {
            if (fileUrnWithRelevancy.Relevancy > result.Relevancy)
            {
              result = fileUrnWithRelevancy;
            }
              }

              return result.URN;
        }