- 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..
<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>
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..
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: