Ejemplo n.º 1
0
        public void Run(System.Collections.ArrayList str)
        {
            Regex rx = new Regex(@"([a-z][a-z0-9]*)\(([a-zA-Z0-9]+),?([a-zA-Z0-9]+)?\)");
            WorkingMemory wm = Laduj("rezolucja2.drl");
            int nf  = 0;
            int np = 0;
            string s;
            for (int i = str.Count-1; i > -1; i--) {
                s = str[i].ToString();
                nf = i;
                Match m = rx.Match(s);
                while (m.Success) {
                    GroupCollection gc = m.Groups;

                    if (gc[3].Value == "") {
                        Predykat p = new Predykat(gc[1].Value,gc[2].Value,nf,np);
                        Console.WriteLine("Nazwa: {0}, arg1: {1}, nf: {2}, np: {3}",p.nazwa,p.arg1,p.nf,p.np);
                        wm.assertObject(p);

                    }
                    else {
                        Predykat p = new Predykat(gc[1].Value,gc[2].Value,gc[3].Value,nf,np);
                        Console.WriteLine("Nazwa: {0}, arg1: {1}, arg2: {2}, nf: {3}, np: {4}",p.nazwa,p.arg1, p.arg2,p.nf,p.np);
                        wm.assertObject(p);
                    }
                    np ++;
                    m = m.NextMatch();
                }
                Predykat e = new Predykat("__end",nf,np); // znacznik konca klauzuli
                wm.assertObject(e);
                np = 0;
                //nf++;
            }
            wm.assertObject(new Vars(0,0));
            wm.fireAllRules();
        }
Ejemplo n.º 2
0
        public void Run()
        {
            Regex rx = new Regex(@"([a-z][a-z0-9]*)\(([a-zA-Z0-9]+),?([a-zA-Z0-9]+)?\)");
            WorkingMemory wm = Laduj("rezolucja2.drl");
            string[] str = {"lubi(ola,ela),hmm(B,G)","lubi(G,H),kolezanki(G,H),costam(H,G)"};
            int nf  = 0;
            int np = 0;
            foreach (string s in str) {
                Match m = rx.Match(s);
                while (m.Success) {
                    GroupCollection gc = m.Groups;

                    if (gc[3].Value == "") {
                        Predykat p = new Predykat(gc[1].Value,gc[2].Value,nf,np);
                        Console.WriteLine("Nazwa: {0}, arg1: {1}, nf: {2}, np: {3}",p.symbol,p.arg1,p.nf,p.np);
                        if (p.var1)
                        {
                            Console.WriteLine("zmienna");
                        }
                        else {
                            Console.WriteLine("stala");
                        }
                        wm.assertObject(p);

                    }
                    else {
                        Predykat p = new Predykat(gc[1].Value,gc[2].Value,gc[3].Value,nf,np);
                        Console.WriteLine("Nazwa: {0}, arg1: {1}, arg2: {2}, nf: {3}, np: {4}",p.symbol,p.arg1, p.arg2,p.nf,p.np);
                        wm.assertObject(p);
                    }
                    np ++;
                    m = m.NextMatch();
                }
                Predykat e = new Predykat("__end",nf,np);
                wm.assertObject(e);
                np = 0;
                nf++;
            }
            wm.assertObject(new Vars(0,0));
            wm.fireAllRules();
        }