コード例 #1
0
        /// <summary>
        /// Creates the new word.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="word">The word.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="isDefault">if set to <c>true</c> [is default].</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public IWord CreateNewWord(int id, string word, Side side, WordType type, bool isDefault)
        {
            if (word != null)
            {
                SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                cmd.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                cmd.Parameters.Add("@id", id);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());

                int    currentPos = 0;
                object retval     = MSSQLCEConn.ExecuteScalar(cmd);
                if (retval != DBNull.Value)
                {
                    currentPos = Convert.ToInt32(retval);
                }
                cmd.Parameters.Clear();

                cmd.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                cmd.Parameters.Add("@id", id);
                cmd.Parameters.Add("@text", word);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@position", currentPos + 10);
                cmd.Parameters.Add("@isdefault", isDefault);

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));

                return(new DbWord(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)), word, type, isDefault, Parent));
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: Word.cs プロジェクト: jem-green/Gcode
        public override string ToString()
        {
            StringBuilder word = new StringBuilder(_word.ToString());

            word.Append(_value);
            return(word.ToString());
        }
コード例 #3
0
        public IWord CreateNewWord(int id, string word, Side side, WordType type, bool isDefault)
        {
            if (word != null)
            {
                using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
                {
                    using (NpgsqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "INSERT INTO \"TextContent\" (cards_id, text, side, type, position, is_default) VALUES (:id, :text, :side, :type, " +
                                          "(COALESCE((SELECT position FROM \"TextContent\" WHERE cards_id=:id AND side=:side AND type=:type ORDER BY position DESC LIMIT 1), 0) + 10), " +
                                          ":isdefault) RETURNING id";
                        cmd.Parameters.Add("id", id);
                        cmd.Parameters.Add("text", word);
                        cmd.Parameters.Add("side", side.ToString());
                        cmd.Parameters.Add("type", type.ToString());
                        cmd.Parameters.Add("isdefault", isDefault);

                        Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));

                        return(new DbWord(Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser)), word, type, isDefault, Parent));
                    }
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public static string ToLongString(this WordType type)
        {
            if (mapping.TryGetValue(type, out var value))
            {
                return(value);
            }

            return(type.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Clears all words.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public void ClearAllWords(int id, Side side, WordType type)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

            cmd.CommandText = "DELETE FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type";
            cmd.Parameters.Add("@id", id);
            cmd.Parameters.Add("@side", side.ToString());
            cmd.Parameters.Add("@type", type.ToString());
            MSSQLCEConn.ExecuteNonQuery(cmd);

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
        }
コード例 #6
0
ファイル: Conjugator.cs プロジェクト: thedoor2009/Gojuon
    public string Conjugate(string input, ConjugationMode mode, WordType destWordType)
    {
        MethodInfo mi = GetType().GetMethod("Conjugate_" + mode.ToString() + "_" + destWordType.ToString(), BindingFlags.NonPublic | BindingFlags.Instance);
        if (mi != null)
        {
            if (mi.GetParameters().Length != 1 || mi.ReturnType != typeof(string))
            {
                Debug.LogError("Conjugation Handler does not match expected signature: " + "Conjugate_" + mode.ToString() + "_" + destWordType.ToString());
                return "Error";
            }

            string result = mi.Invoke(this, new object[] {input} ) as string;
            return result;
        }
        else
        {
            Debug.LogError("No Conjugation Handler: " + "Conjugate_" + mode.ToString() + "_" + destWordType.ToString());
            Debug.LogWarning("The conjugation might not be defined for the given WordType. Better handling of these cases will come later");
            return "Error";
        }
    }
コード例 #7
0
        /// <summary>
        /// Adds the word.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="word">The word.</param>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public void AddWord(int id, Side side, WordType type, IWord word)
        {
            if (word != null && word.Word.Length > 0)
            {
                SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                cmd.CommandText = "SELECT count(*) FROM TextContent WHERE id = @wordid AND text = @word AND type = @type AND is_default = @isdefault;";
                cmd.Parameters.Add("@wordid", word.Id);
                cmd.Parameters.Add("@word", word.Word);
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@isdefault", word.Default);
                bool wordExists = (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) > 0);
                if (!wordExists)
                {
                    cmd.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                    cmd.Parameters.Add("@id", id);
                    cmd.Parameters.Add("@side", side.ToString());
                    cmd.Parameters.Add("@type", type.ToString());

                    int    currentPos = 0;
                    object retval     = MSSQLCEConn.ExecuteScalar(cmd);
                    if (retval != DBNull.Value)
                    {
                        currentPos = Convert.ToInt32(retval);
                    }
                    cmd.Parameters.Clear();

                    cmd.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                    cmd.Parameters.Add("@id", id);
                    cmd.Parameters.Add("@text", word.Word);
                    cmd.Parameters.Add("@side", side.ToString());
                    cmd.Parameters.Add("@type", type.ToString());
                    cmd.Parameters.Add("@position", currentPos + 10);
                    cmd.Parameters.Add("@isdefault", word.Default);
                    MSSQLCEConn.ExecuteNonQuery(cmd);
                }

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
            }
        }
