Exemplo n.º 1
0
            static void Main(string[] args)
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Invalid args! Press any key to continue.");
                    Console.ReadKey();
                    return;
                }

                ruleprob = new RuleProb();

                StreamReader sr = new StreamReader(args[0]);
                StreamWriter sw = new StreamWriter(new FileStream(args[1], FileMode.Create));

                //String input1 = "(S(NP(DT The)(NN boy))(VP(VP(VBD saw)(NP(DT a)(NN girl)))(PP(IN with)(NP(DT a)(NN telescope)))))";
                //String input2 = "(S(NP(DT The)(NN girl))(VP(VBD saw)(NP(NP(DT a)(NN boy))(PP(IN with)(NP(DT a)(NN telescope))))))";

                Node head;

                while(!sr.EndOfStream)
                {
                    String input = sr.ReadLine();
                    head = ruleprob.readInput(input);
                    getRuleList(head);
                }

                sr.Close();

                rulelist = ruleprob.calcRuleProb();

                List<String> modelprob = new List<String>();
                for (int i = 0; i < rulelist.Count; i++ )
                {
                    Rule rule = rulelist[i];
                    String t;
                    if (rule.rChild == null)
                    {
                        t = rule.info + " # " + rule.lChild + " # " + rule.prob.ToString();
                    }
                    else
                    {
                        t = rule.info + " # " + rule.lChild + " "+ rule.rChild + " # " + rule.prob.ToString();
                    }
                    modelprob.Add(t);
                }

                modelprob.Sort();
                foreach (String t in modelprob)
                {
                    sw.WriteLine(t);
                }
                sw.Flush();
                sw.Close();
            }
Exemplo n.º 2
0
            static void Main(string[] args)
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Invalid args! Press any key to continue.");
                    Console.ReadKey();
                    return;
                }

                ruleprob = new RuleProb();

                readModel(args[0]);

                StreamReader sr = new StreamReader(args[1]);

                String input = sr.ReadLine();
                sr.Close();

                if (input == null)
                {
                    Console.WriteLine("Invalid test string! Press any key to continue.");
                    return;
                }

                StreamWriter sw = new StreamWriter(new FileStream(args[2], FileMode.Create));

                //String input = "A boy with a telescope saw a girl";
                //String input = "The boy saw a girl with a telescope";
                input = "0 " + input;

                chart = readChart(input);
                m = input.Split(' ').Length - 1;

                double prob = calcInnerProb(1, m, head);

                String output = maxProbTree(head);

                for (int i = 0; i < nodeProbList.Count; i++ )
                {
                    NodeProb np = nodeProbList[i];
                    np.outerProb = calcOuterProb(np.lIndex, np.rIndex, np.info);
                }

                List<String> outputList = new List<String>();
                for (int i = 0; i < nodeProbList.Count; i++ )
                {
                    String st = nodeProbList[i].info + " # " + nodeProbList[i].lIndex.ToString() + " # " + nodeProbList[i].rIndex + " # " + nodeProbList[i].innerProb.ToString() + " # " + nodeProbList[i].outerProb;
                    outputList.Add(st);
                }

                outputList.Sort();

                sw.WriteLine(output);
                sw.WriteLine(prob.ToString());

                //Console.WriteLine(output);
                //Console.WriteLine(prob.ToString());

                for (int i = 0; i < outputList.Count; i++ )
                {
                   //Console.WriteLine(outputList[i]);
                    sw.WriteLine(outputList[i]);
                }

                sw.Flush();
                sw.Close();
            }