Esempio n. 1
0
 public void getDoc_MengandungQuery(string[] query)
 {
     double[] hasilPembilang_Perkata;
     double[] hasilPenyebut_Perkata;
     for (int i = 0; i < query.Length; i++)
     {
         string queryPakek = cariID_Term(query[i]);
         if (queryPakek.Equals("0"))
         {
             Console.WriteLine("Tidak ada dokument yang memakai kata '" + query + "'");
             Console.WriteLine("======================================================================");
         }
         else
         {
             koneksi con = new koneksi();
             con.openConnection();
             string queryDF = "SELECT \"idDokumen\", \"id_Term\", \"TF-IDF\" FROM public.\"bobotTerm\" where" +
                              " \"id_Term\"='" + queryPakek + "'";
             DataTable result      = con.getResult(queryDF);
             string[]  dataID_Term = new string[result.Rows.Count];
             hasilTF_IDF_Perkata_Pembagi   = new double[dataID_Term.Length];
             hasilTF_IDF_Perkata_Pembilang = new double[dataID_Term.Length];
             string[] dataTF_IDF_Term = new string[result.Rows.Count];
         }
     }
 }
Esempio n. 2
0
        public void simpanTermBaru(string term)
        {
            con.openConnection();
            this.con = new koneksi();
            string queryTerm = "INSERT INTO public.\"Term\"(\"Term\") VALUES ('" + term + "');";

            con.excequteQuery(queryTerm);
            con.stopAccess();
        }
Esempio n. 3
0
        public void updateDF(string term, string ndata)
        {
            con.openConnection();
            this.con = new koneksi();
            string queryDF = "UPDATE public.\"Term\" set \"DF\"=" + ndata + " WHERE \"Term\"='" + term + "';";

            con.excequteQuery(queryDF);
            con.stopAccess();
        }
Esempio n. 4
0
        public void insert_ToBobot(string idDoc, string idTerm, int tf)
        {
            this.con = new koneksi();
            con.openConnection();
            string queryInsert_Dokument = "INSERT INTO public.\"bobotTerm\"(\"idDokumen\", \"id_Term\", \"Tf\") VALUES ('" + idDoc + "', '" + idTerm + "', " + tf + ");";

            con.excequteQuery(queryInsert_Dokument);
            con.stopAccess();
        }
Esempio n. 5
0
        public int getCOunt()
        {
            this.con = new koneksi();
            string    query  = "SELECT COUNT(*) FROM public.katadasar";
            DataTable result = this.con.getResult(query);
            int       count  = result.Rows.Count;

            return(count);
        }
Esempio n. 6
0
        public void updateTF_IDF(double value, string idBobotTerm)
        {
            con.openConnection();
            this.con = new koneksi();
            string queryTF_IDF = "UPDATE public.\"bobotTerm\" SET \"TF-IDF\"='" + value + "' WHERE \"id_bobotTerm\"='" + idBobotTerm + "';";

            con.excequteQuery(queryTF_IDF);
            con.stopAccess();
        }
Esempio n. 7
0
        public string getValueDF(string term)
        {
            string valueCari = null;

            this.con = new koneksi();
            con.openConnection();
            string    termMasuk = "SELECT \"DF\"  FROM public.\"Term\" where \"Term\"='" + term + "';";
            DataTable result    = this.con.getResult(termMasuk);

            valueCari = result.Rows[0]["DF"].ToString();
            con.stopAccess();
            return(valueCari);
        }
Esempio n. 8
0
        public string cariID_Term(string data)
        {
            string termCari = null;

            this.con = new koneksi();
            con.openConnection();
            string    termMasuk = "SELECT * FROM public.\"Term\" where \"Term\"='" + data + "';";
            DataTable result2   = this.con.getResult(termMasuk);

            termCari = result2.Rows[0]["id_Term"].ToString();
            con.stopAccess();
            return(termCari);
        }
