Search in sources :

Example 56 with Compound

use of nars.term.Compound in project narchy by automenta.

the class PremiseRuleTest method printTermRecursive.

@Test
public void printTermRecursive() throws Narsese.NarseseException {
    // PremiseRule r = (PremiseRule) p.term(onlyRule);
    // return rule(
    // r
    // );
    Compound y = (Compound) parse("(S --> P), --%S |- (P --> S), (Belief:Conversion, Info:SeldomUseful)").term();
    Terms.printRecursive(System.out, y);
}
Also used : Compound(nars.term.Compound) Test(org.junit.jupiter.api.Test)

Example 57 with Compound

use of nars.term.Compound in project narchy by automenta.

the class NLPGen method train.

private void train(String natural, Task t) {
    Compound pattern = (Compound) (index.get(t.term(), true).term());
    rules.add((tt, freq, conf, tense) -> {
        if (timeMatch(t, tense)) {
            if (Math.abs(t.freq() - freq) < 0.33f) {
                if (Math.abs(t.conf() - conf) < 0.33f) {
                    final String[] result = { null };
                    Unify u = new Unify(VAR_PATTERN, terminal.random(), Param.UnificationStackMax, terminal.matchTTLmean.intValue()) {

                        @Override
                        public void tryMatch() {
                            final String[] r = { natural };
                            xy.forEach((x, y) -> {
                                String var = x.toString();
                                if (!var.startsWith("%"))
                                    return;
                                // HACK conversion between normalized pattern vars and the vars used in the input pattern
                                var = String.valueOf(((char) (var.charAt(1) - '1' + 'A')));
                                r[0] = r[0].replace(var, y.toString());
                            });
                            result[0] = r[0];
                        }
                    };
                    u.unify(pattern, tt, true);
                    if (result[0] != null)
                        return result[0];
                }
            }
        }
        return null;
    });
}
Also used : Unify(nars.term.subst.Unify) Compound(nars.term.Compound)

Example 58 with Compound

use of nars.term.Compound in project narchy by automenta.

the class UnitCompoundTest method assertEqual.

static void assertEqual(Op o, Atomic x, Compound u) {
    Compound g = CachedCompound.the(o, new UnitSubterm(x));
    assertEquals(g.hashCode(), u.hashCode());
    assertEquals(g.hashCodeSubterms(), u.hashCodeSubterms());
    assertEquals(u, g);
    assertEquals(g, u);
    assertEquals(0, u.compareTo(g));
    assertEquals(0, g.compareTo(u));
    assertEquals(g.toString(), u.toString());
    assertTrue(Arrays.equals(TermKey.termByVolume(g).array(), TermKey.termByVolume(u).array()));
    assertTrue(Arrays.equals(IO.termToBytes(g), IO.termToBytes(u)));
}
Also used : UnitSubterm(nars.subterm.UnitSubterm) Compound(nars.term.Compound)

Aggregations

Compound (nars.term.Compound)58 Test (org.junit.jupiter.api.Test)38 Term (nars.term.Term)20 Unify (nars.term.subst.Unify)3 FasterList (jcog.list.FasterList)2 XorShift128PlusRandom (jcog.math.random.XorShift128PlusRandom)2 Op (nars.Op)2 PatternCompound (nars.derive.PatternCompound)2 PatternIndex (nars.index.term.PatternIndex)2 Atomic (nars.term.atom.Atomic)2 Variable (nars.term.var.Variable)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 alice.tuprolog (alice.tuprolog)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Prioritized (jcog.pri.Prioritized)1 Narsese (nars.Narsese)1