/*********************************************************************/
/* */
/* AgentService Framework */
/* www.agentservice.it */
/* */
/* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */
/* GNU Lesser General Public License */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation, */
/* version 2.1 of the License. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the */
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/*********************************************************************/
using AgentService.Ontology;
using AgentService.Ontology.Schema.Abstract;
using System;
using AgentService.Ontology.Validation;
namespace AgentService.Ontology.Schema
{
///
/// This class is the schema for the IRE entity in a ontology.
///
public class IRESchema : TermSchema
{
public static readonly new string base_name = "IRE";
private static new IRESchema baseSchema = new IRESchema();
public static readonly string variable = "Variable";
public static readonly string proposition = "Proposition";
///
/// Constructs a generic IREschema.
///
private IRESchema(): base(base_name)
{
}
///
/// Costructs a IREschema with a given name.
///
/// The name of the IRE.
public IRESchema(string typeName):base(typeName)
{
try
{
Add(variable, VariableSchema.GetBaseSchema());
Add(proposition, PredicateSchema.GetBaseSchema());
}
catch(Exception ex)
{
throw new OntologyException("Unable to create a IRESchema with name "+typeName.ToString()+": "+ex.ToString());
}
}
///
/// Constructs an IREschema with given typeName, variable schema and predicate schema.
///
/// The type name.
/// The variable schema.
/// The predicate schema.
public IRESchema(string typeName, VariableSchema varSchema, PredicateSchema predSchema): base(typeName)
{
try
{
Add(variable, varSchema);
Add(proposition, predSchema);
}
catch(Exception ex)
{
throw new OntologyException("Unable to create a IRESchema with name "+typeName.ToString()+": "+ex.ToString());
}
}
///
/// Retrieves a generic base schema for all IREs.
///
///
public static new ObjectSchema GetBaseSchema()
{
return baseSchema;
}
///
/// IRE must be compatible with a Term.
///
/// The term of wathever type
/// True if the IRE is compatible.
public override bool IsCompatibleWith(ObjectSchema s)
{
try
{
if (s != null)
{
return s.DescendsFrom(TermSchema.GetBaseSchema());
}
else
{
return false;
}
}
catch(Exception ex)
{
throw new OntologyException(ex.ToString());
}
}
///
/// Returns true if
///- s is the base schema for the XXXSchema class and this schema is
/// an instance of (e.g. s is ConceptSchema.GetBaseSchema() and this
/// schema is an instance of ConceptSchema)
/// - s is the base schema for a super-class of the XXXSchema class and
/// this schema is an instance of (e.g. s is TermSchema.GetBaseSchema()
/// and this schema is an instance of ConceptSchema.
///
/// Object schema
/// Returns true if s is a base schema for this schema.
public override bool DescendsFrom(ObjectSchema s)
{
try
{
if (s != null)
{
if (s.Equals(GetBaseSchema()))
{
return true;
}
if (base.DescendsFrom(s))
{
return true;
}
// An IRE is also a ContentElement
return ContentElementSchema.GetBaseSchema().DescendsFrom(s);
}
else
{
return false;
}
}
catch(Exception ex)
{
throw new OntologyException(ex.ToString());
}
}
///
/// Returns an abstract object that represents this agent action.
///
///
public override AbsObject NewInstance()
{
return new AbsIRE(GetTypeName());
}
///
/// Validates a given abstract object, using a given ontology.
///
/// The abstract object to Validate.
/// The ontology to use.
public override void Validate(AbsObject abs, Ontology onto)
{
try
{
if (!(abs is AbsIRE))
{
throw new ValidationException(abs+" is not an AbsIRE");
}
ValidateSlots(abs, onto);
}
catch(Exception ex)
{
throw new ValidationException("Unable to Validate "+abs+": "+ex.ToString());
}
}
}
}