Esempio n. 9
0
        public string getIDF_Term(string term)
        {
            koneksi con = new koneksi();

            con.openConnection();
            double    getIDF_Term = 0;
            string    QgetDF_Term = "SELECT \"IDF\"  FROM public.\"Term\" where \"Term\"='" + term + "';";
            DataTable result      = con.getResult(QgetDF_Term);

            getIDF_Term = Convert.ToDouble(result.Rows[0]["IDF"]);
            con.stopAccess();
            return(getIDF_Term.ToString());
        }
Esempio n. 10
0
        public string[] getId_Doc(string idTerm)
        {
            koneksi con = new koneksi();

            con.openConnection();
            string    query  = "SELECT \"idDokumen\" FROM public.\"bobotTerm\" where \"id_Term\" = '" + idTerm + "'";
            DataTable result = con.getResult(query);

            string[] arrayDoc = new string[result.Rows.Count];
            for (int i = 0; i < result.Rows.Count; i++)
            {
                arrayDoc[i] = result.Rows[i]["idDokumen"].ToString();
            }
            return(arrayDoc);
        }
Esempio n. 11
0
        public string[] getID_Term(string[] query)
        {
            koneksi con = new koneksi();

            con.openConnection();
            string    queryTerm = "SELECT \"id_Term\" FROM public.\"Term\" where \"Term\" in ( " + string.Join(", ", query) + ");";
            DataTable result    = con.getResult(queryTerm);

            string[] arrayTerm = new string[result.Rows.Count];
            for (int i = 0; i < result.Rows.Count; i++)
            {
                arrayTerm[i] = "'" + result.Rows[i]["id_Term"] + "'".ToString();
            }
            return(arrayTerm);
        }
Esempio n. 12
0
        public void setIDF()
        {
            con.openConnection();
            this.con = new koneksi();
            string    queryDF = "SELECT \"id_Term\"  FROM public.\"Term\";";
            DataTable result  = this.con.getResult(queryDF);

            string[] dataID_Term = new string[result.Rows.Count];
            for (int i = 0; i < result.Rows.Count; i++)
            {
                dataID_Term[i] = result.Rows[i]["id_Term"].ToString();
                double value = count_IDF(dataID_Term[i]);
                updateIDF(value, dataID_Term[i]);
            }
            con.stopAccess();
        }