コード例 #8
0
        /// <summary>
        /// 将单词添加到单词本
        /// </summary>
        /// <param name="name"></param>
        /// <param name="word"></param>
        /// <param name="type"></param>
        public static void AddWord(string name, string word, WordType type)
        {
            string      path = AppInfoHelper.GetMyWordBookFolder() + "\\" + name + ".xml";
            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(path);
            XmlElement root = xdoc.DocumentElement;
            XmlElement node = xdoc.CreateElement("item");

            node.InnerText = word;
            node.SetAttribute("wordtype", type.ToString());
            xdoc.Save(path);
        }
コード例 #9
0
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=@cardid AND side=@side AND type=@type " +
                                  "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=@mediatype);";
                cmd.Parameters.Add("@cardid", cardid);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@mediatype", mediatype.ToString());
                cmd.ExecuteNonQuery();
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
コード例 #10
0
        public void ClearAllWords(int id, Side side, WordType type)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM \"TextContent\" WHERE cards_id=:id AND side=:side AND type=:type";
                    cmd.Parameters.Add("id", id);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);

                    Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
                }
            }
        }
コード例 #11
0
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=:cardid AND side=:side AND type=:type " +
                                      "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=:mediatype);";
                    cmd.Parameters.Add("cardid", cardid);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    cmd.Parameters.Add("mediatype", mediatype.ToString());
                    cmd.ExecuteNonQuery();
                }
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
コード例 #12
0
        /// <summary>
        /// Get text description in a short form.
        /// </summary>
        /// <param name="type">Type of the word.</param>
        /// <returns>Text description in a short form.</returns>
        public static string ToShortFormString(this WordType type)
        {
            switch (type)
            {
            case WordType.Unknown: return("-");

            case WordType.Noun: return("сущ");

            case WordType.Adjective: return("прил");

            case WordType.Adverb: return("нар");

            case WordType.Verb: return("гл");

            case WordType.Preposition: return("предл");

            default: return(type.ToString());
            }
        }
コード例 #13
0
        public void AddWord(int id, Side side, WordType type, IWord word)
        {
            if (word != null && word.Word.Length > 0)
            {
                using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
                {
                    using (NpgsqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "SELECT \"InsertWordIfNotExists\"(:id,:cardid,:isdefault,:text,:side,:type);";
                        cmd.Parameters.Add("id", word.Id);
                        cmd.Parameters.Add("isdefault", word.Default);
                        cmd.Parameters.Add("cardid", id);
                        cmd.Parameters.Add("text", word.Word);
                        cmd.Parameters.Add("side", side.ToString());
                        cmd.Parameters.Add("type", type.ToString());
                        PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);

                        Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
                    }
                }
            }
        }
コード例 #14
0
        public void AddWords(int id, Side side, WordType type, List <IWord> words)
        {
            if (words.Count > 0)
            {
                using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
                {
                    using (NpgsqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = string.Empty;
                        int    paramnum = 0;
                        string textparamname, idparametername, isdefaultparametername;
                        foreach (IWord word in words)
                        {
                            if (word != null && word.Word.Length > 0)
                            {
                                paramnum++;
                                textparamname          = string.Format("text{0}", paramnum);
                                idparametername        = string.Format("id{0}", paramnum);
                                isdefaultparametername = string.Format("isdefault{0}", paramnum);

                                cmd.CommandText += string.Format("SELECT \"InsertWordIfNotExists\"(:{0},:cardid,:{1},:{2},:side,:type);",
                                                                 idparametername, isdefaultparametername, textparamname);

                                cmd.Parameters.Add(textparamname, word.Word);
                                cmd.Parameters.Add(idparametername, word.Id);
                                cmd.Parameters.Add(isdefaultparametername, word.Default);
                            }
                        }

                        cmd.Parameters.Add("cardid", id);
                        cmd.Parameters.Add("side", side.ToString());
                        cmd.Parameters.Add("type", type.ToString());
                        PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);

                        Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
                    }
                }
            }
        }
コード例 #15
0
        public void AddWord(int id, Side side, WordType type, IWord word)
        {
            if (word != null && word.Word.Length > 0)
            {
                using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
                {
                    using (NpgsqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "SELECT \"InsertWordIfNotExists\"(:id,:cardid,:isdefault,:text,:side,:type);";
                        cmd.Parameters.Add("id", word.Id);
                        cmd.Parameters.Add("isdefault", word.Default);
                        cmd.Parameters.Add("cardid", id);
                        cmd.Parameters.Add("text", word.Word);
                        cmd.Parameters.Add("side", side.ToString());
                        cmd.Parameters.Add("type", type.ToString());
                        PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);

                        Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
                    }
                }
            }
        }
コード例 #16
0
        public void SetCardMedia(int id, int cardid, Side side, WordType type, bool isDefault, EMedia mediatype)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = con.BeginTransaction();
                ClearCardMedia(cardid, side, type, mediatype);

                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"Cards_MediaContent\" (media_id, cards_id, side, type, is_default) VALUES (:mediaid, :cardid, :side, :type, :isdefault);";
                    cmd.Parameters.Add("mediaid", id);
                    cmd.Parameters.Add("cardid", cardid);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    cmd.Parameters.Add("isdefault", isDefault);
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);
                }

                tran.Commit();

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
            }
        }
コード例 #17
0
        public static void printObservationMatrix(Dictionary <ObservationFromState, double> model, List <string> myDictionary)
        {
            WordType[] types = (WordType[])Enum.GetValues(typeof(WordType));

            ObservationFromState obsv = new ObservationFromState("", WordType.Undefined);

            StringBuilder output = new StringBuilder();

            //Header
            output.Append("...,");
            for (int n = 0; n < myDictionary.Count; n++)
            {
                output.Append(myDictionary[n].escape() + ",");
            }
            output.AppendLine();



            for (int row = 0; row < types.Length; row++)
            {
                WordType from = types[row];
                obsv.state = from;
                output.Append(from.ToString() + ",");
                for (int col = 0; col < myDictionary.Count; col++)
                {
                    obsv.observation = myDictionary[col];
                    if (model.ContainsKey(obsv))
                    {
                        output.Append(model[obsv]);
                    }
                    output.Append(",");
                }

                output.AppendLine();
            }
            System.IO.File.WriteAllText("observer.csv", output.ToString());
        }
コード例 #18
0
        public void SetCardMedia(int id, int cardid, Side side, WordType type, bool isDefault, EMedia mediatype)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = con.BeginTransaction();
                ClearCardMedia(cardid, side, type, mediatype);

                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"Cards_MediaContent\" (media_id, cards_id, side, type, is_default) VALUES (:mediaid, :cardid, :side, :type, :isdefault);";
                    cmd.Parameters.Add("mediaid", id);
                    cmd.Parameters.Add("cardid", cardid);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    cmd.Parameters.Add("isdefault", isDefault);
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);
                }

                tran.Commit();

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
            }
        }
コード例 #19
0
        /// <summary>
        /// Creates the new word.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="word">The word.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="isDefault">if set to <c>true</c> [is default].</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public IWord CreateNewWord(int id, string word, Side side, WordType type, bool isDefault)
        {
            if (word != null)
            {
                SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                cmd.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                cmd.Parameters.Add("@id", id);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());

                int currentPos = 0;
                object retval = MSSQLCEConn.ExecuteScalar(cmd);
                if (retval != DBNull.Value)
                    currentPos = Convert.ToInt32(retval);
                cmd.Parameters.Clear();

                cmd.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                cmd.Parameters.Add("@id", id);
                cmd.Parameters.Add("@text", word);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@position", currentPos + 10);
                cmd.Parameters.Add("@isdefault", isDefault);

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));

                return new DbWord(Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)), word, type, isDefault, Parent);
            }
            else
                return null;
        }
