Search in sources :

Example 1 with IrcException

use of org.pircbotx.exception.IrcException in project narchy by automenta.

the class IRCAgent method main.

public static void main(String[] args) {
    // Param.DEBUG = true;
    // NARS.realtime().get();
    @NotNull NAR n = NARchy.ui();
    // newRealtimeNAR(1024, 25, 2);
    n.termVolumeMax.set(20);
    // Control c = n.getControl();
    // n.setControl(new ChainedControl(c) {
    // //            @Override
    // //            public void activate(Termed term, float priToAdd) {
    // //
    // //                synchronized(this) {
    // //                    System.out.print(term + " " + priToAdd + "\t===");
    // //                    super.activate(term, priToAdd);
    // //                    System.out.println(pri(term));
    // //                }
    // //            }
    // });
    IRCAgent bot = new IRCAgent(n, "experiment1", "irc.freenode.net", // "#123xyz"
    "#netention");
    n.onOpN("trace", (arg, nn) -> {
        if (arg.subs() > 0) {
            switch(arg.sub(0).toString()) {
                case "on":
                    bot.setTrace(true);
                    break;
                case "off":
                    bot.setTrace(false);
                    bot.out.clear();
                    break;
            }
        }
    });
    /*
        n.on("readToUs", (Command) (a, t, nn) -> {
            if (t.length > 0) {
                String url = $.unquote(t[0]);
                if (canReadURL(url)) {
                    try {

                        Term[] targets;
                        if (t.length > 1 && t[1] instanceof Compound) {
                            targets = ((Compound)t[1]).terms();
                        } else {
                            targets = null;
                        }

                        Collection<String> lines = IOUtil.readLines(new URL(url).openStream());

                        new RateIterator<String>(lines.iterator(), 2)
                                .threadEachRemaining(l -> {

                                    bot.hear(l, nn.self().toString());

                                    if (targets == null) {
                                        bot.broadcast(l);
                                    } else {
                                        for (Term u : targets)
                                            bot.send($.unquote(u), l);
                                    }

                                }).start();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        */
    /*

        try {
            new RateIterator<Task>(
                NQuadsRDF.stream(n,
                    new File("/home/me/Downloads/nquad")), 500)
                        .threadEachRemaining(n::inputLater).start();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        */
    // new NARWeb(n, 8080);
    n.startFPS(10f);
    try {
        bot.start();
    } catch (IOException | IrcException e) {
        e.printStackTrace();
    }
// nar.run(1);
}
Also used : IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) IrcException(org.pircbotx.exception.IrcException) NAR(nars.NAR)

Example 2 with IrcException

use of org.pircbotx.exception.IrcException in project narchy by automenta.

the class IRCNLP method main.

public static void main(String[] args) {
    // Param.DEBUG = true;
    float durFPS = 20f;
    NAR n = NARS.realtime(durFPS).get();
    n.activationRate.set(0.2f);
    n.forgetRate.set(1f);
    n.freqResolution.set(0.2f);
    n.confResolution.set(0.05f);
    n.termVolumeMax.set(48);
    /*@NotNull Default n = new Default(new Default.DefaultTermIndex(4096),
            new RealTime.DS(true),
            new TaskExecutor(256, 0.25f));*/
    // NARS n = new NARS(new RealTime.DS(true), new XorShift128PlusRandom(1), 1);
    // n.addNAR(16, 0.25f);
    // n.addNAR(512, 0.25f);
    // n.logBudgetMin(System.out, 0.75f);
    new Thread(() -> {
        try {
            new TextUI(n, 1024);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }).start();
    IRCNLP bot = new IRCNLP(n, // "exp" + Math.round(10000 * Math.random()),
    "nar" + Math.round(64 * 1024 * Math.random()), "irc.freenode.net", "#123xyz");
    Term HEAR = $.the("hear");
    // Param.DEBUG = true;
    n.onTask(t -> {
        // if (t.isGoal()) {
        // feedback
        Term tt = t.term();
        long start = t.start();
        if (start != ETERNAL) {
            if (t.isBeliefOrGoal()) /* BOTH */
            {
                long now = n.time();
                int dur = n.dur();
                if (start >= now - dur) {
                    if (tt.op() == INH && HEAR.equals(tt.sub(1))) {
                        if (tt.subIs(0, PROD) && tt.sub(0).subIs(0, Op.ATOM)) {
                            bot.speak(tt.sub(0).sub(0), start, t.truth());
                        }
                    }
                }
            }
        }
    });
    // n.log();
    // for (int i = 0; i < 2; i++) {
    // Hear.hear(n, "do you know what is a sentence?", "", 100, 0.5f);
    // Util.sleep(1000);
    // 
    // Hear.hear(n, "i know that and this is a sentence.", "", 100, 0.5f);
    // Util.sleep(1000);
    // }
    // n.clear();
    // new Loop(1 / 15f) {
    // 
    // final Term[] promptWord = new Term[]{
    // $.varDep(1),
    // $.quote("and"),
    // $.quote("a"),
    // $.quote("is"),
    // //$.quote("then")
    // /* so, now, etc */
    // };
    // 
    // @Override
    // public boolean next() {
    // try {
    // Term word = promptWord[n.random().nextInt(promptWord.length)];
    // n.input("$0.9 hear(" + word + "). :|:");
    // } catch (Narsese.NarseseException e) {
    // e.printStackTrace();
    // }
    // return true;
    // }
    // };
    NARHear.readURL(n);
    n.logPriMin(System.out, 0.9f);
    n.start();
    try {
        bot.start();
    } catch (IOException | IrcException e) {
        e.printStackTrace();
    }
// n.on("say", (x, aa, nn) -> {
// String msg = Joiner.on(' ').join(
// Stream.of(aa).map(t -> {
// if (t.op()== Op.VAR_DEP) {
// return "a";
// }
// return $.unquote(t);
// }).toArray()
// );
// 
// System.out.println(Arrays.toString(aa));
// 
// if (!bot.prevOut.contains(msg)) {
// bot.out.commit();
// bot.out.put(new PLink<String>(msg, 1f));
// }
// });
// 
// //n.log();
// //n.logBudgetMin(System.out, 0.6f);
// //n.log(System.out, x -> x instanceof Task && ((Task)x).isGoal());
// 
// n.input(
// "( (RANGE:{$range} && SENTENCE:$x) ==> SENTENCE:slice($x, $range)).",
// 
// //"((VERB:{$V} && FRAG($X,$V,$Y)) ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).",
// 
// //"((FRAG:$XY && ($XY <-> flat((FRAG($X), and, FRAG($Y))))) <=> ((/,MEANS,$X,_) && (/,MEANS,$Y,_))).",
// 
// //                "((VERB:{$V} && SENTENCE($X,$V))                   ==> (((/,MEANS,$X,_),(/,MEANS,$X,_)) --> (/,MEANS,$V,_))).",
// //                "((VERB:{$V} && SENTENCE($X,$V,$Y))                ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).",
// //                "((&&, VERB:{$V}, ADV:{$A}, SENTENCE($X,$V,$A,$Y)) ==> (((/,MEANS,$X,_),(/,MEANS,$Y,_)) --> (/,MEANS,($V|$A),_))).",
// //                "((&&, VERB:{$V}, PREP:{$P}, SENTENCE($X,$V,$P,$Y)) ==> (((/,MEANS,$X,_),$P,(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).",
// //                "((&&, VERB:{$V}, DET:{#a}, SENTENCE($X,$V,#a,$Y)) ==> (((/,MEANS,$X,_),{(/,MEANS,$Y,_)}) --> (/,MEANS,$V,_))).",
// //                "((&&, VERB:{$V}, DET:{#a}, SENTENCE(#a,$X,$V,$Y)) ==> (({(/,MEANS,$X,_)},(/,MEANS,$Y,_)) --> (/,MEANS,$V,_))).",
// 
// "(SENTENCE($x,\"is\",$y) <=> ($x --> $y)).",
// "(SENTENCE($x,\"is\",\"a\",$y) <=> ({$x} --> $y)).",
// "(SENTENCE($x,\"has\",$y) <=> ($x --> [$y])).",
// "(SENTENCE($x,\"isnt\",$y) <=> (--,($x --> $y))).",
// "(SENTENCE($x,\"and\",$y,\"are\",$z) <=> (($x & $y)-->$z)).",
// "(SENTENCE($x,\"and\",$y) <=> ($x && $y)).",
// "(SENTENCE($x,\"or\",$y) <=> ($x || $y)).",
// "(SENTENCE($x,\"then\",$y) <=> ($x &&+1 $y)).",
// "(SENTENCE($x,\"after\",$y) <=> ($x &&-1 $y)).",
// "(($x --> \"verb\") <=> VERB:{$x}).",
// "(($x --> \"noun\") <=> NOUN:{$x}).",
// "(($x --> \"adverb\") <=> ADV:{$x}).",
// "(($x --> \"preposition\") <=> PREP:{$x}).",
// "(#x <-> \"it\"). %0.5;0.5%",
// "(#x <-> \"that\"). %0.5;0.5%",
// "(#x <-> \"the\"). %0.5;0.5%",
// "(#x <-> \"what\"). %0.5;0.5%",
// "(#x <-> \"who\"). %0.5;0.5%",
// "(#x <-> \"where\"). %0.5;0.5%",
// "(#x <-> \"which\"). %0.5;0.5%",
// 
// //NAL9 integration
// "(believe <-> \"believe\").",
// "(wonder <-> \"wonder\").",
// "(want <-> \"want\").",
// 
// //"((WHERE_PREP:{#in} && FRAG(#in,$where)) ==> WHERE:(/,MEANS,$where,_))."
// 
// //"(FRAG<->SENTENCE).", //sentence is also its own fragment
// 
// "RANGE:{(0,2),(0,3),(1,4)}.",
// //"RANGE:{(0,3),(1,4),(4,7),(0,7)}.",
// //"RANGE:{(0,3)}.",
// //"RANGE:{0,1,2,3,4,(0,1),(0,2),(0,3)}.",
// 
// "VERB:{\"is\",\"maybe\",\"isnt\",\"was\",\"willBe\",\"wants\",\"can\",\"likes\"}.",
// "DET:{\"a\",\"the\"}.",
// "PREP:{\"for\",\"on\",\"in\",\"with\"}.",
// "ADV:{\"never\",\"always\",\"maybe\"}.",
// 
// //                "SENTENCE(tom,is,never,sky).",
// //                "SENTENCE(tom,is,always,cat).",
// //                "SENTENCE(tom,is,cat).",
// //                "SENTENCE(tom,is,a,cat).",
// //                "SENTENCE(tom,likes,the,sky).",
// //                "SENTENCE(tom,likes,maybe,cat).",
// //                "SENTENCE(the,sky,is,blue).",
// //                "SENTENCE(a,cat,likes,blue).",
// //                "SENTENCE(sky,wants,the,blue).",
// //                "SENTENCE(sky,is,always,blue).",
// //
// //            "SENTENCE(yes,wants,no).",
// //            "SENTENCE(yes,is,no).",
// //            "SENTENCE(yes,isnt,no).",
// //
// //            "SENTENCE(it,is,my,good).",
// //            //"SENTENCE(it,is,bad,and,it,can,good).",
// //            "SENTENCE(good,was,bad).",
// //            "SENTENCE(right,willBe,wrong).",
// //            "SENTENCE(true,can,false).",
// 
// 
// 
// //"$0.9$ (?y --> (/,MEANS,?x,_))?",
// 
// //"$0.9$ SENTENCE(?z,?x,?y)?"
// 
// //"$0.9$ SENTENCE(?y)?",
// 
// //"$0.9 (VERB:{$v} ==> say(DO, $v))."
// //"$0.9 say(#y)!",
// 
// "$0.9 (SENTENCE:$y ==> say:$y).",
// "$0.9 (SENTENCE:#y && say:#y)!"
// //"say(cat,is,blue)!",
// //"say(#x,is,#y)!"
// 
// 
// );
}
Also used : IOException(java.io.IOException) Term(nars.term.Term) IrcException(org.pircbotx.exception.IrcException)

Aggregations

IOException (java.io.IOException)2 IrcException (org.pircbotx.exception.IrcException)2 NAR (nars.NAR)1 Term (nars.term.Term)1 NotNull (org.jetbrains.annotations.NotNull)1