Declarativa Declarativa
 

 

Entrada

Produtos

Serviços

Inquiridor
Aplicações internet à medida
Auditoria informática
Subcontratação para I&D

Plataforma de conteúdos

Tecnologia

Web Information Systems
Web Application Maker
InterProlog

A empresa

Apresentação institucional

com.declarativa.interprolog
Class TermModel

java.lang.Object
  extended bycom.declarativa.interprolog.TermModel
All Implemented Interfaces:
Serializable, TreeModel

public class TermModel
extends Object
implements Serializable, TreeModel

Represents a Prolog term, as a tree of TermModel objects, each containing a term node and a children list. Implements TreeModel, therefore easily supporting display in a JTree. It includes the funcionality of Prolog's Edinburgh syntax write within toString(); if you wish to reflect operator declarations dynamically you should provide a different PrologOperatorsContext object

See Also:
Serialized Form

Field Summary
 TermModel[] children
          public for convenience, but should not be set outside this class; children == null means children == new TermModel[0]
static int listMaxLength
           
 Object node
          public for convenience, but should not be set outside this class
 TermModel root
          The TermModel containing this; relevant to define variable scope.
 
Constructor Summary
TermModel()
           
TermModel(int n)
           
TermModel(Object n)
           
TermModel(Object n, boolean isAList)
           
TermModel(Object n, TermModel[] c)
           
TermModel(Object n, TermModel[] c, boolean isAList)
           
TermModel(Object n, Vector v)
           
 
Method Summary
 void addChildren(TermModel[] more)
          Add children to this term node; a new children array is created and old children are copied to it
 void addTermModelListener(TermModelListener l)
          Start notifying listener l of changes to this term.
 void addTreeModelListener(TreeModelListener l)
           
 void assignTermChanges(TermModel other)
          Assuming this and the other terms are structurally similar, replaces variable nodes in this term by corresponding nonvar nodes.
 void assignToVar(VariableNode v, Object value)
          Replaces all occurrences of v in this subterm by value, using setNodeValue
 Object clone()
          Clones by serialization, to keep variable bindings; these should form a closed graph within this term, otherwise the new term instance would contain dangling references
 void deleteChildren(int[] less)
          Delete children with specified indexes; a new children array is created and old children are copied to it
 void deleteChildren(TermModel[] less)
          Removes the children in array; it finds children to remove by using the equivalent of Prolog's ==.
 boolean equals(Object x)
          True if both terms are structurally similar with equal nodes
static ObjectExamplePair example()
           
static TreePath findPathForNode(String label, TermModel tree, boolean exactMatch)
           
 void fireTermChanged()
           
 TermModel[] flatList()
          Flattens this list into a new TermModel array, but not completely: the result may still contain lists
static TermModel[] flatList(TermModel list)
          Flattens a list into a TermModel array, but not completely: the result may still contain lists
 Object getChild(int index)
           
 Object getChild(Object parent, int index)
           
 int getChildCount()
           
 int getChildCount(Object parent)
           
 TermModel[] getChildren()
           
 String getFunctorArity()
          Return a node/arity String
 int getIndexOfChild(Object parent, Object child)
           
 Object getRoot()
           
 String getTemplate()
          Return a Node(_,..._) String
 int intValue()
          Returns node object as an int, assuming it is a Number
 boolean isAtom()
           
 boolean isInteger()
           
 boolean isLeaf()
           
 boolean isLeaf(Object node)
           
 boolean isList()
          May be an empty list
 boolean isListEnd()
           
 boolean isNumber()
           
 boolean isRoot()
          This node is its own root
 boolean isVar()
           
 String listToString(PrologOperatorsContext ops)
           
 Vector makeIntegerVector()
          Assuming this is a list of numbers, returns a Vector containing one Integer for each number in the list
static TermModel makeList(TermModel[] terms)
           
static TermModel makeList(Vector terms)
           
 boolean nodeIsVar()
           
static Hashtable props2Hashtable(TermModel[] terms)
           
 void removeTermModelListener(TermModelListener l)
           
 void removeTreeModelListener(TreeModelListener l)
           
 void setChild(int index, TermModel child)
          Set the child, notifying TermModelListeners
 void setChildren(TermModel[] c)
          Set the children array, notifying TermModelListeners
 void setNodeValue(Object v)
          Set the node, notifying TermModelListeners
 void setRoot()
          Set the root variables of nodes in this subterm to refer this term node as their root
 void setRoot(TermModel r)
          Set the root variables of nodes in this subterm to refer r as their root
 String toString()
           
 String toString(PrologEngine engine)
           
 String toString(PrologOperatorsContext ops)
           
 boolean unifies(TermModel term)
          Returns true if the term is (would be) unifiable with this.
 void valueForPathChanged(TreePath path, Object newValue)
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

node

public Object node
public for convenience, but should not be set outside this class


children

public TermModel[] children
public for convenience, but should not be set outside this class; children == null means children == new TermModel[0]


root

public transient TermModel root
The TermModel containing this; relevant to define variable scope. For this to contain the root, the root TermModel must have been messaged once with setRoot()


listMaxLength

public static final int listMaxLength
See Also:
Constant Field Values
Constructor Detail