コード例 #20
0
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser))
            {
                cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=@cardid AND side=@side AND type=@type " +
                    "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=@mediatype);";
                cmd.Parameters.Add("@cardid", cardid);
                cmd.Parameters.Add("@side", side.ToString());
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@mediatype", mediatype.ToString());
                cmd.ExecuteNonQuery();
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
コード例 #21
0
        public void ClearCardMedia(int cardid, Side side, WordType type, EMedia mediatype)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM \"Cards_MediaContent\" WHERE cards_id=:cardid AND side=:side AND type=:type " +
                        "AND media_id IN (SELECT id FROM \"MediaContent\" WHERE media_type=:mediatype);";
                    cmd.Parameters.Add("cardid", cardid);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    cmd.Parameters.Add("mediatype", mediatype.ToString());
                    cmd.ExecuteNonQuery();
                }
            }

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid));
        }
コード例 #22
0
 public override string ToString()
 {
     return(from.ToString() + " -> " + to.ToString());
 }
コード例 #23
0
        /// <summary>
        /// Adds the words.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="words">The words.</param>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        /// <remarks>Documented by Dev08, 2009-01-19</remarks>
        public void AddWords(int id, Side side, WordType type, List <IWord> words)
        {
            if (words.Count > 0)
            {
                //SqlCeCommand cmd1 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                //SqlCeCommand cmd2 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                //SqlCeCommand cmd3 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

                //SqlCeParameter paramWordId = new SqlCeParameter("@id", SqlDbType.Int);
                //SqlCeParameter paramCardId = new SqlCeParameter("@cardid", SqlDbType.Int);
                //SqlCeParameter paramType = new SqlCeParameter("@type", SqlDbType.NVarChar);
                //SqlCeParameter paramIsDefault = new SqlCeParameter("@isdefault", SqlDbType.Bit);
                //cmd1.CommandText = "SELECT count(*) FROM TextContent WHERE id = @wordid AND text = @word AND type = @type AND is_default = @isdefault;";
                //cmd1.Parameters.Add(paramWordId);
                //cmd1.Parameters.Add(paramCardId);
                //cmd1.Parameters.Add(paramType);
                //cmd1.Parameters.Add(paramIsDefault);

                //SqlCeParameter paramSide = new SqlCeParameter("@side", SqlDbType.NVarChar);
                //cmd2.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                //cmd2.Parameters.Add(paramWordId);
                //cmd2.Parameters.Add(paramSide);
                //cmd2.Parameters.Add(paramType);

                //SqlCeParameter paramText = new SqlCeParameter("@text", SqlDbType.NText);
                //SqlCeParameter paramPosition = new SqlCeParameter("@position", SqlDbType.Int);
                //cmd3.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @:side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                //cmd3.Parameters.Add(paramCardId);
                //cmd3.Parameters.Add(paramText);
                //cmd3.Parameters.Add(paramSide);
                //cmd3.Parameters.Add(paramType);
                //cmd3.Parameters.Add(paramPosition);
                //cmd3.Parameters.Add(paramIsDefault);

                foreach (IWord word in words)
                {
                    if (word != null && word.Word.Length > 0)
                    {
                        //paramCardId.Value = id;
                        //paramWordId.Value = word.Id;
                        //paramText.Value = word.Word;
                        //paramSide.Value = side.ToString();
                        //paramType.Value = type.ToString();
                        //paramIsDefault.Value = word.Default;

                        SqlCeCommand cmd1 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                        cmd1.CommandText = "SELECT count(*) FROM TextContent WHERE id = @wordid AND text = @word AND type = @type AND is_default = @isdefault;";
                        cmd1.Parameters.Add("@wordid", word.Id);
                        cmd1.Parameters.Add("@word", word.Word);
                        cmd1.Parameters.Add("@type", type.ToString());
                        cmd1.Parameters.Add("@isdefault", word.Default);

                        bool wordExists = (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd1)) > 0);
                        if (!wordExists)
                        {
                            int          currentPos = 0;
                            SqlCeCommand cmd2       = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                            cmd2.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                            cmd2.Parameters.Add("@id", id);
                            cmd2.Parameters.Add("@side", side.ToString());
                            cmd2.Parameters.Add("@type", type.ToString());

                            object retval = MSSQLCEConn.ExecuteScalar(cmd2);
                            if (retval != DBNull.Value)
                            {
                                currentPos = Convert.ToInt32(retval);
                            }

                            //paramPosition.Value = currentPos + 10;
                            SqlCeCommand cmd3 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                            cmd3.CommandText = "INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @word, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                            cmd3.Parameters.Add("@id", id);
                            cmd3.Parameters.Add("@word", word.Word);
                            cmd3.Parameters.Add("@side", side.ToString());
                            cmd3.Parameters.Add("@type", type.ToString());
                            cmd3.Parameters.Add("@position", currentPos + 10);
                            cmd3.Parameters.Add("@isdefault", word.Default);
                            MSSQLCEConn.ExecuteNonQuery(cmd3);
                        }
                    }
                }

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
            }
        }
