Search in sources :

Example 21 with Task

use of nars.entity.Task in project opennars by opennars.

the class Name method execute.

/**
 * To create a judgment with a given statement
 * @param args Arguments, a Statement followed by an optional tense
 * @param memory The memory in which the operation is executed
 * @return Immediate results as Tasks
 */
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory memory) {
    Term compound = args[1];
    Term atomic = args[2];
    Similarity content = Similarity.make(compound, atomic);
    // a naming convension
    TruthValue truth = new TruthValue(1, 0.9999f);
    Sentence sentence = new Sentence(content, Symbols.JUDGMENT_MARK, truth, new Stamp(memory));
    BudgetValue budget = new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_JUDGMENT_DURABILITY, truth);
    return Lists.newArrayList(new Task(sentence, budget, true));
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Similarity(nars.language.Similarity) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 22 with Task

use of nars.entity.Task in project opennars by opennars.

the class SwingLogText method print.

// public class TaskIcon extends NCanvas {
// 
// public TaskIcon() {
// super();
// setMaximumSize(new Dimension(50,10));
// setPreferredSize(new Dimension(50,10));
// setSize(50,10);
// 
// Graphics2D g = getBufferGraphics();
// 
// showBuffer(g);
// }
// 
// 
// 
// }
protected int print(Class c, Object o) {
    float priority = 1f;
    if (c != OUT.class) {
        // pad the channel name to max 6 characters, right aligned
        String n = c.getSimpleName();
        // n = n.substring(0,Math.min(4, n.length()));
        switch(n.length()) {
            case 0:
                break;
            case 1:
                n = "   " + n;
                break;
            case 2:
                n = "  " + n;
                break;
            case 3:
                n = " " + n;
                break;
        }
        Color chanColor = Video.getColor(c.getClass().hashCode(), 0.8f, 0.8f);
        print(chanColor, n);
    } else {
        if (o instanceof Task) {
            Task t = (Task) o;
            Sentence s = t.sentence;
            if (s != null) {
                priority = t.budget.getPriority();
                // printColorBlock(LogPanel.getPriorityColor(priority), "  ");
                TruthValue tv = s.truth;
                if (tv != null) {
                    float evidence = TruthFunctions.c2w(tv.getConfidence());
                    float pos_2 = tv.getConfidence() * tv.getFrequency();
                    float positive_evidence_in_0_1 = TruthFunctions.w2c(evidence * tv.getFrequency());
                    float negative_evidence_in_0_1 = TruthFunctions.w2c(evidence * (1.0f - tv.getFrequency()));
                    printColorBlock(LogPanel.getPositiveEvidenceColor(positive_evidence_in_0_1), "  ");
                    printColorBlock(LogPanel.getNegativeEvidenceColor(negative_evidence_in_0_1), "  ");
                } else if (t.getBestSolution() != null) {
                    float evidence = TruthFunctions.c2w(t.getBestSolution().truth.getConfidence());
                    float pos_2 = t.getBestSolution().truth.getConfidence() * t.getBestSolution().truth.getFrequency();
                    float positive_evidence_in_0_1 = TruthFunctions.w2c(evidence * t.getBestSolution().truth.getFrequency());
                    float negative_evidence_in_0_1 = TruthFunctions.w2c(evidence * (1.0f - t.getBestSolution().truth.getFrequency()));
                    // printColorBlock(LogPanel.getStatementColor('=', priority, t.getBestSolution().truth.get), "    ");
                    printColorBlock(LogPanel.getPositiveEvidenceColor(positive_evidence_in_0_1), "  ");
                    printColorBlock(LogPanel.getNegativeEvidenceColor(negative_evidence_in_0_1), "  ");
                } else {
                    printColorBlock(LogPanel.getStatementColor(s.punctuation, priority), "    ");
                }
            }
        }
    }
    CharSequence text = LogPanel.getText(c, o, showStamp, nar);
    StringBuilder sb = new StringBuilder(text.length() + 2);
    sb.append(' ');
    if (text.length() > maxLineWidth)
        sb.append(text.subSequence(0, maxLineWidth));
    else
        sb.append(text);
    if (sb.charAt(sb.length() - 1) != '\n')
        sb.append('\n');
    if (o instanceof Task) {
        Task t = (Task) o;
        int color = 128;
        Concept cc = nar.memory.concept(t.getTerm());
        color = (int) Math.min(255.0f, 80.0f + t.getPriority() * 255.0f);
        Color col = new Color(color, color, color);
        if (cc != null) {
            color = (int) (128.0f + cc.getPriority() * 128.0f);
            print(col, sb.toString(), new ConceptAction(cc));
            return doc.getLength();
        }
        print(col, sb.toString());
        return doc.getLength();
    }
    // float tc = 0.75f + 0.25f * priority;
    // Color textColor = new Color(tc,tc,tc);
    String s = sb.toString();
    print(Color.GRAY, sb.toString());
    return doc.getLength();
}
Also used : Concept(nars.entity.Concept) Task(nars.entity.Task) TruthValue(nars.entity.TruthValue) Color(java.awt.Color) Sentence(nars.entity.Sentence)

Example 23 with Task

use of nars.entity.Task in project opennars by opennars.

the class TaskTree method run.

