i need your help urgently finishing my program below. The program is for showing how the semantic network works. the program reads from the text file then when user inputs a question it outputs answer related to the network. i have attached the txt file( semantic.txt)
if the user enters a code in any of the following format the program will read #3 and output corresponding data
/*
* ?:?:?
* 1:?:?
* ?:1:?
* ?:?:1
* 1:1:?
* 1:?:1
* ?:1:1
* 1:1:1 true / false
*/
i.e if 10:?:?
output
<pre lang="css">10:4:11
10:3:12
10:2:13
10:1:14
</pre>
please help me change my code. thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
using ConsoleApplication1;
namespace trial1
{
class Program
{
static void Main(string[] args)
{
StreamReader streamReader = new StreamReader("D:\\semantic.txt");
int block = 0;
while (!streamReader.EndOfStream)
{
string line = streamReader.ReadLine().Trim();
if (line.CompareTo("") == 0)
{
continue;
}
if (line.CompareTo("#1") == 0)
{
Console.WriteLine("We have #1");
block = 1;
continue;
}
if (line.CompareTo("#2") == 0)
{
Console.WriteLine("\n\nWe have #2");
block = 2;
continue;
}
if (line.CompareTo("#3") == 0)
{
Console.WriteLine("\n\nWe have #3");
block = 3;
continue;
}
if (block == 1)
{
string[] first = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (first.Length == 2)
{
int code = Convert.ToInt32(first[0].Trim());
string name = first[1].Trim();
Console.WriteLine("code = {0}, name = '{1}'", code, name);
}
}
if (block == 2)
{
string[] second = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (second.Length == 3)
{
int code = Convert.ToInt32(second[0].Trim());
string connector = second[1].Trim();
int code2 = Convert.ToInt32(second[2].Trim());
Console.WriteLine("code = {0}, connector = '{1}', code2 = {2}", code, connector, code2);
}
}
if (block == 3)
{
string[] third = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (third.Length == 3)
{
int name = Convert.ToInt32(third[0].Trim());
int code2 = Convert.ToInt32(third[1].Trim());
int name1 = Convert.ToInt32(third[2].Trim());
Console.WriteLine("name = {0}, code2 = {1}, name1 = {2}", name, code2, name1);
}
}
}
streamReader.Close();
StreamReader Reader = new StreamReader("D:\\semantic.txt");
string text = Reader.ReadToEnd();
// THE THIRD BLOCK
int x = text.IndexOf("#3");
string z = text.Substring(x + 2);
int k = Convert.ToInt32("23");
//VERIFY
Console.WriteLine("\n\nEnter the code for verification.");
string str = Console.ReadLine();
string [] str1 = str.Split(' ');
foreach (string input in str1)
{
if (z.Contains(input))
{
Console.WriteLine(z.Contains(input));
int th = z.IndexOf(input);
int thr = z.LastIndexOf(input);
Console.WriteLine(z.Substring(th, thr-th));
}
else
{
Console.WriteLine(z.Contains(input));
}
}
Console.ReadLine();
}
}
}