コード例 #24
0
        public void RandomiseSentenceWithWordType_ShouldFindSuitableSentenceInDictionary(WordType wordType)
        {
            var result = imagination.RandomiseSentenceWithWordType(wordType);

            Assert.Contains("[" + wordType.ToString() + "]", result);
        }
コード例 #25
0
        /// <summary>
        /// Adds the words.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="words">The words.</param>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        /// <remarks>Documented by Dev08, 2009-01-19</remarks>
        public void AddWords(int id, Side side, WordType type, List<IWord> words)
        {
            if (words.Count > 0)
            {
                //SqlCeCommand cmd1 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                //SqlCeCommand cmd2 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                //SqlCeCommand cmd3 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);

                //SqlCeParameter paramWordId = new SqlCeParameter("@id", SqlDbType.Int);
                //SqlCeParameter paramCardId = new SqlCeParameter("@cardid", SqlDbType.Int);
                //SqlCeParameter paramType = new SqlCeParameter("@type", SqlDbType.NVarChar);
                //SqlCeParameter paramIsDefault = new SqlCeParameter("@isdefault", SqlDbType.Bit);
                //cmd1.CommandText = "SELECT count(*) FROM TextContent WHERE id = @wordid AND text = @word AND type = @type AND is_default = @isdefault;";
                //cmd1.Parameters.Add(paramWordId);
                //cmd1.Parameters.Add(paramCardId);
                //cmd1.Parameters.Add(paramType);
                //cmd1.Parameters.Add(paramIsDefault);

                //SqlCeParameter paramSide = new SqlCeParameter("@side", SqlDbType.NVarChar);
                //cmd2.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                //cmd2.Parameters.Add(paramWordId);
                //cmd2.Parameters.Add(paramSide);
                //cmd2.Parameters.Add(paramType);

                //SqlCeParameter paramText = new SqlCeParameter("@text", SqlDbType.NText);
                //SqlCeParameter paramPosition = new SqlCeParameter("@position", SqlDbType.Int);
                //cmd3.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @:side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                //cmd3.Parameters.Add(paramCardId);
                //cmd3.Parameters.Add(paramText);
                //cmd3.Parameters.Add(paramSide);
                //cmd3.Parameters.Add(paramType);
                //cmd3.Parameters.Add(paramPosition);
                //cmd3.Parameters.Add(paramIsDefault);

                foreach (IWord word in words)
                {
                    if (word != null && word.Word.Length > 0)
                    {
                        //paramCardId.Value = id;
                        //paramWordId.Value = word.Id;
                        //paramText.Value = word.Word;
                        //paramSide.Value = side.ToString();
                        //paramType.Value = type.ToString();
                        //paramIsDefault.Value = word.Default;

                        SqlCeCommand cmd1 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                        cmd1.CommandText = "SELECT count(*) FROM TextContent WHERE id = @wordid AND text = @word AND type = @type AND is_default = @isdefault;";
                        cmd1.Parameters.Add("@wordid", word.Id);
                        cmd1.Parameters.Add("@word", word.Word);
                        cmd1.Parameters.Add("@type", type.ToString());
                        cmd1.Parameters.Add("@isdefault", word.Default);

                        bool wordExists = (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd1)) > 0);
                        if (!wordExists)
                        {
                            int currentPos = 0;
                            SqlCeCommand cmd2 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                            cmd2.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                            cmd2.Parameters.Add("@id", id);
                            cmd2.Parameters.Add("@side", side.ToString());
                            cmd2.Parameters.Add("@type", type.ToString());

                            object retval = MSSQLCEConn.ExecuteScalar(cmd2);
                            if (retval != DBNull.Value)
                                currentPos = Convert.ToInt32(retval);

                            //paramPosition.Value = currentPos + 10;
                            SqlCeCommand cmd3 = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                            cmd3.CommandText = "INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @word, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                            cmd3.Parameters.Add("@id", id);
                            cmd3.Parameters.Add("@word", word.Word);
                            cmd3.Parameters.Add("@side", side.ToString());
                            cmd3.Parameters.Add("@type", type.ToString());
                            cmd3.Parameters.Add("@position", currentPos + 10);
                            cmd3.Parameters.Add("@isdefault", word.Default);
                            MSSQLCEConn.ExecuteNonQuery(cmd3);
                        }
                    }
                }

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
            }
        }
