/*********************************************************************/ /* */ /* 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 is the class used to define schemas of agent actions in an ontology. /// public class AgentActionSchema : ConceptSchema { public static readonly new string base_name= "AgentActionSchema"; private static new AgentActionSchema baseSchema = new AgentActionSchema(); /// /// Constructs a schema that vinculates an entity to be a generic agent action. /// private AgentActionSchema() : base(AgentActionSchema.base_name) { } /// /// Creates an AgentActionSchema with a given type-name. /// /// The name of this AgentActionSchema public AgentActionSchema(string typeName): base(typeName) { } /// /// Retrieves the generic base schema for all agent actions. /// /// Returns the generic base schema for all agent actions. public static new ObjectSchema GetBaseSchema() //Upper case of GetBaseSchema { return baseSchema; } /// /// Adds a slot of type PredicateSchema to this schema. /// /// The name of the slot. /// The schema of the slot. public void add(string name, PredicateSchema slotSchema) { base.Add(name, slotSchema); } /// /// Adds a slot of type PredicateSchema to this schema. /// /// The name of the slot. /// The schema of the slot. /// The optionality, i.e. OPTIONAL or MANDATORY public void add(string name, PredicateSchema slotSchema, int optionality) { base.Add(name, slotSchema, optionality); } /// /// 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. protected new bool DescendsFrom(ObjectSchema s) { try { if (s != null) { if (s.Equals(GetBaseSchema())) { return true; } if (base.DescendsFrom(s)) { return true; } 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() { try { return new AbsAgentAction(GetTypeName()); } catch(Exception ex) { throw new OntologyException(ex.ToString()); } } /// /// Validates a given abstract object, using a given ontology. /// /// The abstract object to Validate. /// The ontology to use. public new void Validate(AbsObject abs, Ontology onto) { try { if (!(abs is AbsAgentAction)) { throw new ValidationException(abs+" is not an AbsAgentAction"); } ValidateSlots(abs, onto); } catch(Exception ex) { throw new ValidationException("Unable to Validate "+abs.ToString()+": "+ex.ToString()); } } } }