Search in sources :

Example 1 with NormalizedVariable

use of nars.term.var.NormalizedVariable in project narchy by automenta.

the class PrologCore method pterm.

// NARS term -> Prolog term
public static alice.tuprolog.Term pterm(final Term term) {
    if (term instanceof Compound) {
        Op op = term.op();
        alice.tuprolog.Term[] st = psubterms(((Compound) term));
        switch(op) {
            case IMPL:
                return new Struct(":-", st[1], st[0]);
            case CONJ:
                return new Struct(",", st);
            case NEG:
                return new Struct(/*"\\="*/
                "not", st);
            case PROD:
                // list
                return new Struct(st);
            case INH:
                Term pred = term.sub(1);
                if (pred.op() == ATOM) {
                    Term subj = term.sub(0);
                    if (subj.op() == PROD) {
                        alice.tuprolog.Term args = st[0];
                        return new Struct(wrapAtom(pred.toString()), args instanceof alice.tuprolog.Term ? Iterators.toArray(((Struct) st[0]).listIterator(), alice.tuprolog.Term.class) : new alice.tuprolog.Term[] { args });
                    }
                }
                break;
        }
        return new Struct(op.str, st);
    } else if (term instanceof NormalizedVariable) {
        switch(term.op()) {
            case VAR_QUERY:
            case VAR_PATTERN:
            // ?? as if atomic
            case VAR_DEP:
            case // ??
            VAR_INDEP:
                return new Var("_" + (((NormalizedVariable) term).anonNum()));
        }
    } else if (term instanceof Atomic) {
        return new Struct(wrapAtom(term.toString()));
    }
    throw new UnsupportedOperationException();
// //CharSequence s = termString(term);
// if (term instanceof Statement) {
// Statement i = (Statement)term;
// String predicate = classPredicate(i.getClass());
// alice.tuprolog.Term  subj = alice.tuprolog.Term (i.getSubject());
// alice.tuprolog.Term  obj = alice.tuprolog.Term (i.getPredicate());
// if ((subj!=null) && (obj!=null))
// return new Struct(predicate, subj, obj);
// }
// else if ((term instanceof SetTensional) || (term instanceof Product) /* conjunction */) {
// Compound s = (Compound)term;
// String predicate = classPredicate(s.getClass());
// alice.tuprolog.Term [] args = alice.tuprolog.Term s(s.term);
// if (args!=null)
// return new Struct(predicate, args);
// }
// //Image...
// //Conjunction...
// else if (term instanceof Negation) {
// alice.tuprolog.Term  np = alice.tuprolog.Term (((Negation)term).term[0]);
// if (np == null) return null;
// return new Struct("negation", np);
// }
// else if (term.getClass().equals(Variable.class)) {
// return getVariable((Variable)term);
// }
// else if (term.getClass().equals(Atom.class)) {
// return new Struct(pescape(term.toString()));
// }
// else if (term instanceof Compound) {
// //unhandled type of compound term, store as an atomic string
// //NOT ready yet
// if (allTerms) {
// return new Struct('_' + pescape(term.toString()));
// }
// }
// 
// return null;
}
Also used : Op(nars.Op) alice.tuprolog(alice.tuprolog) Compound(nars.term.Compound) NormalizedVariable(nars.term.var.NormalizedVariable) Atomic(nars.term.atom.Atomic) Term(nars.term.Term)

Aggregations

alice.tuprolog (alice.tuprolog)1 Op (nars.Op)1 Compound (nars.term.Compound)1 Term (nars.term.Term)1 Atomic (nars.term.atom.Atomic)1 NormalizedVariable (nars.term.var.NormalizedVariable)1