コード例 #26
0
        public void AddWords(int id, Side side, WordType type, List<IWord> words)
        {
            if (words.Count > 0)
            {
                using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
                {
                    using (NpgsqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = string.Empty;
                        int paramnum = 0;
                        string textparamname, idparametername, isdefaultparametername;
                        foreach (IWord word in words)
                        {
                            if (word != null && word.Word.Length > 0)
                            {
                                paramnum++;
                                textparamname = string.Format("text{0}", paramnum);
                                idparametername = string.Format("id{0}", paramnum);
                                isdefaultparametername = string.Format("isdefault{0}", paramnum);

                                cmd.CommandText += string.Format("SELECT \"InsertWordIfNotExists\"(:{0},:cardid,:{1},:{2},:side,:type);",
                                    idparametername, isdefaultparametername, textparamname);

                                cmd.Parameters.Add(textparamname, word.Word);
                                cmd.Parameters.Add(idparametername, word.Id);
                                cmd.Parameters.Add(isdefaultparametername, word.Default);
                            }
                        }

                        cmd.Parameters.Add("cardid", id);
                        cmd.Parameters.Add("side", side.ToString());
                        cmd.Parameters.Add("type", type.ToString());
                        PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);

                        Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
                    }
                }
            }
        }
コード例 #27
0
ファイル: Similarity.cs プロジェクト: rokii/context_analyzer
        /// <summary>
        /// 计算两个词语的相似度
        /// </summary>
        /// <param name="word1"></param>
        /// <param name="word2"></param>
        /// <param name="wordtype"></param>
        /// <returns></returns>
        public double calWordSim(string word1, string word2, WordType wordtype)
        {
            string[] concepts1Type = null;
            string[] concepts1 = this.getConcepts(word1,ref concepts1Type);
            string[] concepts2Type = null;
            string[] concepts2 = this.getConcepts(word2,ref concepts2Type);

            if (concepts1 == null)
            {
                System.Diagnostics.Trace.WriteLine(word1 + "不在字典中");
                return 0d;
            }

            if (concepts2 == null)
            {
                System.Diagnostics.Trace.WriteLine(word2 + "不在字典中");
                return 0d;
            }

            int len1 = concepts1.Length;
            int len2 = concepts2.Length;

            if (len1 == 0)
            {
                System.Diagnostics.Trace.WriteLine(word1 + "不在字典中");
                return 0d;
            }
            if (len2 == 0)
            {
                System.Diagnostics.Trace.WriteLine(word2 + "不在字典中");
                return 0d;
            }

            double maxsim = 0d;
            for (int i = 0; i < len1; i++)
            {
                if (concepts1Type[i].Trim().ToUpper() != wordtype.ToString().ToUpper())
                {
                    continue;
                }

                for (int j = 0; j < len2; j++)
                {
                    if (concepts1Type[i].Trim().ToUpper() == concepts2Type[j].Trim().ToUpper())
                    {
                        double sim = calConceptSim(concepts1[i], concepts2[j]);
                        if (sim > maxsim) { maxsim = sim; }
                    }
                }
            }
            return maxsim;
        }
コード例 #28
0
        /// <summary>
        /// Clears all words.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public void ClearAllWords(int id, Side side, WordType type)
        {
            SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
            cmd.CommandText = "DELETE FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type";
            cmd.Parameters.Add("@id", id);
            cmd.Parameters.Add("@side", side.ToString());
            cmd.Parameters.Add("@type", type.ToString());
            MSSQLCEConn.ExecuteNonQuery(cmd);

            Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
        }
