Esempio n. 1
0
        /// <summary>
        /// Create a keyword release
        /// </summary>
        /// <param name="Ado"></param>
        /// <param name="releaseId"></param>
        /// <param name="userName"></param>
        internal void Create(ADO Ado, int releaseId, string userName)
        {
            Release_ADO rAdo = new Data.Release_ADO(Ado);

            var latestRelease = Release_ADO.GetReleaseDTO(rAdo.ReadID(releaseId, userName));

            if (latestRelease == null) return;

            rAdo.DeleteKeywords(latestRelease.RlsCode, userName);

            //Create the table that will be bulk inserted
            DataTable dt = new DataTable();
            dt.Columns.Add("KRL_VALUE", typeof(string));
            dt.Columns.Add("KRL_RLS_ID", typeof(int));
            dt.Columns.Add("KRL_MANDATORY_FLAG", typeof(bool));
            dt.Columns.Add("KRL_SINGULARISED_FLAG", typeof(bool));

            Keyword_Release_ADO adoKeywordCreate = new Keyword_Release_ADO();

            //Get the matrices for the RlsCode - There may be more than one e.g. if multiple languages are used in the same release
            Matrix_ADO mAdo = new Matrix_ADO(Ado);
            IList<dynamic> matrixList;

            matrixList = mAdo.ReadAllForRelease(latestRelease.RlsCode, userName);

            //Create the table rows
            foreach (dynamic item in matrixList)
            {
                //Get a Keyword Extractor - the particular version returned will depend on the language
                Keyword_BSO_Extract kbe = new Keyword_BSO_Extract(item.LngIsoCode);
                // IKeywordExtractor ext = kbe.GetExtractor();

                //Add the keywords and other data to the output table
                AddToTable(ref dt, kbe.ExtractSplitSingular(item.MtrTitle), item.RlsID);

                //Add the MtrCode to the keyword list without any transformations
                AddToTable(ref dt, new List<string>() { item.MtrCode }, item.RlsID, false);

                //Add the Copyright Code
                AddToTable(ref dt, kbe.ExtractSplit(item.CprCode), item.RlsID, false);

                //Add the Copyright Value
                AddToTable(ref dt, kbe.ExtractSplit(item.CprValue), item.RlsID, false);

                //Add the Language
                AddToTable(ref dt, kbe.ExtractSplit(item.LngIsoName), item.RlsID, false);

                //Add the Frequency Code
                //AddToTable(ref dt, ext.ExtractSplit(item.FrqCode), item.RlsID);

                //Add the Frequency Value
                AddToTable(ref dt, kbe.ExtractSplitSingular(item.FrqValue), item.RlsID);

                //Get the keywords from Statistic
                IList<dynamic> statList = mAdo.ReadStatisticByRelease(latestRelease.RlsCode, item.LngIsoCode);
                foreach (dynamic statItem in statList)
                {
                    AddToTable(ref dt, kbe.ExtractSplit(statItem.SttCode), item.RlsID, false);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(statItem.SttValue), item.RlsID);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(statItem.SttUnit), item.RlsID);
                }

                //Get the keywords from Classification
                IList<dynamic> classificationList = mAdo.ReadClassificationByRelease(latestRelease.RlsCode, item.LngIsoCode);
                foreach (dynamic classItem in classificationList)
                {
                    AddToTable(ref dt, kbe.ExtractSplit(classItem.ClsCode), item.RlsID, false);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(classItem.ClsValue), item.RlsID);

                    //Get the keywords from Variables
                    IList<dynamic> variableList = mAdo.ReadVariableByRelease(latestRelease.RlsCode, item.LngIsoCode, classItem.ClsCode);
                    foreach (dynamic variableItem in variableList)
                    {
                        AddToTable(ref dt, kbe.ExtractSplit(variableItem.VrbCode), item.RlsID, false);
                        AddToTable(ref dt, kbe.ExtractSplitSingular(variableItem.VrbValue), item.RlsID);
                    }
                }

                //Get the keywords from Period
                IList<dynamic> periodList = mAdo.ReadPeriodByRelease(latestRelease.RlsCode, item.LngIsoCode, item.FrqCode);
                foreach (dynamic periodItem in periodList)
                {
                    AddToTable(ref dt, kbe.ExtractSplit(periodItem.PrdCode), item.RlsID, false);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(periodItem.PrdValue), item.RlsID);
                }

            }
            //Final check to make sure there are no duplicates
            adoKeywordCreate.Create(Ado, dt.DefaultView.ToTable(true, new string[4] { "KRL_VALUE", "KRL_RLS_ID", "KRL_MANDATORY_FLAG", "KRL_SINGULARISED_FLAG" }));
        }
        internal void Create(ADO Ado, int releaseId, string userName, Matrix matrix)
        {
            Release_ADO rAdo = new Data.Release_ADO(Ado);

            var latestRelease = Release_ADO.GetReleaseDTO(rAdo.ReadID(releaseId, userName));

            if (latestRelease == null)
            {
                return;
            }


            //Create the table that will be bulk inserted
            DataTable dt = new DataTable();

            dt.Columns.Add("KRL_VALUE", typeof(string));
            dt.Columns.Add("KRL_RLS_ID", typeof(int));
            dt.Columns.Add("KRL_MANDATORY_FLAG", typeof(bool));
            dt.Columns.Add("KRL_SINGULARISED_FLAG", typeof(bool));

            Keyword_Release_ADO adoKeywordCreate = new Keyword_Release_ADO();



            List <Matrix.Specification> specList = new List <Matrix.Specification>()
            {
                matrix.MainSpec
            };

            if (matrix.OtherLanguageSpec != null)
            {
                foreach (Matrix.Specification lspec in matrix.OtherLanguageSpec)
                {
                    specList.Add(lspec);
                }
            }

            //Create the table rows
            foreach (var spec in specList)
            {
                //spec = matrix.GetSpecFromLanguage(item.LngIsoCode);
                //Get a Keyword Extractor - the particular version returned will depend on the language
                Keyword_BSO_Extract kbe = new Keyword_BSO_Extract(spec.Language);


                //Add the keywords and other data to the output table
                AddToTable(ref dt, kbe.ExtractSplitSingular(spec.Title), releaseId);

                //Add the MtrCode to the keyword list without any transformations
                AddToTable(ref dt, new List <string>()
                {
                    spec.MatrixCode
                }, releaseId, false);

                //Add the Copyright Code
                AddToTable(ref dt, kbe.ExtractSplit(matrix.Copyright.CprCode, false), releaseId, false);

                //Add the Copyright Value
                AddToTable(ref dt, kbe.ExtractSplit(matrix.Copyright.CprValue), releaseId, false);

                //Add the Language
                //AddToTable(ref dt, kbe.ExtractSplit(item.LngIsoName), item.RlsID, false);

                //Add the Frequency Code
                AddToTable(ref dt, kbe.ExtractSplit(spec.Frequency.Code, false), releaseId);

                //Add the Frequency Value
                AddToTable(ref dt, kbe.ExtractSplitSingular(spec.Frequency.Value), releaseId);

                //Get the keywords from Statistic
                foreach (dynamic statItem in spec.Statistic)
                {
                    AddToTable(ref dt, kbe.ExtractSplit(statItem.Code, false), releaseId, false);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(statItem.Value), releaseId);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(statItem.Unit), releaseId);
                }



                //Get the keywords from Classification
                foreach (dynamic classItem in spec.Classification)
                {
                    AddToTable(ref dt, kbe.ExtractSplit(classItem.Code, false), releaseId, false);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(classItem.Value), releaseId);

                    //Get the keywords from Variables

                    foreach (dynamic variableItem in classItem.Variable)
                    {
                        AddToTable(ref dt, kbe.ExtractSplit(variableItem.Code, false), releaseId, false);
                        AddToTable(ref dt, kbe.ExtractSplitSingular(variableItem.Value), releaseId);
                    }
                }

                //Get the keywords from Period
                foreach (dynamic periodItem in spec.Frequency.Period)
                {
                    AddToTable(ref dt, kbe.ExtractSplit(periodItem.Code, false), releaseId, false);
                    AddToTable(ref dt, kbe.ExtractSplitSingular(periodItem.Value), releaseId);
                }
            }
            var distinctRows = dt.DefaultView.ToTable(true, new string[4] {
                "KRL_VALUE", "KRL_RLS_ID", "KRL_MANDATORY_FLAG", "KRL_SINGULARISED_FLAG"
            });

            //Final check to make sure there are no duplicates
            adoKeywordCreate.Create(Ado, distinctRows);
        }
