//==============================Vowels==========================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace vowels
{
class Program
{
static void Main(string[]
args)
{
string
text = File.ReadAllText("d:\\input.txt");
Regex
remove = new Regex(@"\.|\s|,|!|\\|/|:|;|\[|\]|\{|\}|\?|<|>|\|");//...To remove symbols from the words
string[]
words = remove.Split(text);
int
v = 0;
List<string> vowels = new
List<string>();
List<string> consonents = new
List<string>();
Console.WriteLine(text);
foreach
(string s in
words)
{
string
s1=s.ToLower();
if
(s1.StartsWith("a") ||
s1.StartsWith("e") ||
s1.StartsWith("o") ||
s1.StartsWith("i") || s1.StartsWith("u"))
{
vowels.Add(s1);
v++;
}
}
Console.WriteLine("\n........................................\n");
List<string> distVowels = vowels.Distinct().ToList();
Console.WriteLine("Given text file contains " +
distVowels.Count() + " distinct vowels which
are as:");
foreach
(string s in
distVowels)
{
int
freq = 0;
for
(int i = 0; i < vowels.Count(); i++)
{
if
(s.Equals(vowels[i]))
{
freq++;
}
}
Console.WriteLine(s+"=>"+freq);
}
Console.Read();
}
}
}
//==============================Consonents==========================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace Consonents
{
class Program
{
static void Main(string[]
args)
{
string
text = File.ReadAllText("d:\\input.txt");
Regex
remove = new Regex(@"\.|\s|,|!|\\|/|:|;|\[|\]|\{|\}|\?|<|>|\|");//...To remove symbols from the words
string[]
words = remove.Split(text);
int
c = 0;
List<string> consonents = new
List<string>();
Console.WriteLine(text);
foreach (string s in words)
{
string
s1 = s.ToLower();
if
(s1.StartsWith("a") ||
s1.StartsWith("e") ||
s1.StartsWith("o") ||
s1.StartsWith("i") ||
s1.StartsWith("u"))
{
continue;
}
else
if(!s.Equals(""))
{
consonents.Add(s1);
c++;
}
}
Console.WriteLine("\n........................................\n");
List<string> distConsonents =
consonents.Distinct().ToList();
Console.WriteLine("Given text file contains " +
distConsonents.Count() + " distinct consonents
which are as:");
foreach
(string s in
distConsonents)
{
int
freq = 0;
for
(int i = 0; i < consonents.Count(); i++)
{
if
(s.Equals(consonents[i]))
{
freq++;
}
}
Console.WriteLine(s
+ "=>" + freq);
}
Console.Read();
}
}
}
//=============================Count
Lines Words======================================
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace Line_Word_Count
{
class Program
{
static void Main(string[]
args)
{
string[]
lines = File.ReadAllLines("d:\\input.txt");
List<string> words = new
List<string>();
List<string> consonents = new
List<string>();
Console.WriteLine("Given text file contains " +
lines.Count() + " lines");
foreach
(string s in
lines)
{
string[]
wrd = s.Split(' ');
foreach
(string w in
wrd)
{
words.Add(w);
}
}
Console.WriteLine("Given text file contains " +
words.Count() + " words");
Console.Read();
}
}
}
//==============================Count
Articles==============================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace CountWords
{
class Program
{
static void Main(string[]
args)
{
string
text = File.ReadAllText("d:\\input.txt");
Regex
remove = new Regex(@"\.|\s|,|!|\\|/|:|;|\[|\]|\{|\}|\?|<|>|\|");//...To remove symbols from the words
string[]
words = remove.Split(text);
List<string> a = new List<string>();
List<string> an = new List<string>();
List<string> the = new List<string>();
Console.WriteLine(text);
foreach
(string s in
words)
{
string
s1 = s.ToLower();
if
(s1.Equals("a"))
{
a.Add(s1);
}
else
if (s1.Equals("an"))
{
an.Add(s1);
}
else
if (s1.Equals("the"))
{
the.Add(s1);
}
}
Console.WriteLine("\n...........................................\n");
Console.WriteLine("Number of a's="+a.Count());
Console.WriteLine("Number of an's=" + an.Count());
Console.WriteLine("Number of the's=" + the.Count());
Console.WriteLine("Total Number of articles=" + (a.Count()
+ an.Count() + the.Count()));
Console.Read();
}
}
}
//==========================Word
Frequency================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace Line_Word_Count
{
class Program
{
static void Main(string[]
args)
{
string[]
lines = File.ReadAllLines("d:\\input.txt");
List<string> words = new
List<string>();
List<string> consonents = new
List<string>();
Console.WriteLine("Given text file contains " +
lines.Count() + " lines");
foreach
(string s in
lines)
{
string[]
wrd = s.Split(' ');
foreach
(string w in
wrd)
{
words.Add(w);
}
}
List<string> distWords = words.Distinct().ToList();
foreach
(string s in
distWords)
{
int
freq = 0;
for
(int i = 0; i < words.Count(); i++)
{
if
(s.Equals(words[i]))
{
freq++;
}
}
Console.WriteLine(s
+ "=>" + freq);
}
Console.WriteLine("Total number of words=" +
words.Count());
Console.Read();
}
}
}
//=====================================Naïve
Bayes===================================
//#define num 11; PAGE 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BayesAlgo
{
class Film
{
public string[][] film = {
new string[]{"Amir Khan","Anushka
Sharma","Rajkumar Hirani","Rajkumar Hirani","Rajkumar Hirani","Hit"},
new string[]{"Rajkumar Rao","Kangana","Vikas Bahl","Anurag
Kashyap","Anvita Dutt","Hit"},
new string[]{"R.Madhavan","Kangana","Anand L. Rai","Anand
L. Rai","Himanshu","Hit"},
new
string[]{"Ranbir
Kapur","Anushka Sharma","Anurag Kashyap","Vikas Bahl","Anurag
Kashyap","Flop"},
new string[]{"Ranbir Kapur","Jackueline","Vikramjit Singh","Bhushan Kumar","Vikramjit
Singh","Flop"},
new string[]{"Vir Das","Kangana","Sai Kabir","Raju
Chadda","Sai Kabir","Flop"},
new string[]{"Salman Khan","Jackqueline","Sajid","Sajid","Rajat Arora","Hit"},
new string[]{"Salman Khan","Karina
Kapur","Kabir Khan","Salman Khan","Kabir
Khan","Hit"},
new string[]{"Abhishek Bachchan","Priyanka Chopra","Goldie Bahl","Sunil
Lulla","Goldi Bahl","Flop"},
new string[]{"Abhishek Bachchan","Aishwarya","Mani
Ratnan","Mani Ratnan","Valmiki","Flop"},
new string[]{"Amir Khan","Karina
Kapur","Rajkumar Hirani","Vidhu Vinod Chopra","Rajkumar Hirani","Hit"}
};
float
hCount = 0;
float
fCount = 0;
public int amirC = 0;
public int salmanC = 0;
public int ranbirC = 0;
public int virC = 0;
public int abhiC = 0;
public int madhavanC = 0;
public int rajC = 0;
public int amirH = 0;
public int salmanH = 0;
public int ranbirH = 0;
public int virH= 0;
public int abhiH = 0;
public int madhavanH = 0;
public int rajH = 0;
public int amirF = 0;
public int salmanF = 0;
public int ranbirF = 0;
public int virF= 0;
public int abhiF = 0;
public int madhavanF = 0;
public int rajF = 0;
int i;
public float aHProb = 0;
public float sHProb = 0;
public float rHProb = 0;
public float vHProb = 0;
public float abHProb = 0;
public float mHProb = 0;
public float rajHProb = 0;
public float aFProb = 0;
public float sFProb = 0;
public float rFProb = 0;
public float vFProb = 0;
public float abFProb = 0;
public float mFProb = 0;
public float rajFProb = 0;
//.....................................................................................
public int anuC = 0;
public int kC = 0;
public int jacC = 0;
public int karinaC = 0;
public int priyaC = 0;
public int aishC = 0;
public int anuH = 0;
public int kH = 0;
public int jacH = 0;
public int karinaH = 0;
public int priyaH = 0;
public int aishH = 0;
public int anuF = 0;
public int kF = 0;
public int jacF = 0;
public int karinaF = 0;
public int priyaF = 0;
public int aishF = 0;
public float anuHProb = 0;
public float kHProb = 0;
public float jacHProb = 0;
public float karinaHProb = 0;
public float priyaHProb = 0;
public float aishHProb = 0;
public float anuFProb = 0;
public float kFProb = 0;
public float jacFProb = 0;
public float karinaFProb = 0;
public float priyaFProb = 0;
public float aishFProb = 0;
public float HitCount() //count #
of hits Page 2
{
hCount = 0;
for
(int i = 0; i < film.Length; i++)
{
if
(film[i][5].Equals("Hit"))
hCount++;
}
return
hCount;
}
public float FlopCount()
//counts # of flops
{
fCount = 0;
for
(int i = 0; i < film.Length; i++)
{
if
(film[i][5].Equals("Flop"))
fCount++;
}
return
fCount;
}
public float HitProb()
{
return(hCount/film.Length);
}
public float FlopProb()
{
return
(fCount / film.Length);
}
public void ActorCount()
//counts # of particular Actor
{
try
{
//Console.WriteLine(film.Length);
for
(i = 0; i < (film.Length-1); i++)
{
if
(film[i][0].Equals("Amir Khan"))
amirC++;
else
if (film[i][0].Equals("Rajkumar
Rao"))
rajC++;
else
if (film[i][0].Equals("R.Madhavan"))
madhavanC++;
else
if (film[i][0].Equals("Ranbir
Kapur"))
ranbirC++;
else
if (film[i][0].Equals("Vir
Das"))
virC++;
else
if (film[i][0].Equals("Salman
Khan"))
salmanC++;
else
if (film[i][0].Equals("Abhishek
Bachchan"))
abhiC++;
}
if
(film[i][0].Equals("Amir Khan"))
amirC++;
else
if (film[i][0].Equals("Rajkumar
Rao"))
rajC++;
else
if (film[i][0].Equals("R.
Madhavan"))
madhavanC++;
else
if (film[i][0].Equals("Ranbir
Kapur"))
ranbirC++;
else
if (film[i][0].Equals("Vir
Das"))
virC++;
else
if (film[i][0].Equals("Salman
Khan"))
salmanC++;
else
if (film[i][0].Equals("Abhishek
Bachchan"))
abhiC++;
//Console.WriteLine(amirC);
//Console.WriteLine(rajC);
//Console.WriteLine(madhavanC);
//Console.WriteLine(ranbirC);
//
Console.WriteLine(abhiC);
}
catch
(Exception e)
{
Console.WriteLine("Exception: "+e);
}
}
public void ActoressCount()
//counts # of particular Actoress
{
try
{
//Console.WriteLine(film.Length);
for
(i = 0; i < (film.Length - 1); i++)
{
if
(film[i][1].Equals("Anushka Sharma"))
anuC++;
else
if (film[i][1].Equals("Kangana"))
kC++;
else
if (film[i][1].Equals("Jackueline"))
jacC++;
else
if (film[i][1].Equals("Karina
Kapur"))
karinaC++;
else
if (film[i][1].Equals("Priyanka
Chopra"))
priyaC++;
else
if (film[i][1].Equals("Aishwarya"))
aishC++;
}
if
(film[i][1].Equals("Anushka Sharma"))
anuC++;
else
if (film[i][1].Equals("Kangana"))
kC++;
else
if (film[i][1].Equals("Jackueline"))
jacC++;
else
if (film[i][1].Equals("Karina
Kapur"))
karinaC++;
else
if (film[i][1].Equals("Priyanka
Chopra"))
priyaC++;
else
if (film[i][1].Equals("Aishwarya"))
aishC++;
//Console.WriteLine(anuC);
//Console.WriteLine(kC);
//Console.WriteLine(jacC);
//Console.WriteLine(karinaC);
//Console.WriteLine(priyaC);
//Console.WriteLine(aishC);
}
catch
(Exception e)
{
Console.WriteLine("Exception: " + e);
}
}
public void Show()
{
Console.WriteLine("Hit Probability="+HitCount());
Console.WriteLine("Flop Probability="+FlopCount());
}
public string ActorProb()
{
int
ch=1;
//Actors
Console.WriteLine("..........................Actors........................");
Console.WriteLine("1:Amir Khan\t2:Rajkumar Rao\t3:R. Madhavn\t4:Ranbir
Kapur\n5:Vir Das\t6:Salman Khan\t7:Abhishek Bachchan");
Console.Write("Select one of Actors=> ");
ch = Int32.Parse(Console.ReadLine());
switch
(ch)
{
case
1://Amir Khan.....................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][0].Equals("Amir
Khan") && film[i][5].Equals("Hit"))
amirH++;
else if
(film[i][0].Equals("Amir Khan")
&& film[i][5].Equals("Flop"))
amirF++;
}
if
(film[i][0].Equals("Amir Khan")
&& film[i][5].Equals("Hit"))
amirH++;
else
if (film[i][0].Equals("Amir
Khan") && film[i][5].Equals("Flop"))
amirF++;
Console.WriteLine("Amir hit ="+amirH);
Console.WriteLine("Total hit ="+HitCount());
aHProb = amirH /
HitCount();
aFProb = amirF /
FlopCount();
Console.WriteLine("Amir hit prob="+ aHProb);
return(aHProb+" "+aFProb);
//break;
case
2://Rajkumar Rao...............................
for
(i = 0; i < (film.Length - 1); i++)
{
if
(film[i][0].Equals("Rajkumar Rao")
&& film[i][5].Equals("Hit"))
rajH++;
else if
(film[i][0].Equals("Rajkumar Rao")
&& film[i][5].Equals("Flop"))
rajF++;
}
if
(film[i][0].Equals("Rajkumar Rao")
&& film[i][5].Equals("Hit"))
rajH++;
else
if (film[i][0].Equals("Rajkumar
Rao") && film[i][5].Equals("Flop"))
rajF++;
Console.WriteLine("Rajkumar Rao hit =" + rajH);
Console.WriteLine("Total hit ="+HitCount());
rajHProb = rajH /
HitCount();
rajFProb = rajF /
FlopCount();
Console.WriteLine("Rajkumar Rao hit prob=" + rajHProb);
Console.WriteLine("Rajkumar Rao flop prob=" + rajFProb);
return(rajHProb+" "+rajFProb);//break;
case 3://R.Madhvan.....................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][0].Equals("R.Madhavan")
&& film[i][5].Equals("Hit"))
madhavanH++;
else if
(film[i][0].Equals("R.Madhavan")
&& film[i][5].Equals("Flop"))
madhavanF++;
}
if
(film[i][0].Equals("R.Madhavan")
&& film[i][5].Equals("Hit"))
madhavanH++;
else
if (film[i][0].Equals("R.Madhavan")
&& film[i][5].Equals("Flop"))
madhavanF++;
Console.WriteLine("R.Madhavan hit =" + madhavanH);
Console.WriteLine("Total hit ="+HitCount());
mHProb = madhavanH /
HitCount();
mFProb = madhavanF /
FlopCount();
Console.WriteLine("R.Madhavan hit prob=" + mHProb);
Console.WriteLine("R.Madhavan flop prob=" + mFProb);
return
(mHProb + " " + mFProb);//break;
case
4://Ranbir Kapur...................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][0].Equals("Ranbir
Kapur") && film[i][5].Equals("Hit"))
ranbirH++;
else if
(film[i][0].Equals("Ranbir Kapur")
&& film[i][5].Equals("Flop"))
ranbirF++;
}
if
(film[i][0].Equals("Ranbir Kapur")
&& film[i][5].Equals("Hit"))
ranbirH++;
else
if (film[i][0].Equals("Ranbir
Kapur") && film[i][5].Equals("Flop"))
ranbirF++;
Console.WriteLine("Ranbir Kapur hit =" + ranbirH);
Console.WriteLine("Total hit ="+HitCount());
rHProb = ranbirH /
HitCount();
rFProb = ranbirF /
FlopCount();
Console.WriteLine("Ranbir Kapur hit prob=" + rHProb);
Console.WriteLine("Ranbir Kapur flop prob=" + rFProb);
return(rHProb+" "+rFProb);//break;
case
5://Vir Das..........................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][0].Equals("Vir
Das") && film[i][5].Equals("Hit"))
virH++;
else if
(film[i][0].Equals("Vir Das")
&& film[i][5].Equals("Flop"))
virF++;
}
if
(film[i][0].Equals("Vir Das")
&& film[i][5].Equals("Hit"))
virH++;
else
if (film[i][0].Equals("Vir
Das") && film[i][5].Equals("Flop"))
virF++;
Console.WriteLine("Vir Das hit =" + virH);
Console.WriteLine("Total hit ="+HitCount());
vHProb = virH /
HitCount();
vFProb = virF / FlopCount();
Console.WriteLine("Vir Das hit prob=" + vHProb);
Console.WriteLine("Vir Das flop prob=" + vFProb);
return(vHProb+" "+vFProb);//break;
case
6://Salman Khan.....................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][0].Equals("Salman
Khan") && film[i][5].Equals("Hit"))
salmanH++;
else if
(film[i][0].Equals("Salman Khan")
&& film[i][5].Equals("Flop"))
salmanF++;
}
if
(film[i][0].Equals("Salman Khan")
&& film[i][5].Equals("Hit"))
salmanH++;
else
if (film[i][0].Equals("Salman
Khan") && film[i][5].Equals("Flop"))
salmanF++;
Console.WriteLine("Salman Khan hit =" + salmanH);
Console.WriteLine("Total hit ="+HitCount());
sHProb = salmanH /
HitCount();
sFProb = salmanF /
FlopCount();
Console.WriteLine("Salman Khan hit prob=" + sHProb);
Console.WriteLine("Salman Khan flop prob=" + sFProb);
return(sHProb+" "+sFProb);//break;
case
7://Abhiskekh Bachchan........................
for (i = 0;
i < (film.Length - 1); i++)
{
if (film[i][0].Equals("Abhishek
Bachchan") && film[i][5].Equals("Hit"))
abhiH++;
else if
(film[i][0].Equals("Abhishek Bachchan")
&& film[i][5].Equals("Flop"))
abhiF++;
}
if
(film[i][0].Equals("Abhishek Bachchan")
&& film[i][5].Equals("Hit"))
abhiH++;
else
if (film[i][0].Equals("Abhishek
Bachchan") && film[i][5].Equals("Flop"))
abhiF++;
Console.WriteLine("Abhishek Bachchan hit =" + abhiH);
Console.WriteLine("Total hit ="+HitCount());
abHProb = abhiH /
HitCount();
abFProb = abhiF /
FlopCount();
Console.WriteLine("Abhishek Bachchan hit prob=" +
abHProb);
Console.WriteLine("Abhishek Bachchan flop prob=" +
abFProb);
return(abHProb+" "+abFProb);//break;
} return
" ";
}
/*Console.WriteLine("..........................Actress........................");*/
public void Result()
{
string
actor = ActorProb();
string
actress = ActoressProb();
string[]
s=actor.Split(' ');
string[]
s1 = actress.Split(' ');
float
ah=float.Parse(s[0]);
float
af = float.Parse(s[1]);
float
ash = float.Parse(s1[0]);
float
asf = float.Parse(s1[1]);
Console.WriteLine("ah="+ah);
Console.WriteLine("af="+af);
Console.WriteLine("ash=" + ash);
Console.WriteLine("asf=" + asf);
float
fh = ah * ash * HitProb();
float
ff = af * asf * FlopProb();
Console.WriteLine("fh=" + fh);
Console.WriteLine("ff=" + ff);
if(fh>ff)
Console.WriteLine("Film will be HIT");
else
Console.WriteLine("Film will be FLOP");
}
public string ActoressProb()
{
int
ch;
Console.WriteLine("1:Anushka Sharma\t2:Kangana\t3:Priyanka
Chopra\n4:Karina Kapur\t5:Aishwarya\t6:Jackqueline");
Console.WriteLine("Select one of Actress=> ");
ch = Int32.Parse(Console.ReadLine());
switch
(ch)
{
case
1://Anushka Sharma.......................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][1].Equals("Anushka
Sharma") && film[i][5].Equals("Hit"))
anuH++;
else
if (film[i][1].Equals("Anushka
Sharma") && film[i][5].Equals("Flop"))
anuF++;
}
if
(film[i][1].Equals("Anushka Sharma")
&& film[i][5].Equals("Hit"))
anuH++;
else
if (film[i][1].Equals("Anushka
Sharma") && film[i][5].Equals("Flop"))
anuF++;
Console.WriteLine("Anushka Sharma hit =" + anuH);
Console.WriteLine("Total hit ="+HitCount());
anuHProb = anuH /
HitCount();
anuFProb = anuF /
FlopCount();
Console.WriteLine("Anushka Sharma hit prob=" + anuHProb);
Console.WriteLine("Anushka Sharma flop prob=" + anuFProb);
return(anuHProb+" "+anuFProb);//break;
case
2://Kangana.....................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][1].Equals("Kangana")
&& film[i][5].Equals("Hit"))
kH++;
else if
(film[i][1].Equals("Kangana")
&& film[i][5].Equals("Flop"))
kF++;
}
if
(film[i][1].Equals("Kangana")
&& film[i][5].Equals("Hit"))
kH++;
else
if (film[i][1].Equals("Kangana")
&& film[i][5].Equals("Flop"))
kF++;
Console.WriteLine("Kangana hit =" + kH);
Console.WriteLine("Total hit ="+HitCount());
kHProb = kH /
HitCount();
kFProb = kF /
FlopCount();
Console.WriteLine("Kangana hit prob=" + kHProb);
Console.WriteLine("Kangana flop prob=" + kFProb);
return(kHProb+" "+kFProb);//break;
case
3://Priyanka Chopra..........................
for (i = 0; i < (film.Length - 1); i++)
{
if (film[i][1].Equals("Priyanka
Chopra") && film[i][5].Equals("Hit"))
priyaH++;
else if
(film[i][1].Equals("Priyanka Chopra")
&& film[i][5].Equals("Flop"))
priyaF++;
}
if (film[i][1].Equals("Priyanka
Chopra") && film[i][5].Equals("Hit"))
priyaH++;
else if (film[i][1].Equals("Priyanka Chopra") &&
film[i][5].Equals("Flop"))
priyaF++;
Console.WriteLine("Priyanka
Chopra hit =" + priyaH);
Console.WriteLine("Total hit ="+HitCount());
priyaHProb = priyaH /
HitCount();
priyaFProb = priyaF /
FlopCount();
Console.WriteLine("Priyanka Chopra hit prob=" +
priyaHProb);
Console.WriteLine("Priyanka Chopra flop prob=" +
priyaFProb);
return(priyaHProb+" "+priyaFProb);//break;
case
4://Karina Kapur.......................................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][1].Equals("Karina
Kapur") && film[i][5].Equals("Hit"))
karinaH++;
else if
(film[i][1].Equals("Karina Kapur")
&& film[i][5].Equals("Flop"))
karinaF++;
}
if
(film[i][1].Equals("Karina Kapur")
&& film[i][5].Equals("Hit"))
karinaH++;
else
if (film[i][1].Equals("Karina
Kapur") && film[i][5].Equals("Flop"))
karinaF++;
Console.WriteLine("Karina Kapur hit =" + karinaH);
Console.WriteLine("Total hit ="+HitCount());
karinaHProb = karinaH /
HitCount();
karinaFProb = karinaF /
FlopCount();
Console.WriteLine("Karina Kapur hit prob=" + karinaHProb);
Console.WriteLine("Karina Kapur flop prob=" +
karinaFProb);
return(karinaHProb+" "+karinaFProb);//break;
case
5://Aishwarya....................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][1].Equals("Aishwarya")
&& film[i][5].Equals("Hit"))
aishH++;
else if
(film[i][1].Equals("Aishwarya")
&& film[i][5].Equals("Flop"))
aishF++;
}
if
(film[i][1].Equals("Aishwarya")
&& film[i][5].Equals("Hit"))
aishH++;
else
if (film[i][1].Equals("Aishwarya")
&& film[i][5].Equals("Flop"))
aishF++;
Console.WriteLine("Aishwarya hit =" + aishH);
Console.WriteLine("Total hit ="+HitCount());
aishHProb = aishH /
HitCount();
aishFProb = aishF /
FlopCount();
Console.WriteLine("Aishwarya Kapur hit prob=" +
aishHProb);
Console.WriteLine("Aishwarya Kapur flop prob=" +
aishFProb);
return(aishHProb+" "+aishFProb);//break;
case
6://Jacqualin........................................
for
(i = 0; i < (film.Length - 1); i++)
{
if (film[i][1].Equals("Jackueline")
&& film[i][5].Equals("Hit"))
jacH++;
else if
(film[i][1].Equals("Jackueline")
&& film[i][5].Equals("Flop"))
jacF++;
}
if
(film[i][1].Equals("Jackueline")
&& film[i][5].Equals("Hit"))
jacH++;
else
if (film[i][1].Equals("Jackueline")
&& film[i][5].Equals("Flop"))
jacF++;
Console.WriteLine("Jackueline hit =" + jacH);
Console.WriteLine("Total hit ="+HitCount());
jacHProb = jacH /
HitCount();
jacFProb = jacF /
FlopCount();
Console.WriteLine("Jackueline hit prob=" + jacHProb);
Console.WriteLine("Jackueline flop prob=" + jacFProb);
return(jacHProb+" "+jacFProb);//break;
} return
" ";
}
}
class Program
{
static void Main(string[]
args)
{
try
{
Film
f = new Film();
f.Result();
//f.ActorProb();
Console.WriteLine("HitProb="+f.HitProb());
Console.WriteLine("FlopProb="+f.FlopProb());
//f.ActoressProb();
//f.ActorCount();
//f.ActoressCount();
}
catch
(Exception e)
{
Console.WriteLine("Eaception: "+e);
}
/*int a,
b, c;
a =
Int32.Parse(Console.ReadLine());
b = Int32.Parse(Console.ReadLine());
c = a + b;
Console.WriteLine("\nhit={0}",f.HitProb());
Console.WriteLine("\nflop={0}", f.FlopProb());*/
}
}
}
program for k mean
================================================================
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
k_mean
{
class Program
{
static void Main(string[] args)
{
int[] c = new int[20];
int[] e = new int[100];
int[,] clst = new int[50, 50];
int cn, en, temp = 0, t = 0, i, j;
Console.WriteLine("Enter
number of elements=>");
en = Int32.Parse(Console.ReadLine().Trim());
Console.WriteLine("Enter
elements=>");
for (i = 0; i < en; i++)
e[i] =
Int32.Parse(Console.ReadLine().Trim());
Console.WriteLine("You
entered=>");
for (i = 0; i < en; i++)
Console.WriteLine("e[" + i + "]=" + e[i]);
Console.WriteLine("Enter
number of cluster=>");
cn =
Int32.Parse(Console.ReadLine().Trim());
for (i = 0; i < cn; i++)
c[i] = e[i];
Console.WriteLine("centers=>\n");
for (i = 0; i < cn; i++)
Console.WriteLine("c[" + i + "]=" + c[i]);
for (i = 0; i < en; i++)
{
Console.WriteLine("_______________i=" + i);
for (j = 0; j < cn; j++)
{
Console.WriteLine("-------------j=" + j);
if (j == 0)
{
temp = Math.Abs(c[j] -
e[i]);
t = e[i];
Console.WriteLine("**********"
+ temp);
Console.WriteLine("....e[" + i + "]=" + e[i]);
}
else
{
if (temp >=
Math.Abs(c[j] - e[i]))
{
temp =
Math.Abs(c[j] - e[i]);
t = e[i];
Console.WriteLine("********" + temp);
Console.WriteLine(".......ee[" + i + "]=" + e[i]);
}
}
clst[j, i] = t;
Console.WriteLine("clst" + 1 + "," + j +
"j=" + clst[i, j]);
Console.ReadLine();
}
}
}
}
}
***************OUTPUT********************
Enter
number of ele
3
Enter
elements=>
50
51
52
You
entered=>
e[0]=50
e[1]=51
e[2]=52
Enter
number of clu
2
centers=>
c[0]=50
c[1]=51
_______________i=0
-------------j=0
**********0
....e[0]=50
clst1,0j=50
-------------j=1
clst1,1j=0
_______________i=1
-------------j=0
**********1
....e[1]=51
clst1,0j=50
-------------j=1
********0
.......ee[1]=51
clst1,1j=51
_______________i=2
-------------j=0
**********2
....e[2]=52
clst1,0j=0
-------------j=1
********1
.......ee[2]=52
clst1,1j=0
program for precision ,recall,F_measure metrics
==============================================================================
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
precision_recall
{
class Program
{
static void Main(string[] args)
{
float tp, fp, tn, fn, f, recall,
pre, av;
Console.WriteLine("Enter the
values of tp,tn,fp,fn=>");
tp = float.Parse(Console.ReadLine().Trim());
tn=
float.Parse(Console.ReadLine().Trim());
fp=
float.Parse(Console.ReadLine().Trim());
fn =
float.Parse(Console.ReadLine().Trim());
av = (tp + tn) / (tp + tn + fn +
fp);
recall = tp / (tp + fn);
pre = tp / (tp + fp);
f = (2 * recall * pre) / 2 * pre *
recall;
Console.WriteLine("Accuracy=" + av);
Console.WriteLine("\nRecall=" + recall);
Console.WriteLine("\nPrecision="
+ pre);
Console.WriteLine("F_measure=" + f);
Console.ReadLine();
}
}
}
*************OUTPUT*************
Enter the
values of tp,tn,fp,fn=>
2
3
4
5
Accuracy=0.3571429
Recall=0.2857143
Precision=0.3333333
F_measure=0.009070296
***program to count word frequency***
===========================================================================
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.IO;
namespace
WordFrequencyCount
{
class Program
{
static void Main(string[] args)
{
int freq,total=0;
String
text=File.ReadAllText(@"D:\\xyz.txt").ToLower();
String
delimator=",./;:?!-\n\t";
String[]
Words=text.Split(delimator.ToCharArray());
String[]
AllWords=Words.Distinct().ToArray<String>();
foreach(String str in AllWords)
{
freq=0;
for(int
i=0;i<Words.Length;i++)
{
if(str.Equals(Words[i]))
{
freq++;
total++;
}
}
Console.WriteLine(str+"
:"+freq+"\n");
}
Console.WriteLine("Total No of
words:"+total);
Console.ReadKey();
}
}
}
/*Output:-
:1fghjk
zxcvbn :1
Total No of
words:2 */
**Count the No. of Articles(the,an,a) in given
input File...
------------------------------------------------------------------------------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.IO;
using
System.Text;
namespace
VowelCount
{
class Program
{
static void Main(string[] args)
{
int
countthe=0,counta=0,countan=0,counttotal=0;
String text =
File.ReadAllText(@"F:\\xyz.txt").ToLower();
String delimator="
,.:;!?-\n\t"; // For Spliting
String[] Worlds =
text.Split(delimator.ToCharArray());
//convert string to CharArray()
Console.WriteLine(text);
foreach(String str in Worlds)
{
if (str =="the")
{
countthe++;
counttotal++;
}
else if (str == "an")
{
countan++;
counttotal++;
}
else if (str == "a")
{
counta++;
counttotal++;
}
}
Console.WriteLine("Total No of
Articles:"+counttotal);
Console.WriteLine("No of
(the/The):"+countthe);
Console.WriteLine("No of
(a/A):"+counta);
Console.WriteLine("No of
(an/An):" + countan);
Console.ReadKey();
}
}
}
************Consonant Count*****************
-----------------------------------------------------------------------------------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.IO;
using
System.Text.RegularExpressions;
using
System.Text;
namespace
CountConsonant
{
class Program
{
static void Main(string[] args)
{
String text =
File.ReadAllText(@"F:\\xyz.txt").ToLower();
int total =
text.Count("bcdfghjklmnpqrstvwxyz".Contains);
Console.WriteLine("Total
Consonants: " + total);
Console.WriteLine("b
:"+text.Count("b".Contains));
Console.WriteLine("c :" +
text.Count("c".Contains));
Console.WriteLine("d :" +
text.Count("d".Contains));
Console.WriteLine("f :" +
text.Count("f".Contains));
Console.WriteLine("g :" +
text.Count("g".Contains));
Console.WriteLine("h :" +
text.Count("h".Contains));
Console.WriteLine("j :" +
text.Count("j".Contains));
Console.WriteLine("k :" +
text.Count("k".Contains));
Console.WriteLine("l :" +
text.Count("l".Contains));
Console.WriteLine("m :" +
text.Count("m".Contains));
Console.WriteLine("n :" +
text.Count("n".Contains));
Console.WriteLine("p :" +
text.Count("p".Contains));
Console.WriteLine("q :" +
text.Count("q".Contains));
Console.WriteLine("r :" +
text.Count("r".Contains));
Console.WriteLine("s :" +
text.Count("s".Contains));
Console.WriteLine("t :" +
text.Count("t".Contains));
Console.WriteLine("v :" +
text.Count("v".Contains));
Console.WriteLine("w :" +
text.Count("w".Contains));
Console.WriteLine("x :" +
text.Count("x".Contains));
Console.WriteLine("y :" +
text.Count("y".Contains));
Console.WriteLine("z :" +
text.Count("z".Contains));
Console.ReadKey();
}
}
}
*******Vowels Counts *******
-----------------------------------------------------------------------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.IO;
namespace
MyVowelCount
{
class Program
{
static void Main(string[] args)
{
int a = 0, e = 0, i = 0, o = 0, u =
0;
String text =
File.ReadAllText(@"F:\\xyz.txt").ToLower();
int
total=text.Count("aeiou".Contains);
foreach (char ch in text)
{
if (ch == 'a')
a++;
else if (ch == 'e')
e++;
else if (ch == 'i')
i++;
else if (ch == 'o')
o++;
else if (ch == 'u')
u++;
}
Console.WriteLine("Total
Vowels:"+total);
Console.WriteLine("No. of
<a/A> : "+a);
Console.WriteLine("No. of
<e/E> : "+e);
Console.WriteLine("No. of
<i/I> : " +i);
Console.WriteLine("No. of
<u/U> : " +u);
Console.WriteLine("No. of
<o/O> : " +o);
Console.ReadKey();
}
}
}
*************line and Words count*****************
--------------------------------------------------------------------------------------------------------------------
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.IO;
namespace
LineWordsCount
{
class Program
{
static void Main(string[] args)
{
int lcount =
File.ReadAllLines(@"F:\\xyz.txt").Length;
String text =
File.ReadAllText(@"F:\\xyz.txt");
String delimator = "
,.:!;?-\n\t";
String[] words =
text.Split(delimator.ToCharArray());
int wcount = words.Length;
Console.WriteLine("Total no of
Lines :" + lcount);
Console.WriteLine("Total no of
Words :"+wcount);
Console.ReadKey();
}
}
}
*************Words frequency count******************
-------------------------------------------------------------------------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.IO;
namespace
WordFrequencyCount
{
class Program
{
static void Main(string[] args)
{
int freq,total=0;
String text =
File.ReadAllText(@"F:\\xyz.txt").ToLower();
String delimator = "
,./;:?!-\n\t";
String[] Words =
text.Split(delimator.ToCharArray());
String[] AllWords =
Words.Distinct().ToArray<String>();
foreach (String str in AllWords)
{
freq = 0;
for (int i = 0; i <
Words.Length; i++)
{
if (str.Equals(Words[i]))
{
freq++;
total++;
}
}
Console.WriteLine(str+"
:"+freq+"\n");
}
Console.WriteLine("Total No of
Words :"+total);
Console.ReadKey();
}
}
}