Пример #1
0
        /*
         * static final String[] rules = { "$s = ' ';",
         * "$noun = dog | house | government | wall | street | zebra;",
         * "$adjective = red | glorious | simple | nasty | heavy | clean;",
         * "$article = quickly | oddly | silently | boldly;",
         * "$adjectivePhrase = ($adverb $s)? 50% $adjective* 0% 30% 20% 10%;",
         * "$nounPhrase = $articles $s ($adjectivePhrase $s)? 30% $noun;",
         * "$verb = goes | fishes | walks | sleeps;",
         * "$tverb = carries | lifts | overturns | hits | jumps on;",
         * "$copula = is 30% | seems 10%;",
         * "$sentence1 = $nounPhrase $s $verb $s ($s $adverb)? 30%;",
         * "$sentence2 = $nounPhrase $s $tverb $s $nounPhrase ($s $adverb)? 30%;",
         * "$sentence3 = $nounPhrase $s $copula $s $adjectivePhrase;",
         * "$conj = but | and | or;",
         * "$sentence4 = $sentence1 | $sentence2 | $sentence3 20% | $sentence4 $conj $sentence4 20%;"
         * , "$sentence = $sentence4 '.';"};
         */
        /*
         * private static void testEnglish() { Pick s = Pick.unquoted(" "); Pick
         * verbs = Pick.or(new String[]{"goes", "fishes", "walks", "sleeps"}); Pick
         * transitive = Pick.or(new String[]{"carries", "lifts", "overturns",
         * "hits", "jumps on"}); Pick nouns = Pick.or(new String[]{"dog", "house",
         * "government", "wall", "street", "zebra"}); Pick adjectives = Pick.or(new
         * String[]{"red", "glorious", "simple", "nasty", "heavy", "clean"}); Pick
         * articles = Pick.or(new String[]{"the", "a"}); Pick adverbs = Pick.or(new
         * String[]{"quickly", "oddly", "silently", "boldly"}); Pick adjectivePhrase
         * = Pick.and(0.5, Pick.and(adverbs).and2(s)).and2(adjectives); Pick
         * nounPhrase = Pick.and(articles).and2(s) .and2(0.3,
         * Pick.and(adjectivePhrase).and2(s)) .and2(nouns); Pick copula =
         * Pick.or(new String[]{"is", "seems"}); Pick sentence1 =
         * Pick.and(nounPhrase).and2(s).and2(verbs) .and2(0.3,
         * Pick.and(s).and2(adverbs)).name("s1"); Pick sentence2 =
         * Pick.and(nounPhrase).and2(s).and2(transitive).and2(s).and2(nounPhrase)
         * .and2(0.3, Pick.and(s).and2(adverbs)).name("s2"); Pick sentence3 =
         * Pick.and
         * (nounPhrase).and2(s).and2(copula).and2(s).and2(adjectivePhrase).name
         * ("s3"); Pick conj = Pick.or(new String[]{", but", ", and", ", or"}); Pick
         * forward = Pick.unquoted("forward"); Pick pair =
         * Pick.and(forward).and2(conj).and2(s).and2(forward).name("part"); Pick
         * sentenceBase =
         * Pick.or(sentence1).or2(sentence2).or2(sentence3).or2(0.6666,
         * pair).name("sentence"); sentenceBase.replace(forward, sentenceBase); Pick
         * sentence = Pick.and(sentenceBase).and2(Pick.unquoted(".")); Pick.Target
         * target = Pick.Target.make(sentence); for (int i = 0; i < 50; ++i) {
         * System.out.println(i + ": " + target.next()); } } private static void
         * testOr(Pick p, int count) { Pick.Target target = Pick.Target.make(p);
         * Counts counts = new Counts(count + 10); for (int i = 0; i < 1000; ++i) {
         * String s = target.next(); counts.inc(s.length()); } counts.show(); }
         * private static void testCodePoints(Pick p) { Pick.Target target =
         * Pick.Target.make(p); Counts counts = new Counts(128); for (int i = 0; i <
         * 10000; ++i) { String s = target.next(); counts.inc(s.charAt(0)); }
         * counts.show(); }
         */
        public static void PrintRandoms()
        {
            BNF bnf = new BNF(new Random(0), new Quoter.RuleQuoter()).AddRules(
                "[a-z]{2,5}").Complete();

            System.Console.Out.WriteLine("Start");
            for (int i = 0; i < 100; ++i)
            {
                String temp = bnf.Next();
                System.Console.Out.WriteLine(i + ")\t" + temp);
            }
        }
Пример #2
0
        static internal void TestBNFMthd(String rules, UnicodeSet chars, int count)
        {
            BNF bnf = new BNF(new Random(0), new Quoter.RuleQuoter())
                      .AddSet("$chars", chars).AddRules(rules).Complete();

            System.Console.Out.WriteLine("====================================");
            System.Console.Out.WriteLine("BNF");
            System.Console.Out.WriteLine(rules);
            System.Console.Out.WriteLine(bnf.GetInternal());
            for (int i = 0; i < count; ++i)
            {
                System.Console.Out.WriteLine(i + ": " + bnf.Next());
            }
        }