Esempio n. 3
0
        /// <summary>
        /// Search method
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        internal dynamic Search(Navigation_DTO_Search dto)
        {
            //Get a keyword extractor. The keyword extractor should, if possible, correspond to the supplied LngIsoCode
            //If an extractor is not found for the supplied LngIsoCode then a basic default extractor is supplied.
            Keyword_BSO_Extract kbe = new Keyword_BSO_Extract(dto.LngIsoCode);
            //  IKeywordExtractor extractor = kbe.GetExtractor();

            //Get a list of keywords based on the supplied search term
            List <string> searchList          = new List <string>();
            List <string> searchListInvariant = new List <string>();
            int           searchTermCount     = 0;

            if (dto.Search != null)
            {
                //Get a singularised version of each word
                searchList = kbe.ExtractSplitSingular(dto.Search);
                //We need a count of search terms (ignoring duplicates caused by singularisation)
                searchTermCount = searchList.Count;
                //Some words will not be searched for in their singular form (flagged on the table), so we need those as well
                searchListInvariant = kbe.ExtractSplit(dto.Search);
                //Eliminate duplicates from the list
                searchList = searchList.Union(searchListInvariant).ToList();
            }



            //The list of keywords must be supplied to the search stored procedure
            //In order to do this,  we pass a datatable as a parameter
            //First we create the table
            DataTable dt = new DataTable();

            dt.Columns.Add("Key");
            dt.Columns.Add("Value");
            dt.Columns.Add("Attribute");



            //Gather any synonyms and include them in the search, in the synonyms column
            foreach (string word in searchList)
            {
                var hitlist = kbe.extractor.SynonymList.Where(x => x.match == word.ToLower());
                if ((kbe.extractor.SynonymList.Where(x => x.match == word.ToLower())).Count() > 0)
                {
                    foreach (var syn in hitlist)
                    {
                        var row = dt.NewRow();
                        row["Key"]       = syn.lemma;
                        row["Value"]     = syn.match;
                        row["Attribute"] = Configuration_BSO.GetCustomConfig("search.synonym-multiplier");
                        dt.Rows.Add(row);
                    }
                }
                else
                {
                    var row = dt.NewRow();
                    row["Key"]       = word;
                    row["Value"]     = word;
                    row["Attribute"] = Configuration_BSO.GetCustomConfig("search.synonym-multiplier");
                    dt.Rows.Add(row);
                }
                //The main search term must be included along with the synonyms, i.e. a word is a synonym of itself
                //But with a higher search priority, which goes into the Attribute column
                var keyrow = dt.NewRow();
                if (dt.Select("Key = '" + word + "'").Count() == 0)
                {
                    keyrow["Key"]       = word;
                    keyrow["Value"]     = word;
                    keyrow["Attribute"] = Configuration_BSO.GetCustomConfig("search.search-word-multiplier");
                    dt.Rows.Add(keyrow);
                }
            }


            //Sort the search terms to ensure invariant word order in the search
            dt.DefaultView.Sort = "Key,Value asc";
            dt = dt.DefaultView.ToTable();


            //The ExecuteReaderProcedure method requires that the parameters be contained in a List<ADO_inputParams>
            List <ADO_inputParams> paramList = new List <ADO_inputParams>()
            {
                new ADO_inputParams()
                {
                    name = "@LngIsoCode", value = dto.LngIsoCode
                }
            };

            ADO_inputParams param = new ADO_inputParams()
            {
                name = "@Search", value = dt
            };

            param.typeName = "KeyValueVarcharAttribute";
            paramList.Add(param);
            //We need a count of search terms (ignoring duplicates caused by singularisation)
            paramList.Add(new ADO_inputParams()
            {
                name = "@SearchTermCount", value = searchTermCount
            });

            if (dto.MtrCode != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@MtrCode", value = dto.MtrCode
                });
            }
            if (dto.MtrOfficialFlag != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@MtrOfficialFlag", value = dto.MtrOfficialFlag
                });
            }
            if (dto.SbjCode != default(int))
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@SbjCode", value = dto.SbjCode
                });
            }
            if (dto.PrcCode != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@PrcCode", value = dto.PrcCode
                });
            }
            if (dto.CprCode != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@CprCode", value = dto.CprCode
                });
            }
            if (dto.RlsExceptionalFlag != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@RlsExceptionalFlag", value = dto.RlsExceptionalFlag
                });
            }
            if (dto.RlsReservationFlag != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@RlsReservationFlag", value = dto.RlsReservationFlag
                });
            }
            if (dto.RlsArchiveFlag != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@RlsArchiveFlag", value = dto.RlsArchiveFlag
                });
            }
            if (dto.RlsAnalyticalFlag != null)
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@RlsAnalyticalFlag", value = dto.RlsAnalyticalFlag
                });
            }



            //We store from the ADO because the search terms may have been changed by keyword rules
            MemCachedD_Value cache = MemCacheD.Get_ADO("PxStat.System.Navigation", "System_Navigation_Search", paramList); //

            if (cache.hasData)
            {
                return(cache.data.ToObject <List <dynamic> >());
            }



            //Call the stored procedure
            ADO_readerOutput output = ado.ExecuteReaderProcedure("System_Navigation_Search", paramList);

            MemCacheD.Store_ADO <dynamic>("PxStat.System.Navigation", "System_Navigation_Search", paramList, output.data, new DateTime(), Resources.Constants.C_CAS_NAVIGATION_SEARCH);
            //return the list of entities that have been found
            return(output.data);
        }