Esempio n. 13
0
        public bool getKataSambung(string kata)
        {
            this.con = new koneksi();
            string    query  = "SELECT kata FROM public.kata_sambung where kata =  '" + kata + "'";
            DataTable result = this.con.getResult(query);

            con.closeConnection();
            if (result.Rows.Count == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 14
0
        public void get_LongDoc()
        {
            con.openConnection();
            this.con = new koneksi();
            string    queryDF = "select count(distinct \"idDokumen\") as getLong from public.\"bobotTerm\";";
            DataTable result  = this.con.getResult(queryDF);

            getNumber = Convert.ToInt32(result.Rows[0]["getLong"].ToString());
            if (getNumber == 0)
            {
                getNumber = 1;
            }
            else
            {
                getNumber += 1;
            }
            con.stopAccess();
        }
Esempio n. 15
0
        public bool cekID_Doc(string id)
        {
            bool status = false;

            this.con = new koneksi();
            con.openConnection();
            string    cek_KesediaanID = "SELECT *  FROM public.\"bobotTerm\" where \"idDokumen\"='" + id + "';";
            DataTable result          = this.con.getResult(cek_KesediaanID);

            if (result.Rows.Count > 0)
            {
                status = false;
            }
            else
            {
                status = true;
            }
            return(status);
        }
Esempio n. 16
0
        public string cariID_Term(string data)
        {
            koneksi con = new koneksi();

            con.openConnection();
            string    termCari  = null;
            string    termMasuk = "SELECT * FROM public.\"Term\" where \"Term\"='" + data + "';";
            DataTable result2   = con.getResult(termMasuk);

            idDoc = new string[result2.Rows.Count];
            if (result2.Rows.Count >= 1)
            {
                termCari = result2.Rows[0]["id_Term"].ToString();
                con.stopAccess();
                return(termCari);
            }
            else
            {
                return("0");
            }
        }
Esempio n. 17
0
        public double cariTF_IDF(string id_doc, string idTerm)
        {
            koneksi con = new koneksi();

            con.openConnection();
            double termCari;
            string termMasuk = "SELECT \"TF-IDF\" FROM public.\"bobotTerm\" where" +
                               " \"idDokumen\"=" + id_doc + " and \"id_Term\"=" + idTerm + ";";
            DataTable result2 = con.getResult(termMasuk);

            if (result2.Rows.Count >= 1)
            {
                termCari = Convert.ToDouble(result2.Rows[0]["TF-IDF"]);
                con.stopAccess();
                return(termCari);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 18
0
        public bool runVSM_DB(string data, string id, int tf)
        {
            string idTerm;

            this.con = new koneksi();
            con.openConnection();
            string    cek_KesediaanTerm = "SELECT * FROM public.\"Term\" where \"Term\"='" + data + "';";
            DataTable result            = this.con.getResult(cek_KesediaanTerm);

            con.stopAccess();
            if (result.Rows.Count == 0)
            {
                //simpan Term baru
                con.openConnection();
                this.con = new koneksi();
                string queryTerm = "INSERT INTO public.\"Term\"(\"Term\", \"DF\") VALUES ('" + data + "','1');";
                con.excequteQuery(queryTerm);
                con.stopAccess();
                con.closeConnection();

                //baca idTermnya
                idTerm = cariID_Term(data);
                insert_ToBobot(id, idTerm, tf);
                con.stopAccess();
                con.closeConnection();
            }
            else // ketika sama
            {
                //baca idTermnya
                idTerm = cariID_Term(data);
                //update nilai df kata-n
                int dfBefore    = Convert.ToInt32(getValueDF(data));
                int data_update = (dfBefore + 1);
                updateDF(data, Convert.ToString(data_update));
                insert_ToBobot(id, idTerm, tf);
                con.stopAccess();
            }
            //simpan dokument
            return(true);
        }
Esempio n. 19
0
        public string[] getID_Doc(string[] idTerm)
        {
            koneksi con = new koneksi();

            con.openConnection();
            string    queryTerm = "SELECT \"idDokumen\" FROM public.\"bobotTerm\" where \"id_Term\" in ( " + string.Join(", ", idTerm) + " );";
            DataTable result    = con.getResult(queryTerm);

            string[]      arrayDoc   = new string[result.Rows.Count];
            List <string> List_idDoc = new List <string>();

            for (int i = 0; i < result.Rows.Count; i++)
            {
                if (!List_idDoc.Contains(result.Rows[i]["idDokumen"]))
                {
                    List_idDoc.Add("'" + result.Rows[i]["idDokumen"] + "'".ToString());
                }
                else
                {
                }
            }
            arrayDoc = List_idDoc.ToArray();
            return(arrayDoc);
        }
Esempio n. 20
0
        public double cekKetersediaan_Term(string kata)
        {
            koneksi con = new koneksi();

            con.openConnection();
            string    query  = "SELECT \"Term\"  FROM public.\"Term\" where \"Term\"='" + kata + "';";
            DataTable result = con.getResult(query);

            con.closeConnection();
            if (result.Rows.Count >= 1)
            {
                con.openConnection();
                double    getIDF_Term = 0;
                string    QgetDF_Term = "SELECT \"IDF\"  FROM public.\"Term\" where \"Term\"='" + kata + "';";
                DataTable result2     = con.getResult(QgetDF_Term);
                getIDF_Term = Convert.ToDouble(result2.Rows[0]["IDF"]);
                con.stopAccess();
                return(getIDF_Term);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 21
0
        public void getDoc_MengandungQuery(string query)
        {
            string queryPakek = cariID_Term(query);

            double[] hasilPembilang_Perkata;
            double[] hasilPenyebut_Perkata;

            if (queryPakek.Equals("0"))
            {
                Console.WriteLine("Tidak ada dokument yang memakai kata '" + query + "'");
                Console.WriteLine("======================================================================");
            }
            else
            {
                koneksi con = new koneksi();
                con.openConnection();
                string queryDF = "SELECT \"idDokumen\", \"id_Term\", \"TF-IDF\" FROM public.\"bobotTerm\" where" +
                                 " \"id_Term\"='" + queryPakek + "'";
                DataTable result = con.getResult(queryDF);

                string[] dataID_Term = new string[result.Rows.Count];
                hasilTF_IDF_Perkata_Pembagi   = new double[dataID_Term.Length];
                hasilTF_IDF_Perkata_Pembilang = new double[dataID_Term.Length];
                string[] dataTF_IDF_Term = new string[result.Rows.Count];
                for (int i = 0; i < result.Rows.Count; i++)
                {
                    int count = 1;
                    dataTF_IDF_Term[i] = result.Rows[i]["idDokumen"].ToString();
                    hasilTF_IDF_Perkata_Pembilang[i] = Convert.ToDouble(result.Rows[i]["TF-IDF"]);
                    hasilTF_IDF_Perkata_Pembagi[i]   = Convert.ToDouble(result.Rows[i]["TF-IDF"]);
                    hasilPembilang_Perkata           = new double[result.Rows.Count];
                    hasilPenyebut_Perkata            = new double[result.Rows.Count];

                    if ((result.Rows.Count - 1) == i)
                    {
                        Console.WriteLine("dokument yang memakai kata '" + query + "' sebanyak " + result.Rows.Count + " dokumen yaitu " + dataID_Term[i]);
                        Console.WriteLine("======================================================================");
                        double TF_IDFperKata = cariTF_IDF(dataID_Term[i], queryPakek);
                        for (int w = 0; w < result.Rows.Count; w++)
                        {
                            string tempId = dataTF_IDF_Term[w];
                            hasilPembilang_Perkata[w] = Math.Round(hasilTF_IDF_Perkata_Pembilang[w] * hasil_TF_IDF_Query, 4);
                            hasilPenyebut_Perkata[w]  = Math.Round(Math.Sqrt(hasilTF_IDF_Perkata_Pembagi[w] * hasil_TF_IDF_Query), 4);
                            Console.WriteLine("Nilai pembilang id doc '" + tempId + " = " + hasilPembilang_Perkata[w]);
                            Console.WriteLine("Nilai pembagi   id doc '" + tempId + " = " + hasilPenyebut_Perkata[w]);
                            Console.WriteLine("======================================================================");
                            double hasilTotal_Pembilang = +hasilPembilang_Perkata[w];
                            for (int fr = 0; fr < idDoc_Terlibat.Length; fr++)
                            {
                                idList.Add(tempId);

                                if (result.Rows.Count - 1 == w)
                                {
                                    idList_Array = idList.ToArray();
                                }
                            }
                        }
                    }
                }
                con.stopAccess();
            }
        }
Esempio n. 22
0
        public string[] runStemming_Tala(string text)
        {
            char[] delimiterChars = { ' ', ',', '.', ':', '\t', '-', '(', ')', '"', '`' };
            System.Console.WriteLine($"Original text: '{text}'");
            string[] words = text.Split(delimiterChars);
            System.Console.WriteLine($"{text.Length} words in text:");
            var count   = new stemmingTala();
            int getData = count.getCOunt();
            int range   = words.Length;

            arrayWord = new string[range];

            //kumpulan aturan tala Stemming//
            string[] test_1 = { "lah", "kah", "pun" };
            string[] test_2 = { "nya", "ku", "mu" };
            string[] test_3 = { "meng", "menya", "menyi", "menyu", "menye", "menyo", "meny",  "men",   "mema", "memi", "memu", "meme", "memo",
                                "memo", "me",    "peng",  "penya", "penyi", "penyu", "penye", "penyo", "peny", "pen",  "pema", "pemi", "pemu","peme","pemo", "pem", "di", "ter", "ke" };
            string[] test_3replace = { "",  "s", "s", "s", "s", "s", "s", "", "p", "p", "p", "p", "p", "", "", "", "s", "s", "s", "s", "s", "s", "",
                                       "p", "p", "p", "p", "p", "",  "",  "", "" };

            string[,] test_22 = { { "meng",  ""  }, { "menya", "s" }, { "menyi", "s" }, { "menyu", "s" }, { "menye", "s" }
                                  ,{ "menyo", "s" }, { "meny",  "s" }, { "men",   "s" }, { "mema",  "p" }, { "memi",  "p" }, { "memu",  "p" }, { "meme",  "p" }
                                  ,{ "memo",  "p" }, { "mem",   ""  }, { "me",    ""  }, { "peng",  ""  }, { "penya", "s" }, { "penyi", "s" }, { "penye", "s" }, { "penyo", "s" }
                                  ,{ "peny",  "s" }, { "pen",   ""  }, { "pema",  "s" }, { "pemi",  "s" }, { "pemu",  "s" }, { "peme",  "s" }, { "pemo",  "s" }, { "pem",   ""  }
                                  ,{ "di",    ""  }, { "ter",   ""  }, { "ke",    ""  } };
            string[,] test_3a   = { { "ber", "" }, { "bel", "" }, { "be", "" }, { "per", "" }, { "pel", "" }, { "pe", "" } };
            string[,] test_4das = { { "kan", "" }, { "an", "" }, { "i", "" } };

            //proses memasukkan kata kedalam array//
            for (int i = 0; i < words.Length; i++)
            {
                arrayWord[i] = text.Split(delimiterChars)[i].ToString().ToLower();
                Console.WriteLine("[" + arrayWord[i] + "]");
                //Proses filtering, atau menghilangkan kata sambung//

                if (count.getKataSambung(arrayWord[i]) == true)
                {
                    //proses menghilangkan wordList//
                    Console.WriteLine("[" + arrayWord[i] + "]" + "=> masuk kata sambung, kata dalam index ini dihapus");
                    arrayWord[i] = "";
                }
                //memeriksa apakah sudah kata dasar//
                else if (count.getKataDasar(arrayWord[i]) == true)
                {
                    arrayWord[i] = arrayWord[i];
                    this.con     = new koneksi();
                    Console.WriteLine("[" + arrayWord[i] + "]" + "[ini kata dasar_ so Fix]");
                }
                //proses tala ke-1// hilangkan sandang kalau ada
                else if (count.cekSandang(arrayWord[i]) > 0)//cek apakah punyak sandang
                {
                    Console.WriteLine("[" + arrayWord[i] + "]" + " Masuk Proses Tala 1");
                    arrayWord[i] = count.replace_Sandang(arrayWord[i]);//proses hapus sandang

                    if (count.getKataDasar(arrayWord[i]) == true)
                    {
                        Console.WriteLine("sudah kata dasar jadi " + "[" + arrayWord[i] + "]");
                    }
                    else if (count.cekAkhiran(arrayWord[i]) > 0)//cek akhirannya
                    {
                        Console.WriteLine("[" + arrayWord[i] + "]" + " Masuk Proses Tala 1");
                        arrayWord[i] = count.replace_Akhiran(arrayWord[i]);//proses hapus akhiran
                        if (count.getKataDasar(arrayWord[i]) == true)
                        {
                            Console.WriteLine("sudah kata dasar jadi " + "[" + arrayWord[i] + "]");
                        }

                        else
                        {
                            Console.WriteLine("belum kata dasar " + "[" + arrayWord[i] + "]" + " Lanjut ke proses selanjutnya");
                        }
                    }
                    else
                    {
                        Console.WriteLine("belum kata dasar " + "[" + arrayWord[i] + "]" + " Lanjut ke proses selanjutnya");
                        if (count.cekAkhiran(arrayWord[i]) > 0)                 // cek apakah punyak akhiran
                        {
                            arrayWord[i] = count.replace_Akhiran(arrayWord[i]); //proses hapus akhiran
                            Console.WriteLine("diproses 2 jadi " + "[" + arrayWord[i] + "]");
                        }

                        else
                        {
                            Console.WriteLine("[" + arrayWord[i] + "]" + "Tidak Punyak akhiran, maka dilakukan menghilangkan awalan 1");
                            arrayWord[i] = count.replace_Awalan1(arrayWord[i]);
                            //runVSM_DB(arrayWord[i], id, getFrekunsiKata());//lakukan proses kelola DB
                            Console.WriteLine("Tidak Punyak akhiran, maka dilakukan menghilangkan awalan 1 menjadi " + "[" + arrayWord[i] + "]");
                        }
                    }
                }
                else if (count.cekAkhiran(arrayWord[i]) > 0)//cek akhirannya
                {
                    Console.WriteLine("[" + arrayWord[i] + "]" + " Masuk Proses Tala 1");
                    arrayWord[i] = count.replace_Akhiran(arrayWord[i]);//proses hapus akhiran
                    if (count.getKataDasar(arrayWord[i]) == true)
                    {
                        //runVSM_DB(arrayWord[i], id, getFrekunsiKata());//lakukan proses kelola DB
                        Console.WriteLine("sudah kata dasar jadi " + "[" + arrayWord[i] + "]");
                    }
                    else
                    {
                        Console.WriteLine("belum kata dasar " + "[" + arrayWord[i] + "]" + " Lanjut ke proses selanjutnya");
                        if (count.getKataDasar(arrayWord[i]) == true)
                        {
                            Console.WriteLine("sudah kata dasar jadi " + "[" + arrayWord[i] + "]");
                        }
                        else if (count.cekawalan1(arrayWord[i]) > 0)//cek punyak awalan kah ???
                        {
                            Console.WriteLine("[" + arrayWord[i] + "]" + "Tidak Punyak akhiran, maka dilakukan menghilangkan awalan 1");
                            arrayWord[i] = count.replace_Awalan1(arrayWord[i]);
                            //runVSM_DB(arrayWord[i], id, getFrekunsiKata());//lakukan proses kelola DB
                            Console.WriteLine("Tidak Punyak akhiran, maka dilakukan menghilangkan awalan 1 menjadi " + "[" + arrayWord[i] + "]");
                        }
                    }
                }
                else if (count.cekawalan1(arrayWord[i]) > 0)
                {
                    Console.WriteLine("[" + arrayWord[i] + "]" + "Tidak Punyak akhiran, maka dilakukan menghilangkan awalan");
                    arrayWord[i] = count.replace_Awalan1(arrayWord[i]);
                    //runVSM_DB(arrayWord[i], id, getFrekunsiKata());//lakukan proses kelola DB
                    Console.WriteLine("Tidak Punyak akhiran, maka dilakukan menghilangkan awalan 1 menjadi " + "[" + arrayWord[i] + "]");
                }
                else if (arrayWord[i].Length < 3)
                {
                    arrayWord[i] = "";
                }
                else
                {
                    arrayWord[i] = arrayWord[i];
                    //runVSM_DB(arrayWord[i], id, getFrekunsiKata());//lakukan proses kelola DB
                    Console.WriteLine("[" + arrayWord[i] + "]");
                }
                con.stopAccess();
                array[i] = arrayWord[i];
            }
            return(array);
        }