public class Ontology extends java.lang.Object implements Serializable
fatherOf
accepts two
parameters, a father and a set of children;
Man
is also of class
Person
.
Ontology
.People
ontology contains an element schema called
Person
. This schema states that a Person
is
characterized by a name
and by an address
:
ConceptSchema personSchema = new ConceptSchema(PERSON);
personSchema.addSlot(NAME, stringSchema);
personSchema.addSlot(ADDRESS, addressSchema, ObjectSchema.OPTIONAL);
where PERSON, NAME
and ADDRESS
are
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
concept Man
as a refinement of the concept Person
:
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 the Person
schema:
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 class
Person
when asking for the value of some attribute, e.g., when
asking for the value of address
. 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 type Man
:
AbsConcept absMan = new AbsConcept(MAN);
absMan.setSlot(NAME, "John");
absMan.setSlot(ADDRESS, absAddress);
where absAddress
is the abstract descriptor for John's
address:
AbsConcept absAddress = new AbsConcept(ADDRESS);
absAddress.setSlot(CITY, "London");
Objects of class Ontology
allows you to:
- register schemas with associated (i) a mandatory term of the
vocabulary e.g.
NAME
and (ii) an optional Java class,
e.g. Person
;
- retrieve the registered information through various keys.
The framework already provides the BasicOntology
ontology
that provides all basic elements, i.e. primitive data types, aggregate
types, etc.
Application-specific ontologies should be implemented extending it.
Concept
,
AbsConcept
,
ConceptSchema
,
BasicOntology
,
Serialized FormConstructor and Description |
---|
Ontology(java.lang.String name,
Introspector introspector)
Construct an Ontology object with a given
name
that uses a given Introspector to
convert between Java objects and abstract descriptors. |
Ontology(java.lang.String name,
Ontology base)
Construct an Ontology object with a given
name
that extends a given ontology. |
Ontology(java.lang.String name,
Ontology[] base,
Introspector introspector)
Construct an Ontology object with a given
name
that extends a given set of ontologies and that uses a given Introspector to
convert between Java objects and abstract descriptors. |
Ontology(java.lang.String name,
Ontology base,
Introspector introspector)
Construct an Ontology object with a given
name
that extends a given ontology and that uses a given Introspector to
convert between Java objects and abstract descriptors. |
Modifier and Type | Method and Description |
---|---|
void |
add(ObjectSchema schema)
Adds a schema to this ontology
|
void |
add(ObjectSchema schema,
java.lang.Class javaClass)
Adds a schema to the ontology and associates it to the class
javaClass |
static void |
checkIsTerm(java.lang.Object obj)
Check whether a given object is a valid term.
|
ConceptSlotFunction |
createConceptSlotFunction(java.lang.String slotName,
Concept c)
Create a ConceptSlotFunction for a given slot of a given Concept.
|
void |
dump()
Dump ontology to default output stream
|
void |
dump(java.io.PrintStream ps)
Dump ontology to specified PrintStream
|
static AbsObject |
externalizeSlotValue(java.lang.Object obj,
Introspector introspector,
Ontology referenceOnto) |
AbsObject |
fromObject(java.lang.Object obj)
Converts a Java object into a proper abstract descriptor.
|
java.util.List |
getActionNames()
Retrieve the names of all agent actions defined in this ontology (including extended ontologies).
|
java.lang.Class |
getClassForElement(java.lang.String name)
Retrieves the concrete class associated with element
name
in this ontology. |
java.util.List |
getConceptNames()
Retrieve the names of all concepts defined in this ontology (including extended ontologies).
|
Introspector |
getIntrospector() |
java.lang.String |
getName()
Retrieves the name of this ontology.
|
java.util.List |
getOwnActionNames()
Retrieve the names of the agent actions defined in this ontology only (excluding extended ontologies).
|
java.util.List |
getOwnConceptNames()
Retrieve the names of the concepts defined in this ontology only (excluding extended ontologies).
|
java.util.List |
getOwnPredicateNames()
Retrieve the names of the predicates defined in this ontology only (excluding extended ontologies).
|
java.util.List |
getPredicateNames()
Retrieve the names of all predicatess defined in this ontology (including extended ontologies).
|
static java.util.List<ObjectSchema> |
getReferencedSchemas(ObjectSchema rootSchema) |
ObjectSchema |
getSchema(java.lang.Class clazz)
Retrieves the schema associated to a given class in this ontology.
|
ObjectSchema |
getSchema(java.lang.String name)
Retrieves the schema of element
name in this ontology. |
static java.lang.Object |
internalizeSlotValue(AbsObject abs,
Introspector introspector,
Ontology referenceOnto) |
static boolean |
isBaseOntology(Ontology[] oo,
java.lang.String name) |
java.lang.Object |
toObject(AbsObject abs)
Converts an abstract descriptor to a Java object of the proper class.
|
java.lang.String |
toString() |
protected void |
useConceptSlotsAsFunctions()
Instruct this ontology to support usage of concept slots as functions.
|
public Ontology(java.lang.String name, Ontology base)
name
that extends a given ontology.
The ReflectiveIntrospector
is used by default to
convert between Java objects and abstract descriptors.name
- The identifier of the ontology.base
- The base ontology.public Ontology(java.lang.String name, Introspector introspector)
name
that uses a given Introspector to
convert between Java objects and abstract descriptors.name
- The identifier of the ontology.introspector
- The introspector.public Ontology(java.lang.String name, Ontology base, Introspector introspector)
name
that extends a given ontology and that uses a given Introspector to
convert between Java objects and abstract descriptors.name
- The identifier of the ontology.base
- The base ontology.introspector
- The introspector.public Ontology(java.lang.String name, Ontology[] base, Introspector introspector)
name
that extends a given set of ontologies and that uses a given Introspector to
convert between Java objects and abstract descriptors.name
- The identifier of the ontology.base
- The base ontology.introspector
- The introspector.public java.lang.String getName()
public Introspector getIntrospector()
public void add(ObjectSchema schema) throws OntologyException
schema
- The schema to addOntologyException
public void add(ObjectSchema schema, java.lang.Class javaClass) throws OntologyException
javaClass
schema
- the schema.javaClass
- the concrete class.OntologyException
public ObjectSchema getSchema(java.lang.String name) throws OntologyException
name
in this ontology.
The search is extended to the base ontologies if the schema is not
found.name
- the name of the schema in the vocabulary.null
if the schema is not found.OntologyException
public ObjectSchema getSchema(java.lang.Class clazz) throws OntologyException
clazz
- the class whose associated schema must be retrieved.null
if the schema is not found.OntologyException
public java.lang.Object toObject(AbsObject abs) throws OntologyException, UngroundedException
abs
- the abstract descriptor.UngroundedException
- if the abstract descriptor contains a
variableOntologyException
- if some mismatch with the schema is foundfromObject(Object)
public AbsObject fromObject(java.lang.Object obj) throws OntologyException
obj
- the objectOntologyException
- if some mismatch with the schema is foundtoObject(AbsObject)
public java.lang.Class getClassForElement(java.lang.String name) throws OntologyException
name
in this ontology. The search is extended to the base ontologiesname
- the name of the schema.name
is found or if no class is associated to that schema.OntologyException
- if name is nullpublic static void checkIsTerm(java.lang.Object obj) throws OntologyException
List
) it also check
the elements.OntologyException
- if the given object is not a valid termpublic java.lang.String toString()
toString
in class java.lang.Object
public java.util.List getOwnConceptNames()
public java.util.List getConceptNames()
public java.util.List getOwnActionNames()
public java.util.List getActionNames()
public java.util.List getOwnPredicateNames()
public java.util.List getPredicateNames()
public ConceptSlotFunction createConceptSlotFunction(java.lang.String slotName, Concept c) throws OntologyException
Person
with a slot name
and a slot age
,
it is possible to create expression such asslotName
- The name of the slotc
- The concept a ConceptSlotFunction must be created for. This concept must have a slot called slotName
OntologyException
ConceptSlotFunction
,
useConceptSlotsAsFunctions()
protected void useConceptSlotsAsFunctions()
ConceptSlotFunction
,
createConceptSlotFunction(String, Concept)
public static AbsObject externalizeSlotValue(java.lang.Object obj, Introspector introspector, Ontology referenceOnto) throws OntologyException
OntologyException
public static java.lang.Object internalizeSlotValue(AbsObject abs, Introspector introspector, Ontology referenceOnto) throws OntologyException
OntologyException
public static java.util.List<ObjectSchema> getReferencedSchemas(ObjectSchema rootSchema) throws OntologyException
OntologyException
public static boolean isBaseOntology(Ontology[] oo, java.lang.String name)
public void dump()
public void dump(java.io.PrintStream ps)