C# Mantık hatam

artisbero

Üye
16 Ara 2010
176
0
ufak bir yapay zeka programı yazmam gerekiyor
programın 4 tane ana kuralı var
1. kural eğer 2 tane aynı kelime var ise tabi stop words şeklinde dizim var bunların dışındaki kelimeler
do you love x şeklinde soruyor
2. kural eğer soru cümlesi sorarsa do you often think about this question ya da why do you want to know şeklinde random sorması gerekiyor
3.kural negatif kelime dizimiz var bunlardan birini kullanırsa neden x şeklinde hissediyorsun kötü bir şey x doktora gitmen lazım tarzında bir şey söylüyor kodda daha detaylı anlarsınız zaten
4. kural program i ı you ya am i are a çevirip sonuna right ekleyip cevaplıyor bir şey kalmadığı durumlarda yani i am ahmet dediğimde are you ahmet right diyor ve son cümleyi ele alıyor
altta da örnek bir metin bu şekilde işlemeli şeklinde..
Ekran-G-r-nt-s-98.png

Kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeworkFinal
{
    class Program
    {
        static **** Main(string[] args)
        {
            bool shutdown = false;
            int[] counters = new int[50];
            bool[] answers = new bool[4];
            string outputValue = " ";
            string inputValue = " ";

            char[] punctuations = { '.', ',', ';', '’', '”', '?', '!', '-', '{', '}', '(', ')', '[', ']' };
            string[] stop_words = {"a", "after", "again", "all", "am", "and", "any", "are", "as", "at", "be", "been",
                                "before", "between", "both", "but", "by", "can", "could", "for", "from", "had", "has", "he", "her", "here",
                                "him", "in", "into", "I", "is", "it", "me", "my", "of", "on", "our", "she", "so", "such", "than", "that", "the",
                                "then", "they", "this", "to", "until", "we", "was", "were", "with", "you"
            };

            string[] negative_words = {"stress", "depression", "sad", "angry", "hate", "pain", "abnormal", "abort", "abuse",
                                "brittle", "hurt", "scared", "afraid", "upset", "confused", "lonely", "tired", "vulnerable", "guilty",
                                "anxiety", "disappointment", "regret", "awful", "sick", "regretful", "unhappy", "sorrowful", "troubled",
                                "worried", "annoyed"
            };


            while (!shutdown)
            {
                Console.Write("User : ");
                inputValue = Console.ReadLine();
                inputValue = inputValue.ToLower();
                inputValue = inputValue.Replace('ı', 'i');
                string[] input = inputValue.Split('.');


                for (int i = 0; i < punctuations.Length; i++)           //kural 1
                {
                    inputValue = inputValue.Replace(punctuations[i], ' ');
                }
                inputValue = inputValue.Replace("  ", " ");
                string[] eachone = inputValue.Split();

                for (int i = 0; i < eachone.Length; i++)
                {
                    for (int j = 0; j < eachone.Length; j++)
                    {
                        if (eachone[j] == eachone[i])
                        {
                            counters[i]++;
                        }

                    }
                    for (int k = 0; k < stop_words.Length; k++)
                    {
                        if (eachone[i] != stop_words[k] && counters[i] >= 2)
                        {
                            outputValue = "Computer : Do you Love " + eachone[i] + " ";

                            counters[i] = 0;
                        }
                    }

                }
                for (int i = 0; i < eachone.Length; i++)       // kural 2
                {
                    if (eachone[i].Contains("why") || eachone[i].Contains("who") || eachone[i].Contains("when")
                        || eachone[i].Contains("where") || eachone[i].Contains("what") || eachone[i].Contains("how"))
                    {
                        Random choose = new Random();
                        int sayi = choose.Next(1, 3);
                        if (sayi == 1)
                        {
                            outputValue = "Computer : Do you often think about this question ?";
                        }
                        if (sayi == 2)
                        {
                            outputValue = "Computer : Why do you want to know?";
                        }
                        answers[1] = true;
                    }

                }

                for (int i = 0; i < negative_words.Length; i++) // kural 3
                {
                    for (int k = 0; k < input.Length; k++)
                    {


                        if (input[k].Contains(negative_words[i]))
                        {
                            outputValue = "Computer : Being " + negative_words[i] + " is bad for your health. How long do you feel " + negative_words[i] + "? Why do you feel " + negative_words[i] + " ?";
                        }

                    }


                    if (input[input.Length - 1].Contains("i am") || input[input.Length - 1].Contains("name is")) // kural 4
                    {

                        
                        input[input.Length - 1] = input[input.Length - 1].Replace(" i ", " you ");
                        input[input.Length - 1] = input[input.Length - 1].Replace(" am ", " are ");
                        input[input.Length - 1] = input[input.Length - 1].Replace(" my ", " your ");
                        input[input.Length - 1] = input[input.Length - 1].Replace("my ", " your "); // me you

                        outputValue="Computer : " + input[input.Length - 1] + ", right ?";
                        
                    }
                    
                }
                Console.WriteLine(outputValue);
                
            }
            Console.ReadLine();
        }
    }
}