コード例 #29
0
        public IWord CreateNewWord(int id, string word, Side side, WordType type, bool isDefault)
        {
            if (word != null)
            {
                using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
                {
                    using (NpgsqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "INSERT INTO \"TextContent\" (cards_id, text, side, type, position, is_default) VALUES (:id, :text, :side, :type, " +
                            "(COALESCE((SELECT position FROM \"TextContent\" WHERE cards_id=:id AND side=:side AND type=:type ORDER BY position DESC LIMIT 1), 0) + 10), " +
                            ":isdefault) RETURNING id";
                        cmd.Parameters.Add("id", id);
                        cmd.Parameters.Add("text", word);
                        cmd.Parameters.Add("side", side.ToString());
                        cmd.Parameters.Add("type", type.ToString());
                        cmd.Parameters.Add("isdefault", isDefault);

                        Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));

                        return new DbWord(Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser)), word, type, isDefault, Parent);
                    }
                }
            }
            else
                return null;
        }
コード例 #30
0
        public void ClearAllWords(int id, Side side, WordType type)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM \"TextContent\" WHERE cards_id=:id AND side=:side AND type=:type";
                    cmd.Parameters.Add("id", id);
                    cmd.Parameters.Add("side", side.ToString());
                    cmd.Parameters.Add("type", type.ToString());
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);

                    Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
                }
            }
        }
コード例 #31
0
 public override string ToString()
 {
     return($"<{type.ToString()} . {value}>");
 }
コード例 #32
0
 internal String ToJson()
 {
     wordTypeJson = wordType.ToString();
     return(JsonConvert.SerializeObject(this));
 }
コード例 #33
0
        public string RandomiseSentenceWithWordType(WordType type)
        {
            var sentences = memory.PlotLines.Value.Where(s => s.Contains("[" + type.ToString() + "]"));

            return(sentences.ElementAt(randomiser.Next(sentences.Count())));
        }
コード例 #34
0
        /// <summary>
        /// Adds the word.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="side">The side.</param>
        /// <param name="type">The type.</param>
        /// <param name="word">The word.</param>
        /// <remarks>Documented by Dev03, 2009-01-09</remarks>
        public void AddWord(int id, Side side, WordType type, IWord word)
        {
            if (word != null && word.Word.Length > 0)
            {
                SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser);
                cmd.CommandText = "SELECT count(*) FROM TextContent WHERE id = @wordid AND text = @word AND type = @type AND is_default = @isdefault;";
                cmd.Parameters.Add("@wordid", word.Id);
                cmd.Parameters.Add("@word", word.Word);
                cmd.Parameters.Add("@type", type.ToString());
                cmd.Parameters.Add("@isdefault", word.Default);
                bool wordExists = (Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)) > 0);
                if (!wordExists)
                {
                    cmd.CommandText = "SELECT position FROM TextContent WHERE cards_id=@id AND side=@side AND type=@type ORDER BY position DESC";
                    cmd.Parameters.Add("@id", id);
                    cmd.Parameters.Add("@side", side.ToString());
                    cmd.Parameters.Add("@type", type.ToString());

                    int currentPos = 0;
                    object retval = MSSQLCEConn.ExecuteScalar(cmd);
                    if (retval != DBNull.Value)
                        currentPos = Convert.ToInt32(retval);
                    cmd.Parameters.Clear();

                    cmd.CommandText = @"INSERT INTO TextContent (cards_id, text, side, type, position, is_default) VALUES (@id, @text, @side, @type, @position, @isdefault); SELECT @@IDENTITY;";
                    cmd.Parameters.Add("@id", id);
                    cmd.Parameters.Add("@text", word.Word);
                    cmd.Parameters.Add("@side", side.ToString());
                    cmd.Parameters.Add("@type", type.ToString());
                    cmd.Parameters.Add("@position", currentPos + 10);
                    cmd.Parameters.Add("@isdefault", word.Default);
                    MSSQLCEConn.ExecuteNonQuery(cmd);
                }

                Parent.CurrentUser.Cache.Uncache(ObjectLifetimeIdentifier.GetIdentifier(ObjectLifetimeIdentifier.GetCacheObject(side, type), id));
            }
        }