Esempio n. 4
0
        /// <summary>
        /// Modify the search terms as a table of keywords
        /// </summary>
        /// <returns></returns>
        internal DataTable PrepareSearchData()
        {
            //Get a keyword extractor. The keyword extractor should, if possible, correspond to the supplied LngIsoCode
            //If an extractor is not found for the supplied LngIsoCode then a basic default extractor is supplied.
            Keyword_BSO_Extract kbe = new Keyword_BSO_Extract(DTO.LngIsoCode);
            //  IKeywordExtractor extractor = kbe.GetExtractor();

            //Get a list of keywords based on the supplied search term
            List <string> searchList          = new List <string>();
            List <string> searchListInvariant = new List <string>();


            if (DTO.Search != null)
            {
                //Get a singularised version of each word
                searchList = kbe.ExtractSplitSingular(DTO.Search);
                //We need a count of search terms (ignoring duplicates caused by singularisation)
                searchTermCount = searchList.Count;
                //Some words will not be searched for in their singular form (flagged on the table), so we need those as well
                searchListInvariant = kbe.ExtractSplit(DTO.Search);
                //Eliminate duplicates from the list
                searchList = searchList.Union(searchListInvariant).ToList();
            }



            //The list of keywords must be supplied to the search stored procedure
            //In order to do this,  we pass a datatable as a parameter
            //First we create the table
            DataTable dt = new DataTable();

            dt.Columns.Add("Key");
            dt.Columns.Add("Value");
            dt.Columns.Add("Attribute");

            int searchSynonymMult = Configuration_BSO.GetCustomConfig(ConfigType.server, "search.synonym-multiplier");
            int searchWordMult    = Configuration_BSO.GetCustomConfig(ConfigType.server, "search.search-word-multiplier");

            //Gather any synonyms and include them in the search, in the synonyms column
            foreach (string word in searchList)
            {
                var hitlist = kbe.extractor.SynonymList.Where(x => x.match == word.ToLower());
                if ((kbe.extractor.SynonymList.Where(x => x.match == word.ToLower())).Count() > 0)
                {
                    foreach (var syn in hitlist)
                    {
                        var row = dt.NewRow();
                        row["Key"]       = syn.lemma;
                        row["Value"]     = syn.match;
                        row["Attribute"] = searchSynonymMult;
                        dt.Rows.Add(row);
                    }
                }
                else
                {
                    var row = dt.NewRow();
                    row["Key"]       = word;
                    row["Value"]     = word;
                    row["Attribute"] = searchSynonymMult;
                    dt.Rows.Add(row);
                }
                //The main search term must be included along with the synonyms, i.e. a word is a synonym of itself
                //But with a higher search priority, which goes into the Attribute column
                var keyrow = dt.NewRow();
                if (dt.Select("Key = '" + word + "'").Count() == 0)
                {
                    keyrow["Key"]       = word;
                    keyrow["Value"]     = word;
                    keyrow["Attribute"] = searchWordMult;
                    dt.Rows.Add(keyrow);
                }
            }


            //Sort the search terms to ensure invariant word order in the search
            dt.DefaultView.Sort = "Key,Value asc";
            dt = dt.DefaultView.ToTable();

            return(dt);
        }