@Override
public void run() {
    for (Task t : toRemove) {
        DefaultMutableTreeNode node = nodes.get(t);
        if (node != null) {
            TreeNode p = node.getParent();
            node.removeFromParent();
            needRefresh.add(p);
            needRefresh.remove(node);
        }
        nodes.remove(t);
        components.remove(t);
        toAdd.remove(t);
    }
    for (Task t : toAdd) {
        // t.getParentTask();
        Task parent = null;
        if (parent != null && parent.equals(t)) {
            // System.err.println(t + " has parentTask equal to itself");
            parent = null;
        }
        DefaultMutableTreeNode tnode = getNode(t);
        if (tnode != null) {
            continue;
        }
        tnode = newNode(t);
        if (parent == null) {
            // System.out.println(tnode + " add to root");
            root.add(tnode);
            needRefresh.add(root);
        } else {
            DefaultMutableTreeNode pnode = getNode(parent);
            if (pnode != null) {
                // System.out.println(tnode + "Adding to: " + pnode);
                if (tnode.getParent() != null) {
                    // pnode.isNodeAncestor(tnode)) {
                    tnode.removeFromParent();
                }
                pnode.add(tnode);
                needRefresh.add(pnode);
            } else {
                // missing parent, reparent to root?
                // System.out.println(tnode + " add to root by default");
                root.add(tnode);
                needRefresh.add(root);
            }
        }
    }
    for (TaskLabel t : components.values()) t.updateTask();
    for (TreeNode t : needRefresh) model.reload(t);
    needRefresh.clear();
    toAdd.clear();
    toRemove.clear();
    repaint();
    lastUpdateTime = System.currentTimeMillis();
}
Also used : Task(nars.entity.Task) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 24 with Task

use of nars.entity.Task in project opennars by opennars.

the class SentenceGraph method event.

@Override
public void event(final Class event, final Object[] a) {
    if (event == Events.ConceptForget.class) {
        // remove all associated beliefs
        Concept c = (Concept) a[0];
        // create a clone of the list for thread safety
        for (Task b : new ArrayList<Task>(c.beliefs)) {
            remove(b.sentence);
        }
    } else if (event == Events.ConceptBeliefAdd.class) {
        Concept c = (Concept) a[0];
        Sentence s = ((Task) a[1]).sentence;
        if (c.getPriority() > minConceptPri.get()) {
            add(s, c);
        }
    } else if (event == Events.ConceptBeliefRemove.class) {
        Concept c = (Concept) a[0];
        Sentence s = (Sentence) a[1];
        remove(s);
    } else /*else if (event == Events.ConceptGoalAdd.class) {
            Concept c = (Concept)a[0];
            Sentence s = ((Task)a[1]).sentence;
            add(s, c);
        }
        else if (event == Events.ConceptGoalRemove.class) {
            Concept c = (Concept)a[0];
            Sentence s = (Sentence)a[1];
            remove(s);
        }*/
    if (event == Events.CyclesEnd.class) {
        if (needInitialConcepts)
            getInitialConcepts();
    } else if (event == Events.ResetEnd.class) {
        reset();
    }
}
Also used : Concept(nars.entity.Concept) Task(nars.entity.Task) Events(nars.io.events.Events) ArrayList(java.util.ArrayList) Sentence(nars.entity.Sentence)

Example 25 with Task

use of nars.entity.Task in project opennars by opennars.

the class CircleLayout method vertex.

@Override
public void vertex(AbstractGraphVis<Item, Object> g, VertexVis<Item, Object> v) {
    Item vertex = v.getVertex();
    float priority = vertex.getPriority();
    double radius = (1.0 - priority) * spacing + 8;
    boolean task = false;
    Concept x = null;
    if (vertex instanceof Concept) {
        x = (Concept) vertex;
    } else if (vertex instanceof Task) {
        task = true;
        x = nar.memory.concept(((Task) vertex).getTerm());
    }
    float angle = ((arcStop - arcStart) * Video.hashFloat(x.hashCode()) + arcStart) * ((float) Math.PI * 2f);
    v.tx = (float) (Math.cos(angle) * radius) * spacing;
    v.ty = (float) (Math.sin(angle) * radius) * spacing;
    if (task) {
        v.ty += spacing * Video.hashFloat(vertex.hashCode());
    }
}
Also used : Concept(nars.entity.Concept) Item(nars.entity.Item) Task(nars.entity.Task)

Aggregations

Task (nars.entity.Task)78 Sentence (nars.entity.Sentence)54 Term (nars.language.Term)37 BudgetValue (nars.entity.BudgetValue)36 TruthValue (nars.entity.TruthValue)34 Stamp (nars.entity.Stamp)25 CompoundTerm (nars.language.CompoundTerm)21 Concept (nars.entity.Concept)18 Conjunction (nars.language.Conjunction)11 Statement (nars.language.Statement)10 Events (nars.io.events.Events)8 Inheritance (nars.language.Inheritance)8 Interval (nars.language.Interval)8 Narsese (nars.io.Narsese)6 SetExt (nars.language.SetExt)6 SetInt (nars.language.SetInt)6 ArrayList (java.util.ArrayList)5 DerivationContext (nars.control.DerivationContext)5 Implication (nars.language.Implication)5 Memory (nars.storage.Memory)5