Package jade.content.onto
Class Ontology
- java.lang.Object
-
- jade.content.onto.Ontology
-
- All Implemented Interfaces:
Serializable,Serializable
- Direct Known Subclasses:
BasicOntology,BeanOntology,BehaviourLoadingOntology,DFAppletOntology,ExceptionOntology,FIPAManagementOntology,IntrospectionOntology,JADEManagementOntology,JavaCollectionOntology,LogManagementOntology,MobilityOntology,PersistenceOntology,SerializableOntology,SLOntology
public class Ontology extends Object implements Serializable
An application-specific ontology describes the elements that agents can use within content of messages. It defines a vocabulary and relationships between the elements in such a vocabulary. The relationships can be:- structural, e.g., the predicate
fatherOfaccepts two parameters, a father and a set of children; - semantic, e.g., a concept of class
Manis also of classPerson.
Ontology.
An ontology is characterized by:- one name;
- one (or more) base ontology that it extends;
- a set of element schemas.
Peopleontology contains an element schema calledPerson. This schema states that aPersonis characterized by anameand by anaddress:ConceptSchema personSchema = new ConceptSchema(PERSON); personSchema.addSlot(NAME, stringSchema); personSchema.addSlot(ADDRESS, addressSchema, ObjectSchema.OPTIONAL);wherePERSON,NAMEandADDRESSare string constants. When you register your schema with the ontology, such constants become part of the vocabulary of the ontology.
Schemas that describe concepts support inheritance. You can define the conceptManas a refinement of the conceptPerson:ConceptSchema manSchema = new ConceptSchema(MAN); manSchema.addSuperSchema(personSchema);Each element schema can be associated with a Java class to map elements of the ontology that comply with a schema with Java objects of that class. The following is a class that might be associated with thePersonschema:public class Person extends Concept { private String name = null; private Address address = null; public void setName(String name) { this.name = name; } public void setAddress(Address address) { this.address = address; } public String getName() { return name; } public Address getAddress() { return address; } }When sending/receiving messages you can represent your content in terms of objects belonging to classes that the ontology associates with schemas.
As the previous example suggests, you cannot use objects of classPersonwhen asking for the value of some attribute, e.g., when asking for the value ofaddress. Basically, the problem is that you cannot 'assign' a variable to an attribute of an object, i.e. you cannot write something like:person.setName(new Variable("X")).
In order to solve this problem, you can describe your content in terms of abstract descriptors. An abstract descriptor is an object that reifies an element of the ontology. The following is the creation of an abstract descriptor for a concept of typeMan:AbsConcept absMan = new AbsConcept(MAN); absMan.setSlot(NAME, "John"); absMan.setSlot(ADDRESS, absAddress);whereabsAddressis the abstract descriptor for John's address:AbsConcept absAddress = new AbsConcept(ADDRESS); absAddress.setSlot(CITY, "London");Objects of classOntologyallows you to:- register schemas with associated (i) a mandatory term of the
vocabulary e.g.
NAMEand (ii) an optional Java class, e.g.Person; - retrieve the registered information through various keys.
BasicOntologyontology that provides all basic elements, i.e. primitive data types, aggregate types, etc. Application-specific ontologies should be implemented extending it.- Author:
- Federico Bergenti - Universita` di Parma, Giovanni Caire - TILAB
- See Also:
Concept,AbsConcept,ConceptSchema,BasicOntology, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Ontology(String name, Introspector introspector)Construct an Ontology object with a givennamethat uses a given Introspector to convert between Java objects and abstract descriptors.Ontology(String name, Ontology base)Construct an Ontology object with a givennamethat extends a given ontology.Ontology(String name, Ontology[] base, Introspector introspector)Construct an Ontology object with a givennamethat extends a given set of ontologies and that uses a given Introspector to convert between Java objects and abstract descriptors.Ontology(String name, Ontology base, Introspector introspector)Construct an Ontology object with a givennamethat extends a given ontology and that uses a given Introspector to convert between Java objects and abstract descriptors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(ObjectSchema schema)Adds a schema to this ontologyvoidadd(ObjectSchema schema, Class javaClass)Adds a schema to the ontology and associates it to the classjavaClassstatic voidcheckIsTerm(Object obj)Check whether a given object is a valid term.ConceptSlotFunctioncreateConceptSlotFunction(String slotName, Concept c)Create a ConceptSlotFunction for a given slot of a given Concept.voiddump()Dump ontology to default output streamvoiddump(PrintStream ps)Dump ontology to specified PrintStreamprotected voidexternalize(Object obj, AbsObject abs, ObjectSchema schema, Ontology globalOnto)Externalize (obj --> abs) the slots defined inschemaand its super-schemasstatic AbsObjectexternalizeSlotValue(Object obj, Introspector introspector, Ontology referenceOnto)AbsObjectfromObject(Object obj)Converts a Java object into a proper abstract descriptor.protected AbsObjectfromObject(Object obj, Ontology globalOnto)Converts a Java object into a proper abstract descriptor.ListgetActionNames()Retrieve the names of all agent actions defined in this ontology (including extended ontologies).ClassgetClassForElement(String name)Retrieves the concrete class associated with elementnamein this ontology.ListgetConceptNames()Retrieve the names of all concepts defined in this ontology (including extended ontologies).IntrospectorgetIntrospector()StringgetName()Retrieves the name of this ontology.ListgetOwnActionNames()Retrieve the names of the agent actions defined in this ontology only (excluding extended ontologies).ListgetOwnConceptNames()Retrieve the names of the concepts defined in this ontology only (excluding extended ontologies).ListgetOwnPredicateNames()Retrieve the names of the predicates defined in this ontology only (excluding extended ontologies).ListgetPredicateNames()Retrieve the names of all predicatess defined in this ontology (including extended ontologies).static List<ObjectSchema>getReferencedSchemas(ObjectSchema rootSchema)ObjectSchemagetSchema(Class clazz)Retrieves the schema associated to a given class in this ontology.ObjectSchemagetSchema(String name)Retrieves the schema of elementnamein this ontology.ObjectgetSlotValue(String slotName, Object obj)Retrieve the value of slotslotNamefrom objectobjprotected voidinternalize(AbsObject abs, Object obj, ObjectSchema schema, Ontology globalOnto)Internalize (abs --> obj) the slots defined inschemaand its super-schemasstatic ObjectinternalizeSlotValue(AbsObject abs, Introspector introspector, Ontology referenceOnto)static booleanisBaseOntology(Ontology[] oo, String name)voidsetSlotValue(String slotName, Object slotValue, Object obj)Set the value of slotslotNameasslotValueto objectobjObjecttoObject(AbsObject abs)Converts an abstract descriptor to a Java object of the proper class.protected ObjecttoObject(AbsObject abs, String lcType, Ontology globalOnto)Converts an abstract descriptor to a Java object of the proper class.StringtoString()protected voiduseConceptSlotsAsFunctions()Instruct this ontology to support usage of concept slots as functions.
-
-
-
Constructor Detail
-
Ontology
public Ontology(String name, Ontology base)
Construct an Ontology object with a givennamethat extends a given ontology. TheReflectiveIntrospectoris used by default to convert between Java objects and abstract descriptors.- Parameters:
name- The identifier of the ontology.base- The base ontology.
-
Ontology
public Ontology(String name, Introspector introspector)
Construct an Ontology object with a givennamethat uses a given Introspector to convert between Java objects and abstract descriptors.- Parameters:
name- The identifier of the ontology.introspector- The introspector.
-
Ontology
public Ontology(String name, Ontology base, Introspector introspector)
Construct an Ontology object with a givennamethat extends a given ontology and that uses a given Introspector to convert between Java objects and abstract descriptors.- Parameters:
name- The identifier of the ontology.base- The base ontology.introspector- The introspector.
-
Ontology
public Ontology(String name, Ontology[] base, Introspector introspector)
Construct an Ontology object with a givennamethat extends a given set of ontologies and that uses a given Introspector to convert between Java objects and abstract descriptors.- Parameters:
name- The identifier of the ontology.base- The base ontology.introspector- The introspector.
-
-
Method Detail
-
getName
public String getName()
Retrieves the name of this ontology.- Returns:
- the name of this ontology.
-
getIntrospector
public Introspector getIntrospector()
-
add
public void add(ObjectSchema schema) throws OntologyException
Adds a schema to this ontology- Parameters:
schema- The schema to add- Throws:
OntologyException
-
add
public void add(ObjectSchema schema, Class javaClass) throws OntologyException
Adds a schema to the ontology and associates it to the classjavaClass- Parameters:
schema- the schema.javaClass- the concrete class.- Throws:
OntologyException
-
getSchema
public ObjectSchema getSchema(String name) throws OntologyException
Retrieves the schema of elementnamein this ontology. The search is extended to the base ontologies if the schema is not found.- Parameters:
name- the name of the schema in the vocabulary.- Returns:
- the schema or
nullif the schema is not found. - Throws:
OntologyException
-
getSchema
public ObjectSchema getSchema(Class clazz) throws OntologyException
Retrieves the schema associated to a given class in this ontology. The search is extended to the base ontologies if the schema is not found.- Parameters:
clazz- the class whose associated schema must be retrieved.- Returns:
- the schema associated to the given class or
nullif the schema is not found. - Throws:
OntologyException
-
toObject
public Object toObject(AbsObject abs) throws OntologyException, UngroundedException
Converts an abstract descriptor to a Java object of the proper class.- Parameters:
abs- the abstract descriptor.- Returns:
- the object
- Throws:
UngroundedException- if the abstract descriptor contains a variableOntologyException- if some mismatch with the schema is found- See Also:
fromObject(Object)
-
fromObject
public AbsObject fromObject(Object obj) throws OntologyException
Converts a Java object into a proper abstract descriptor.- Parameters:
obj- the object- Returns:
- the abstract descriptor.
- Throws:
OntologyException- if some mismatch with the schema is found- See Also:
toObject(AbsObject)
-
getClassForElement
public Class getClassForElement(String name) throws OntologyException
Retrieves the concrete class associated with elementnamein this ontology. The search is extended to the base ontologies- Parameters:
name- the name of the schema.- Returns:
- the Java class or null if no schema called
nameis found or if no class is associated to that schema. - Throws:
OntologyException- if name is null
-
toObject
protected Object toObject(AbsObject abs, String lcType, Ontology globalOnto) throws UnknownSchemaException, UngroundedException, OntologyException
Converts an abstract descriptor to a Java object of the proper class.- Parameters:
abs- the abstract descriptor.lcType- the type of the abstract descriptor to be translated aconverted into lower case. This is passed as parameters to avoid making the conversion to lower case for each base ontology.globalOnto- The ontology this ontology is part of (i.e. the ontology that extends this ontology).- Returns:
- the object
- Throws:
UnknownSchemaException- If no schema for the abs descriptor to be translated is defined in this ontology.UngroundedException- if the abstract descriptor contains a variableOntologyException- if some mismatch with the schema is found * ontology. In this case UnknownSchema
-
internalize
protected void internalize(AbsObject abs, Object obj, ObjectSchema schema, Ontology globalOnto) throws OntologyException
Internalize (abs --> obj) the slots defined inschemaand its super-schemas- Throws:
OntologyException
-
fromObject
protected AbsObject fromObject(Object obj, Ontology globalOnto) throws UnknownSchemaException, OntologyException
Converts a Java object into a proper abstract descriptor.- Parameters:
obj- the objectglobalOnto- The ontology this ontology is part of (i.e. the ontology that extends this ontology).- Returns:
- the abstract descriptor.
- Throws:
UnknownSchemaException- If no schema for the object to be translated is defined in this ontology.OntologyException- if some mismatch with the schema is found
-
externalize
protected void externalize(Object obj, AbsObject abs, ObjectSchema schema, Ontology globalOnto) throws OntologyException
Externalize (obj --> abs) the slots defined inschemaand its super-schemas- Throws:
OntologyException
-
setSlotValue
public void setSlotValue(String slotName, Object slotValue, Object obj) throws OntologyException
Set the value of slotslotNameasslotValueto objectobj- Throws:
OntologyException
-
getSlotValue
public Object getSlotValue(String slotName, Object obj) throws OntologyException
Retrieve the value of slotslotNamefrom objectobj- Throws:
OntologyException
-
checkIsTerm
public static void checkIsTerm(Object obj) throws OntologyException
Check whether a given object is a valid term. If it is an Aggregate (i.e. aList) it also check the elements.- Throws:
OntologyException- if the given object is not a valid term
-
getOwnConceptNames
public List getOwnConceptNames()
Retrieve the names of the concepts defined in this ontology only (excluding extended ontologies). It should be noticed that an agent-action is itself a concept and therefore the returned list also includes names of agent-actions defined in this ontology.
NOT available in J2ME- Returns:
- the names of the concepts defined in this ontology only (excluding extended ontologies)
-
getConceptNames
public List getConceptNames()
Retrieve the names of all concepts defined in this ontology (including extended ontologies). It should be noticed that an agent-action is itself a concept and therefore the returned list also includes names of agent-actions defined in this ontology.
NOT available in J2ME- Returns:
- the names of all concepts defined in this ontology (including extended ontologies)
-
getOwnActionNames
public List getOwnActionNames()
Retrieve the names of the agent actions defined in this ontology only (excluding extended ontologies).
NOT available in J2ME- Returns:
- the names of the agent actions defined in this ontology only (excluding extended ontologies)
-
getActionNames
public List getActionNames()
Retrieve the names of all agent actions defined in this ontology (including extended ontologies).
NOT available in J2ME- Returns:
- the names of all agent actions defined in this ontology (including extended ontologies)
-
getOwnPredicateNames
public List getOwnPredicateNames()
Retrieve the names of the predicates defined in this ontology only (excluding extended ontologies).
NOT available in J2ME- Returns:
- the names of the predicates defined in this ontology only (excluding extended ontologies)
-
getPredicateNames
public List getPredicateNames()
Retrieve the names of all predicatess defined in this ontology (including extended ontologies).
NOT available in J2ME- Returns:
- the names of all predicatess defined in this ontology (including extended ontologies)
-
createConceptSlotFunction
public ConceptSlotFunction createConceptSlotFunction(String slotName, Concept c) throws OntologyException
Create a ConceptSlotFunction for a given slot of a given Concept. The ConceptSlotFunction class allows treating the slots of an ontological concept as functions. For instance, if an ontology defines a conceptPersonwith a slotnameand a slotage, it is possible to create expression such as
(= (age (Person :name John)) 41)
(> (age (Person :name John)) (age (Person :name Bill)))
(iota ?x (= (age (Person :name John)) ?x))
NOT available in MIDP- Parameters:
slotName- The name of the slotc- The concept a ConceptSlotFunction must be created for. This concept must have a slot calledslotName- Returns:
- A ConceptSlotFunction for the given slotName of the given Concept
- Throws:
OntologyException- Since:
- JADE 3.7
- See Also:
ConceptSlotFunction,useConceptSlotsAsFunctions()
-
useConceptSlotsAsFunctions
protected void useConceptSlotsAsFunctions()
Instruct this ontology to support usage of concept slots as functions. This method must be invoked after all schemas have been completely defined and added to this ontology.- Since:
- JADE 3.7
- See Also:
ConceptSlotFunction,createConceptSlotFunction(java.lang.String,jade.content.Concept)
-
externalizeSlotValue
public static AbsObject externalizeSlotValue(Object obj, Introspector introspector, Ontology referenceOnto) throws OntologyException
- Throws:
OntologyException
-
internalizeSlotValue
public static Object internalizeSlotValue(AbsObject abs, Introspector introspector, Ontology referenceOnto) throws OntologyException
- Throws:
OntologyException
-
getReferencedSchemas
public static List<ObjectSchema> getReferencedSchemas(ObjectSchema rootSchema) throws OntologyException
- Throws:
OntologyException
-
dump
public void dump()
Dump ontology to default output stream
-
dump
public void dump(PrintStream ps)
Dump ontology to specified PrintStream
-
-