<a href="https://ibb.co/DGTf34G"><img src="https://i.ibb.co/rbN2nkb/Ekran-G-r-nt-s-98.png" alt="Ekran-G-r-nt-s-98" border="0"></a>
 
Moderatör tarafında düzenlendi:

Vasmin

Uzman üye
19 Şub 2016
1,029
4
Console.Write("User : "); inputValue = Console.ReadLine(x); inputValue = inputValue.ToLower(x); inputValue = inputValue.Replace('ı', 'i'); string[] input = inputValue.Split('.');


x koyduğum yerlere fonksiyon eklemeyi dene bir de .
 

Vasmin

Uzman üye
19 Şub 2016
1,029
4
Console.ReadLine(x); inputValue = inputValue.ToLower(x); burda cenk'in yazdığı yazı ve programın verdiği cevap eksik . buraya belirlediğin fonksiyonları yaz. Mesela Program- You are cenk right ?

User- Yes , i am Cenk .
 

artisbero

Üye
16 Ara 2010
176
0
kodun hatalarını 1-2 saatlik uğraşla çözdüm son haliyle ilgilenen bakmak isteyen olursa kodları paylaşıyorum :)
Kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeworkFinal
{
    class Program
    {
        static **** Main(string[] args)
        {

            bool[] flag = new bool[4];
            bool shutdown = false;
            int counters = 0;
            string outputValue = " ";
            string inputValue = " ";
            char[] punctuations = { '.', ',', ';', '’', '”', '?', '!', '-', '{', '}', '(', ')', '[', ']',' ', };
            string[] stop_words = {"a", "after", "again", "all", "am", "and", "any", "are", "as", "at", "be", "been",
                                "before", "between", "both", "but", "by", "can", "could", "for", "from", "had", "has", "he", "her", "here",
                                "him", "in", "into", "I", "is", "it", "me", "my", "of", "on", "our", "she", "so", "such", "than", "that", "the",
                                "then", "they", "this", "to", "until", "we", "was", "were", "with", "you"
            };

            string[] negative_words = {"stress", "depression", "sad", "angry", "hate", "pain", "abnormal", "abort", "abuse",
                                "brittle", "hurt", "scared", "afraid", "upset", "confused", "lonely", "tired", "vulnerable", "guilty",
                                "anxiety", "disappointment", "regret", "awful", "sick", "regretful", "unhappy", "sorrowful", "troubled",
                                "worried", "annoyed"
            };
            string[] lastSentenceSWords;
            while (!shutdown)
            {
                Console.Write("User : ");
                inputValue = Console.ReadLine();
                inputValue = inputValue.ToLower();
                inputValue = inputValue.Replace('ı', 'i');
                string[] input = inputValue.Split(' ');

                string[] lastSentence = inputValue.Split('.');
                lastSentenceSWords = lastSentence[lastSentence.Length - 1].Split(' ');
                if (inputValue[inputValue.Length - 1] == '.')
                {
                     lastSentenceSWords = lastSentence[lastSentence.Length - 2].Split(' ');
                }
                
                if (inputValue=="i have to go now")
                {
                    break;
                }
                for (int i = 0; i < input.Length; i++)
                {
                    for (int k = 0; k < punctuations.Length; k++)
                    {
                        if (input[i].Contains(punctuations[k]))
                        {
                            input[i] = input[i].Replace(punctuations[k], ' ');
                            input[i] = input[i].Replace("  ", " ");
                        }
                    }
                }
                
                for (int i = 0; i < input.Length; i++)            //kural 1
                {
                    counters = 0;
                    for (int j = 0; j < input.Length; j++)
                    {
                        if (input[j] == input[i])
                        {
                            counters++;
                            if(counters==3)
                            {
                                break;
                            }
                        }
                    }
                    
                    if (counters == 3)
                    {
                        for (int k = 0; k < stop_words.Length; k++)
                        {
                            if (input[i] == stop_words[k])
                            {
                                flag[0] = true;
                                break;
                            }
                        }

                        if (flag[0] != true && flag[3] == false)
                        {
                            outputValue = "Computer : Do you love " + input[i] + " ";
                            Console.WriteLine(outputValue);
                            flag[3] = true;
                            break;
                            
                        }

                    }
                }

                for (int i = 0; i < input.Length; i++)       // kural 2
                {
                    if (input[i].Contains("why") || input[i].Contains("who") || input[i].Contains("when")
                        || input[i].Contains("where") || input[i].Contains("what") || input[i].Contains("how"))
                    {
                        flag[1] = true;
                        Random choose = new Random();
                        int sayi = choose.Next(1, 3);
                        if (sayi == 1)
                        {
                            outputValue = "Computer : Do you often think about this question ?";
                        }
                        if (sayi == 2)
                        {
                            outputValue = "Computer : Why do you want to know?";
                        }
                        Console.WriteLine(outputValue);
                    }
                }
                for (int i = 0; i < negative_words.Length; i++) // kural 3
                {
                    for (int k = 0; k < input.Length; k++)
                    {

                        if (input[k].Contains(negative_words[i]))
                        {
                            outputValue = "Computer : Being " + negative_words[i] + " is bad for your health. How long do you feel " + negative_words[i] + "? Why do you feel " + negative_words[i] + " ?";
                            Console.WriteLine(outputValue);
                            flag[2] = true;
                        }
                        
                    }
                    
                }
                if (flag[3] == false && flag[1] == false && flag[2] == false) // kural 4 
                {
                    for (int i = 0; i < lastSentenceSWords.Length; i++)
                    {
                        if (lastSentenceSWords[i] == "i")
                        {
                            lastSentenceSWords[i] = "you";
                        }
                        else if (lastSentenceSWords[i] == "am")
                        {
                            lastSentenceSWords[i] = "are";
                        }
                        else if (lastSentenceSWords[i] == "my")
                        {
                            lastSentenceSWords[i] = "your";
                        }
                        else if (lastSentenceSWords[i] == "myself")
                        {
                            lastSentenceSWords[i] = "yourself";
                        }
                        else if (lastSentenceSWords[i] == "me")
                        {
                            lastSentenceSWords[i] = "you";
                        }
                    }
                    Random choose2 = new Random();
                    int sayi2 = choose2.Next(1, 3);
                    if (sayi2 == 1)
                    {
                        Console.Write("Computer : You say ");
                        for (int k = 0; k < lastSentenceSWords.Length; k++)
                        {
                            Console.Write(lastSentenceSWords[k] + " ");
                        }
                        Console.Write(".");
                    }
                    if (sayi2 == 2)
                    {
                        Console.Write("Computer : ");

                        for (int k = 0; k < lastSentenceSWords.Length; k++)
                        {
                            Console.Write(lastSentenceSWords[k] + " ");
                        }
                        Console.Write(", right ? ");
                    }
                    Console.WriteLine();
                }
                
                flag[0] = false;
                flag[1] = false;
                flag[2] = false;
                flag[3] = false;
                
            }
        }
    }
}
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.