TermModel

public TermModel()

TermModel

public TermModel(Object n)

TermModel

public TermModel(Object n,
                 TermModel[] c)

TermModel

public TermModel(Object n,
                 boolean isAList)

TermModel

public TermModel(Object n,
                 TermModel[] c,
                 boolean isAList)

TermModel

public TermModel(int n)

TermModel

public TermModel(Object n,
                 Vector v)
Method Detail

example

public static ObjectExamplePair example()

clone

public Object clone()
Clones by serialization, to keep variable bindings; these should form a closed graph within this term, otherwise the new term instance would contain dangling references


equals

public boolean equals(Object x)
True if both terms are structurally similar with equal nodes


setNodeValue

public void setNodeValue(Object v)
Set the node, notifying TermModelListeners


setChild

public void setChild(int index,
                     TermModel child)
Set the child, notifying TermModelListeners


setChildren

public void setChildren(TermModel[] c)
Set the children array, notifying TermModelListeners


getChildren

public TermModel[] getChildren()

addChildren

public void addChildren(TermModel[] more)
Add children to this term node; a new children array is created and old children are copied to it


deleteChildren

public void deleteChildren(int[] less)
Delete children with specified indexes; a new children array is created and old children are copied to it


deleteChildren

public void deleteChildren(TermModel[] less)
Removes the children in array; it finds children to remove by using the equivalent of Prolog's ==. All "matching" terms will be removed


assignToVar

public void assignToVar(VariableNode v,
                        Object value)
Replaces all occurrences of v in this subterm by value, using setNodeValue


assignTermChanges

public void assignTermChanges(TermModel other)
Assuming this and the other terms are structurally similar, replaces variable nodes in this term by corresponding nonvar nodes. If either a (this) node is non var or a (other) node is var, (this) node is left untouched.


setRoot

public void setRoot()
Set the root variables of nodes in this subterm to refer this term node as their root


setRoot

public void setRoot(TermModel r)
Set the root variables of nodes in this subterm to refer r as their root


isRoot

public boolean isRoot()
This node is its own root


getTemplate

public String getTemplate()
Return a Node(_,..._) String


getFunctorArity

public String getFunctorArity()
Return a node/arity String


getRoot

public Object getRoot()
Specified by:
getRoot in interface TreeModel
See Also:
TreeModel

getChild

public Object getChild(Object parent,
                       int index)
Specified by:
getChild in interface TreeModel
See Also:
TreeModel

getChildCount

public int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel
See Also:
TreeModel

isLeaf

public boolean isLeaf(Object node)
Specified by:
isLeaf in interface TreeModel
See Also:
TreeModel

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Specified by:
valueForPathChanged in interface TreeModel
See Also:
TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Specified by:
getIndexOfChild in interface TreeModel
See Also:
TreeModel

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Specified by:
addTreeModelListener in interface TreeModel
See Also:
TreeModel

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Specified by:
removeTreeModelListener in interface TreeModel
See Also:
TreeModel

getChild

public Object getChild(int index)

getChildCount

public int getChildCount()

isLeaf

public boolean isLeaf()

addTermModelListener

public void addTermModelListener(TermModelListener l)
Start notifying listener l of changes to this term. The term is considered changed iff either a node or children is set to a different object; a nonreported change is the setting of a same object as node/children, not the setting of an "equals" object


removeTermModelListener

public void removeTermModelListener(TermModelListener l)

fireTermChanged

public void fireTermChanged()

findPathForNode

public static TreePath findPathForNode(String label,
                                       TermModel tree,
                                       boolean exactMatch)

makeList

public static TermModel makeList(TermModel[] terms)

makeList

public static TermModel makeList(Vector terms)

makeIntegerVector

public Vector makeIntegerVector()
Assuming this is a list of numbers, returns a Vector containing one Integer for each number in the list


intValue

public int intValue()
Returns node object as an int, assuming it is a Number


toString

public String toString()

toString

public String toString(PrologOperatorsContext ops)

toString

public String toString(PrologEngine engine)

listToString

public String listToString(PrologOperatorsContext ops)

isListEnd

public boolean isListEnd()

isList

public boolean isList()
May be an empty list


isAtom

public boolean isAtom()

isNumber

public boolean isNumber()

isInteger

public boolean isInteger()

isVar

public boolean isVar()

nodeIsVar

public boolean nodeIsVar()

flatList

public TermModel[] flatList()
Flattens this list into a new TermModel array, but not completely: the result may still contain lists


flatList

public static TermModel[] flatList(TermModel list)
Flattens a list into a TermModel array, but not completely: the result may still contain lists


props2Hashtable

public static Hashtable props2Hashtable(TermModel[] terms)

unifies

public boolean unifies(TermModel term)
Returns true if the term is (would be) unifiable with this. Doesn't change the terms




 Declarativa - Serviços de Informática, Lda.
  www.declarativa.com, info@declarativa.com  fax: +351-22-030-1511  tel: +351-22-030-1580
UPTEC - Parque de Ciência e Tecnologia da Universidade do Porto (GoogleMap)
Rua Actor Ferreira da Silva 100 4200-298 Porto Portugal