コード例 #1
0
ファイル: QueryBucket.cs プロジェクト: AliHosny/weet-it
        /// <summary>
        /// gets the permutations based on the "_" and ""
        /// </summary>
        /// <param name="questionLeft">the input questionLeft</param>
        /// <returns>returnning the list of customObject</returns>
        public List<customMatchObject> getPermutations(string questionLeft)
        {
            //Trimming the string
            questionLeft = questionLeft.Trim();

            //Removing Extra spaces
            while (questionLeft.Contains("  "))
                questionLeft = questionLeft.Replace("  ", " ");

            //Creating the new list of objects that would be returned
            List<customMatchObject> listObject = new List<customMatchObject>();

            //The list of string that holds all permutations of the input string
            List<string> toReturn = new List<string>();

            //parsing the input string
            List<string> input = new List<string>();
            input = questionLeft.Split(' ').ToList<string>();

            //holds the temporary constructed string
            string temp = "";
            string temponeWord = "";
            string tempUScore = "";

            //list holds the words used to generate a certain permutation
            List<string> wordsUsed = new List<string>();

            //The core algorithm to generate permutations
            for (int j = 1; j <= input.Count; j++)//Size of word
            {
                for (int k = 0; k < (input.Count - (j - 1)); k++) //offset
                {
                    for (int l = k; l < (j + k); l++)
                    {
                        temp += input[l] + " ";
                        temponeWord += input[l];
                        tempUScore += input[l] + "_";
                        wordsUsed.Add(input[l]);
                    }

                    //add the generated strigns to the list and return it
                    customMatchObject tempobj1 = new customMatchObject();
                    tempobj1.wordsUsed = wordsUsed.Distinct().ToList<string>(); ;
                    tempobj1.word = temp.Remove(temp.Length - 1);
                    tempobj1.separator = " ";
                    listObject.Add(tempobj1);

                    customMatchObject tempobj2 = new customMatchObject();
                    tempobj2.wordsUsed = wordsUsed.Distinct().ToList<string>(); ;
                    tempobj2.word = temponeWord;
                    tempobj2.separator = "";
                    listObject.Add(tempobj2);

                    customMatchObject tempobj3 = new customMatchObject();
                    tempobj3.wordsUsed = wordsUsed.Distinct().ToList<string>();
                    tempobj3.word = tempUScore.Remove(temp.Length - 1);
                    tempobj3.separator = "_";
                    listObject.Add(tempobj3);

                    //resetting the variables again
                    temp = "";
                    tempUScore = "";
                    temponeWord = "";
                    wordsUsed = new List<string>();
                }
            }

            return listObject;
        }
コード例 #2
0
        ///// <summary>
        ///// Builds the sparql query for this bucket
        ///// </summary>
        ///// <returns>string of this bucket's query</returns>
        //public void GetQuery()
        //{

        //    string literalQuery = "";
        //    string predicateQuery = "";
        //    string query;

        //    /*
        //     *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! postponed till discussing rating part
        //     *
        //     //reset rating
        //     if (tokens.Count == 0)
        //         rating[0] = 0; //set low rating for empty bucket
        //     else
        //         rating[0] = 10000; //most of the rating changes decrease the rating.
        //     */

        //    foreach (LexiconToken value in tokens)
        //    {
        //        LexiconToken tmpToken = value;
        //        //string tmpWordsUsed = (string)value[1];

        //        if (tmpToken is LexiconLiteral)/*check if type LexiconLiteral*/
        //        {
        //            if ((literalQuery.Length > 0) && (literalQuery != null))
        //                literalQuery = literalQuery + " . ";
        //            literalQuery = literalQuery + tmpToken.BuildQueryPart();/*LexconToken method*/
        //        }
        //        else
        //        {
        //            if (predicateQuery.Length > 0)
        //                predicateQuery = predicateQuery + " . ";
        //            predicateQuery = predicateQuery + tmpToken.BuildQueryPart();	/*LexconToken method*/
        //        }
        //        /*
        //         * Postponed till discussing rating
        //         *
        //         *
        //        double r = rating[0] * 0.9;
        //        rating[0] = new Long(Math.round(r)).intValue();
        //         * */
        //    }

        //    query = predicateQuery;

        //    if ((literalQuery.Length > 0) && (predicateQuery.Length > 0))
        //        query = query + " . ";
        //    query = query + literalQuery;

        //    query = "select distinct *" +
        //    " WHERE { " +
        //        query +
        //        " }";

        //    //set query string of the bucket to the built query
        //    this.query = query;
        //}



        #region helper_methods
        /// <summary>
        /// gets the permutations based on the "_" and ""
        /// </summary>
        /// <param name="questionLeft">the input questionLeft</param>
        /// <returns>returnning the list of customObject</returns>
        public List <customMatchObject> getPermutations(string questionLeft)
        {
            //Trimming the string
            questionLeft = questionLeft.Trim();

            //Removing Extra spaces
            while (questionLeft.Contains("  "))
            {
                questionLeft = questionLeft.Replace("  ", " ");
            }

            //Creating the new list of objects that would be returned
            List <customMatchObject> listObject = new List <customMatchObject>();

            //The list of string that holds all permutations of the input string
            List <string> toReturn = new List <string>();

            //parsing the input string
            List <string> input = new List <string>();

            input = questionLeft.Split(' ').ToList <string>();

            //holds the temporary constructed string
            string temp        = "";
            string temponeWord = "";
            string tempUScore  = "";

            //list holds the words used to generate a certain permutation
            List <string> wordsUsed = new List <string>();

            //The core algorithm to generate permutations
            for (int j = 1; j <= input.Count; j++)                //Size of word
            {
                for (int k = 0; k < (input.Count - (j - 1)); k++) //offset
                {
                    for (int l = k; l < (j + k); l++)
                    {
                        temp        += input[l] + " ";
                        temponeWord += input[l];
                        tempUScore  += input[l] + "_";
                        wordsUsed.Add(input[l]);
                    }

                    //add the generated strigns to the list and return it
                    customMatchObject tempobj1 = new customMatchObject();
                    tempobj1.wordsUsed = wordsUsed.Distinct().ToList <string>();;
                    tempobj1.word      = temp.Remove(temp.Length - 1);
                    tempobj1.separator = " ";
                    listObject.Add(tempobj1);

                    customMatchObject tempobj2 = new customMatchObject();
                    tempobj2.wordsUsed = wordsUsed.Distinct().ToList <string>();;
                    tempobj2.word      = temponeWord;
                    tempobj2.separator = "";
                    listObject.Add(tempobj2);

                    customMatchObject tempobj3 = new customMatchObject();
                    tempobj3.wordsUsed = wordsUsed.Distinct().ToList <string>();
                    tempobj3.word      = tempUScore.Remove(temp.Length - 1);
                    tempobj3.separator = "_";
                    listObject.Add(tempobj3);

                    //resetting the variables again
                    temp        = "";
                    tempUScore  = "";
                    temponeWord = "";
                    wordsUsed   = new List <string>();
                }
            }


            return(listObject);
        }