jcreek.representation
Class SubModel

java.lang.Object
  extended byjcreek.representation.SubModel
Direct Known Subclasses:
ExplanationModel, Partition

public class SubModel
extends java.lang.Object

Represents a submodel of a knowledgemodel. This means a set of entities and relations. Each relation of entity may only exists once in the set. This class is not thread-safe.

Version:
2.0
Author:
Frode Sørmo

Constructor Summary
SubModel()
          Creates an empty submodel.
SubModel(Entity[] ents, Relation[] rels)
          Creates a new SubModel from an array of entities and relations to be included in the submodel.
 
Method Summary
 void add(Entity e)
          Adds an entity to the submodel.
 void add(Entity[] ents)
          Adds a set of entitites to the submodel.
 void add(Relation r)
          Adds a relation to the submodel.
 void add(Relation[] rels)
          Adds an array of relations to the submodel.
 void add(SubModel other)
          Adds all relations and entities in the supplied submodel to this submodel.
 void addExpanded(Relation r)
          Adds a relation, but if the relation is composite, the submodel of containing all relations of the composite structure is added instead.
 void addExpanded(Relation[] rels)
          Adds an array of relations to the submodel, but if the relation is composite, the submodel of containing all relations of the composite structure is added instead.
 void clear()
          Removes all contents (relations and entities) from the submodel.
 boolean contains(Entity ent)
          Returns true if the submodel contains the entity.
 boolean contains(Relation rel)
          Returns true if the submodel contains the relation.
 boolean contains(SubModel model)
          Returns true if model specified is submodel of this submodel, i.e. if all the entities and all of the relations of the specified model is also contained in this model.
 Entity[] getEntities()
          Returns an array of all the entities in the submodel.
 Relation[] getRelations()
          Returns an array of all the relations in the submodel.
 SubModel joinWith(SubModel other)
          Deprecated.  
 boolean remove(Entity r)
          Removes an entity from the submodel.
 boolean remove(Relation r)
          Removes a relation from the submodel.
 void remove(SubModel other)
          Removes all the relations and entities in the supplied model from this model.
 int size()
          Return the number of entities and relations in the submodel.
 java.util.Set toSet()
          Returns a Set that contains all the relations and entities in this model.
 java.lang.String toString()
           
 SubModel union(SubModel other)
          Changes this submodel to be the union of the specified model and this submodel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SubModel

public SubModel(Entity[] ents,
                Relation[] rels)
Creates a new SubModel from an array of entities and relations to be included in the submodel.


SubModel

public SubModel()
Creates an empty submodel.

Method Detail

add

public void add(Entity e)
Adds an entity to the submodel.

Parameters:
e - The entity to add.

add

public void add(Entity[] ents)
Adds a set of entitites to the submodel.

Parameters:
ents - The arrays of entities to add.

add

public void add(Relation r)
Adds a relation to the submodel.

Parameters:
r - The relation to add.

add

public void add(Relation[] rels)
Adds an array of relations to the submodel.

Parameters:
rels - The array of relations to add.

remove

public boolean remove(Relation r)
Removes a relation from the submodel. Return false if the relation is not present in the submodel.


addExpanded

public void addExpanded(Relation r)
Adds a relation, but if the relation is composite, the submodel of containing all relations of the composite structure is added instead.

Parameters:
r - The relation to (expand and) add.

addExpanded

public void addExpanded(Relation[] rels)
Adds an array of relations to the submodel, but if the relation is composite, the submodel of containing all relations of the composite structure is added instead.


remove

public boolean remove(Entity r)
Removes an entity from the submodel. Return false if the relation is not present in the submodel.


contains

public boolean contains(Entity ent)
Returns true if the submodel contains the entity.


contains

public boolean contains(Relation rel)
Returns true if the submodel contains the relation.


getEntities

public Entity[] getEntities()
Returns an array of all the entities in the submodel.


getRelations

public Relation[] getRelations()
Returns an array of all the relations in the submodel.


size

public int size()
Return the number of entities and relations in the submodel.


contains

public boolean contains(SubModel model)
Returns true if model specified is submodel of this submodel, i.e. if all the entities and all of the relations of the specified model is also contained in this model.


union

public SubModel union(SubModel other)
Changes this submodel to be the union of the specified model and this submodel. The specified model is not changed. I.e. this model will only contain the relations and entities contained in both models. A reference to this model will be returned.


add

public void add(SubModel other)
Adds all relations and entities in the supplied submodel to this submodel. The supplied submodel is not changed.

Parameters:
other - The submodel to add to this model.

joinWith

public SubModel joinWith(SubModel other)
Deprecated.  

Intersects the specified model with this model. This model will be changed to become the new submodel. The specified model will not be changed. I.e. this model will now contain all the relations and entities of both the specified model and this model. A reference to this model is returned. This method is deprecated because the name is really not descriptive. Use union(SubModel model) instead.


toSet

public java.util.Set toSet()
Returns a Set that contains all the relations and entities in this model.

Returns:
Set

remove

public void remove(SubModel other)
Removes all the relations and entities in the supplied model from this model. If some relations and entities did not exist in this model, nothing will be done. This model is effectively changed to be the intersection between the supplied model and this model before the remove() operation. The supplied model is not changed.

Parameters:
other - The model to intersect with this model.

clear

public void clear()
Removes all contents (relations and entities) from the submodel.


toString

public java.lang.String toString()


Created at IDI, NTNU by the Artificial Intelligence and Learning group