|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcreek.representation.AbstractKnowledgeModel
jcreek.representation.LocalKnowledgeModel
The KnowledgeModel is the main interface to the model of entities and relations. As the entities can be compared to a node and a relation to an edge, the KnowledgeModel can be thought of as the graph containing these nodes and edges. The LocalKnowledgeModel class implements a KnowledgeModel where all the data is read from a binary or XML file and stored permanently in memory until explicitly saved by using the various save() commands. It can be accessed concurrently by multiple threads (it is thread safe), but this is done by only allowing one thread to do any access to the model at a time.
Field Summary | |
protected java.lang.String |
author
The author of the KnowledgeModel |
protected java.lang.String |
description
A description of this current Knowledge Model. |
protected boolean |
dirty
Marks if this model has been changed since last save. |
protected java.io.File |
file
File to read and write to. |
protected LRUCache |
inferenceCache
|
protected java.lang.String |
name
The name of the Knowledge Model. |
protected java.lang.String |
title
The title of the knowledgemodel. |
Fields inherited from class jcreek.representation.AbstractKnowledgeModel |
modelChangeListeners |
Constructor Summary | |
LocalKnowledgeModel()
Create a new, empty knowledge model. |
|
LocalKnowledgeModel(EpistemologicalModel epistemologicalModel)
Creates a new knowledge model based on the epistemological model supplied. |
|
LocalKnowledgeModel(java.io.File file)
Creates a new KnowledgeModel instance by loading it from the file supplied. |
|
LocalKnowledgeModel(java.io.InputStream input)
Creates a new KnowledgeModel instance by loading it from the supplied stream. |
|
LocalKnowledgeModel(KnowledgeModel model)
Creates a new KnowledgeModel by importing the contents of the supplied model. |
|
LocalKnowledgeModel(java.lang.String filename)
Creates a new KnowledgeModel instance by loading it from the filename supplied. |
Method Summary | |
void |
addContext(Context c)
Registers a context with the KnowledgeModel. |
int |
entitySize()
Returns the number of entities in the model. |
void |
fireModelChangeEvent(ModelChangeEvent event)
Notifies the listeners that a change has occured in the model. |
java.lang.String |
getAuthor()
Returns the author of the model. |
Constraint |
getConstraint(java.lang.Object id)
Find a relation in the model with the given ID. |
java.util.Iterator |
getConstraintIterator()
Returns an iterator of all the constraints in the model. |
Context[] |
getContexts()
Returns an array of all registered contexts. |
Context[] |
getContexts(java.lang.Class c)
Returns all context object registrered with the KnowledgeModel that is of the Class given as a parameter to the method. |
java.lang.String |
getDescription()
Returns the description of the model. |
Entity |
getEntity(java.lang.Object id)
Find an entity in the model with the given name or ID. |
java.util.Iterator |
getEntityIterator()
Returns an iterator of all the entities in the model. |
java.io.File |
getFile()
Returns the file this KnowledgeModel is associated with (if any). |
LRUCache |
getInferenceCache()
Returns this models inference cache. |
java.lang.String |
getName()
Returns the name of the model. |
Partition |
getPartition(java.lang.Object id)
Returns the partition with the given name or ID. |
java.util.Iterator |
getPartitionIterator()
Returns an iterator for all the partitions in this KnowledgeModel. |
Relation |
getRelation(java.lang.Object id)
Find a relation in the model with the given ID. |
java.util.Iterator |
getRelationIterator()
Returns an iterator of all the realtions in the model. |
RelationType |
getRelationType(java.lang.String name)
Find a relation class in the model of the given name. |
java.lang.String |
getTitle()
Returns the title of the model. |
boolean |
hasContext(Context c)
Returns true if the give context is registred with the KnowledgeModel. |
boolean |
hasEntity(Entity entity)
Returns true if this model contains the supplied entity. |
boolean |
hasEntity(java.lang.Object id)
Returns true if an entity with the given name or id exists in the KnowledgeModel. |
boolean |
hasFile()
Returns true if this KnowledgeModel has a file associated with it. |
boolean |
hasPartition(java.lang.Object id)
Returns true if the KnowledgeModel contains a Partition with the given ID or name. |
boolean |
hasRelation(Relation relation)
Returns true if this model contains the supplied relation. |
boolean |
isDirty()
Returns true if this knowledgemodel has been changed since last save. |
void |
load()
Loads the model from the file associated with the model. |
void |
load(java.io.File file)
Loads a model from disk. |
void |
load(java.io.InputStream in)
Loads a model from a stream. |
void |
load(java.lang.String name)
Load a model from disk. |
static void |
main(java.lang.String[] argv)
|
ConstraintData |
makeConstraint()
Creates a new data object for storing data for Constraint. |
EntityData |
makeEntity()
Creates a new data object for storing data for an Entity. |
PartitionData |
makePartition()
Creates a new data object for storing data for a Partition. |
RelationData |
makeRelation(Entity from,
Entity type,
Entity value)
Creates a new data object for storing data for a Relation. |
void |
registerEntity(java.lang.String id,
Entity ent)
Indexes a given entity with the given id. |
void |
registerPartition(java.lang.String name,
Partition partition)
Registers a partition under the given name in this models partition index. |
void |
reindex()
Recreates the relation type index. |
int |
relationSize()
Returns the number of relations in the model. |
void |
removeContext(Context c)
Removes the given context from this KnowledgeModel. |
void |
save()
Saves this document (the data) to the associated disk file. |
void |
saveAs(java.io.File file)
Saves this knowledgemodel (the data) to a new file, and hereinafter is associated with this new file. |
void |
saveAs(java.lang.String name)
Saves the model to disk. |
void |
setAuthor(java.lang.String authorName)
Sets the author of the model. |
void |
setDescription(java.lang.String description)
Sets description of model. |
void |
setFile(java.io.File file)
Sets the file this KnowledgeModel is associated with. |
void |
setName(java.lang.String name)
Sets name of model. |
void |
setTitle(java.lang.String title)
Sets title of model. |
void |
unregisterEntity(java.lang.String name)
Removes the index with the given name from the entity index. |
void |
unregisterPartition(java.lang.String name)
Unregisters an index entry from the parition index. |
Methods inherited from class jcreek.representation.AbstractKnowledgeModel |
addModelChangeListener, getConstraints, getEntities, getPartitions, getRelations, importModel, matchEntityType, mergeModel, removeModelChangeListener |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected transient LRUCache inferenceCache
protected java.lang.String name
protected java.lang.String description
protected java.lang.String title
protected transient java.io.File file
protected transient boolean dirty
protected java.lang.String author
Constructor Detail |
public LocalKnowledgeModel(EpistemologicalModel epistemologicalModel)
public LocalKnowledgeModel()
public LocalKnowledgeModel(java.lang.String filename) throws java.io.IOException, java.lang.ClassNotFoundException
public LocalKnowledgeModel(java.io.File file) throws java.io.IOException, java.lang.ClassNotFoundException
public LocalKnowledgeModel(java.io.InputStream input) throws java.io.IOException, java.lang.ClassNotFoundException
public LocalKnowledgeModel(KnowledgeModel model)
model
- The KnowledgeModel to import.Method Detail |
public void setName(java.lang.String name)
setName
in interface KnowledgeModel
name
- The name of the model.public java.lang.String getName()
getName
in interface KnowledgeModel
public void setDescription(java.lang.String description)
setDescription
in interface KnowledgeModel
description
- The description of the model.public java.lang.String getDescription()
getDescription
in interface KnowledgeModel
public void setTitle(java.lang.String title)
setTitle
in interface KnowledgeModel
title
- The title of the model.public static void main(java.lang.String[] argv)
public java.lang.String getTitle()
getTitle
in interface KnowledgeModel
public java.lang.String getAuthor()
getAuthor
in interface KnowledgeModel
public void setAuthor(java.lang.String authorName)
setAuthor
in interface KnowledgeModel
authorName
- The name of the author.public void setFile(java.io.File file)
file
- file objectpublic java.io.File getFile()
public boolean hasFile()
public Entity getEntity(java.lang.Object id)
getEntity
in interface KnowledgeModel
id
- The name (String) or identifier (Object) for an entity
public Relation getRelation(java.lang.Object id)
getRelation
in interface KnowledgeModel
id
- The unique identifier for this relation.public RelationType getRelationType(java.lang.String name)
getRelationType
in interface KnowledgeModel
getRelationType
in class AbstractKnowledgeModel
name
- The name of the relation class to be found
public void registerEntity(java.lang.String id, Entity ent) throws NameAlreadyExistException
registerEntity
in interface KnowledgeModel
id
- The name of theent
- The Concept object.
NameAlreadyExistException
public void unregisterEntity(java.lang.String name)
unregisterEntity
in interface KnowledgeModel
name
- The name (key) of the index entry to remove.public boolean hasEntity(java.lang.Object id)
hasEntity
in interface KnowledgeModel
id
- The key of the concept.public boolean hasEntity(Entity entity)
entity
- The entity to check if exists in the model.public boolean hasRelation(Relation relation)
relation
- The relation to check if exists in the model.public int entitySize()
entitySize
in interface KnowledgeModel
public int relationSize()
relationSize
in interface KnowledgeModel
public java.util.Iterator getEntityIterator()
getEntityIterator
in interface KnowledgeModel
public java.util.Iterator getRelationIterator()
getRelationIterator
in interface KnowledgeModel
public EntityData makeEntity()
makeEntity
in interface KnowledgeModel
public RelationData makeRelation(Entity from, Entity type, Entity value)
makeRelation
in interface KnowledgeModel
from
- The Entity this relation is from (the origin).value
- The Entity this relation is to (the target).type
- The Entity that represents the type of the relation.public PartitionData makePartition() throws NameAlreadyExistException
makePartition
in interface KnowledgeModel
NameAlreadyExistException
public void registerPartition(java.lang.String name, Partition partition) throws NameAlreadyExistException
registerPartition
in interface KnowledgeModel
name
- The name (key) to register the partition under.partition
- The Partition to register under this name.
NameAlreadyExistException
public void unregisterPartition(java.lang.String name)
unregisterPartition
in interface KnowledgeModel
name
- The name of the index entry to remove.public boolean hasPartition(java.lang.Object id)
hasPartition
in interface KnowledgeModel
id
- The name (string) or id of a partition to test for.public java.util.Iterator getPartitionIterator()
getPartitionIterator
in interface KnowledgeModel
public Partition getPartition(java.lang.Object id)
getPartition
in interface KnowledgeModel
id
- The name or ID of the partition to return.public ConstraintData makeConstraint()
makeConstraint
in interface KnowledgeModel
public Constraint getConstraint(java.lang.Object id)
getConstraint
in interface KnowledgeModel
id
- The unique identifier for this relation.public java.util.Iterator getConstraintIterator()
getConstraintIterator
in interface KnowledgeModel
public void save() throws java.io.IOException
java.io.IOException
public void saveAs(java.io.File file) throws java.io.IOException
file
- new file to save to
java.io.IOException
public void saveAs(java.lang.String name) throws java.io.IOException
name
- The filename of the model.
java.io.IOException
public void load(java.lang.String name) throws java.lang.ClassNotFoundException, java.io.IOException
name
- The filename of the model (without extension)
java.lang.ClassNotFoundException
java.io.IOException
public void load(java.io.File file) throws java.lang.ClassNotFoundException, java.io.IOException
file
- The file representing the model.
java.lang.ClassNotFoundException
java.io.IOException
public void load(java.io.InputStream in) throws java.lang.ClassNotFoundException, java.io.IOException
in
- Loads from the stream in.
java.lang.ClassNotFoundException
java.io.IOException
public void reindex()
public void load() throws java.lang.ClassNotFoundException, java.io.IOException
java.lang.ClassNotFoundException
java.io.IOException
public void addContext(Context c)
addContext
in interface KnowledgeModel
public Context[] getContexts()
getContexts
in interface KnowledgeModel
public Context[] getContexts(java.lang.Class c)
getContexts
in interface KnowledgeModel
public void removeContext(Context c)
removeContext
in interface KnowledgeModel
public boolean hasContext(Context c)
hasContext
in interface KnowledgeModel
public boolean isDirty()
public LRUCache getInferenceCache()
getInferenceCache
in interface KnowledgeModel
public void fireModelChangeEvent(ModelChangeEvent event)
fireModelChangeEvent
in interface KnowledgeModel
event
- The event object reporting this change.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |