示例#1
0
  /**
   * Construct a schema that vinculates an entity to be a generic variable. Note that there are no
   * different types of variable as it happens for concepts (e.g. Person, Address...), IREs (e.g.
   * IOTA, ANY, ALL...) and the like. Therefore there is no VariableSchema constructor that takes a
   * String parameter. Not also that the type of the values that can be assumed by the variable is
   * another story and is defined by the VARIABLE_VALUE_TYPE slot of the VariableSchema
   */
  private VariableSchema() {
    super(BASE_NAME);

    try {
      add(NAME, BasicOntology.getInstance().getSchema(BasicOntology.STRING));
      add(
          VALUE_TYPE,
          BasicOntology.getInstance().getSchema(BasicOntology.STRING),
          ObjectSchema.OPTIONAL);
    } catch (OntologyException oe) {
      oe.printStackTrace();
    }
  }
示例#2
0
 public void action() {
   // Receives information about people joining and leaving
   // the chat from the ChatManager agent
   ACLMessage msg = myAgent.receive(template);
   if (msg != null) {
     if (msg.getPerformative() == ACLMessage.INFORM) {
       try {
         AbsPredicate p = (AbsPredicate) myAgent.getContentManager().extractAbsContent(msg);
         if (p.getTypeName().equals(ChatOntology.JOINED)) {
           // Get new participants, add them to the list of participants
           // and notify the gui
           AbsAggregate agg = (AbsAggregate) p.getAbsTerm(ChatOntology.JOINED_WHO);
           if (agg != null) {
             Iterator it = agg.iterator();
             while (it.hasNext()) {
               AbsConcept c = (AbsConcept) it.next();
               participants.add(BasicOntology.getInstance().toObject(c));
             }
           }
           myGui.notifyParticipantsChanged(getParticipantNames());
         }
         if (p.getTypeName().equals(ChatOntology.LEFT)) {
           // Get old participants, remove them from the list of participants
           // and notify the gui
           AbsAggregate agg = (AbsAggregate) p.getAbsTerm(ChatOntology.JOINED_WHO);
           if (agg != null) {
             Iterator it = agg.iterator();
             while (it.hasNext()) {
               AbsConcept c = (AbsConcept) it.next();
               participants.remove(BasicOntology.getInstance().toObject(c));
             }
           }
           myGui.notifyParticipantsChanged(getParticipantNames());
         }
       } catch (Exception e) {
         Logger.println(e.toString());
         e.printStackTrace();
       }
     } else {
       handleUnexpected(msg);
     }
   } else {
     block();
   }
 }
  private CarOntology() {

    super(ONTOLOGY_NAME, BasicOntology.getInstance());

    try {

      add(new ConceptSchema(CAR), Car.class);
      add(new ConceptSchema(ENGINE), Engine.class);
      add(new PredicateSchema(AVAILABLE), Available.class);
      add(new ConceptSchema(COST), Cost.class);
      add(new ConceptSchema(AUTOMOBILE), AutoMobile.class);
      add(new ConceptSchema(CREDITCARD), CreditCard.class);
      add(new AgentActionSchema(RENT), Rent.class);
      add(new ConceptSchema(CATALOG), Catalog.class);

      ConceptSchema cs1 = (ConceptSchema) getSchema(CAR);
      cs1.add(BRAND, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs1.add(MODEL, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs1.add(COLOR, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs1.add(YEAR, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs2 = (ConceptSchema) getSchema(ENGINE);
      cs2.add(CAPACITY, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs2.add(HORSEPOWER, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs2.add(MILEAGE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs3 = (ConceptSchema) getSchema(COST);
      cs3.add(PRIZE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs3.add(AUTOMOBILE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs4 = (ConceptSchema) getSchema(AUTOMOBILE);
      cs4.add(SERIALID, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

      ConceptSchema cs5 = (ConceptSchema) getSchema(CREDITCARD);
      cs5.add(TYPE, (PrimitiveSchema) getSchema(BasicOntology.STRING));
      cs5.add(NUMBER, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      cs5.add(DATE, (PrimitiveSchema) getSchema(BasicOntology.DATE));

      ConceptSchema cs6 = (ConceptSchema) getSchema(CATALOG);
      cs6.add(CARS, (PrimitiveSchema) getSchema(AUTOMOBILE), 1, ObjectSchema.UNLIMITED);

      AgentActionSchema aas1 = (AgentActionSchema) getSchema(RENT);
      aas1.add(AID, (PrimitiveSchema) getSchema(BasicOntology.AID));
      aas1.add(AUTOMOBILE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));
      aas1.add(CREDITCARD, (PrimitiveSchema) getSchema(BasicOntology.STRING));

      PredicateSchema ps1 = (PredicateSchema) getSchema(AVAILABLE);
      ps1.add(AID, (PrimitiveSchema) getSchema(BasicOntology.AID));
      ps1.add(AUTOMOBILE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER));

    } catch (OntologyException oe) {

      oe.printStackTrace();
    }
  }
/** @author Federico Bergenti - Universita` di Parma */
public class PeopleOntology extends Ontology {
  // A symbolic constant, containing the name of this ontology.
  public static final String ONTOLOGY_NAME = "PEOPLE_ONTOLOGY";

  // Concepts
  public static final String PERSON = "PERSON";
  public static final String MAN = "MAN";
  public static final String WOMAN = "WOMAN";
  public static final String ADDRESS = "ADDRESS";

  // Slots
  public static final String NAME = "NAME";
  public static final String STREET = "STREET";
  public static final String NUMBER = "NUMBER";
  public static final String CITY = "CITY";

  // Predicates
  public static final String FATHER_OF = "FATHER_OF";
  public static final String MOTHER_OF = "MOTHER_OF";

  // Roles in predicates
  public static final String FATHER = "FATHER";
  public static final String MOTHER = "MOTHER";
  public static final String CHILDREN = "CHILDREN";

  // Actions
  public static final String MARRY = "MARRY";

  // Arguments in actions
  public static final String HUSBAND = "HUSBAND";
  public static final String WIFE = "WIFE";

  private static PeopleOntology theInstance = new PeopleOntology(BasicOntology.getInstance());

  public static PeopleOntology getInstance() {
    return theInstance;
  }

  public PeopleOntology(Ontology base) {
    super(ONTOLOGY_NAME, base, new ReflectiveIntrospector());

    try {
      PrimitiveSchema stringSchema = (PrimitiveSchema) getSchema(BasicOntology.STRING);
      PrimitiveSchema integerSchema = (PrimitiveSchema) getSchema(BasicOntology.INTEGER);

      ConceptSchema addressSchema = new ConceptSchema(ADDRESS);
      addressSchema.add(STREET, stringSchema, ObjectSchema.OPTIONAL);
      addressSchema.add(NUMBER, integerSchema, ObjectSchema.OPTIONAL);
      addressSchema.add(CITY, stringSchema);

      ConceptSchema personSchema = new ConceptSchema(PERSON);
      personSchema.add(NAME, stringSchema);
      personSchema.add(ADDRESS, addressSchema, ObjectSchema.OPTIONAL);

      ConceptSchema manSchema = new ConceptSchema(MAN);
      manSchema.addSuperSchema(personSchema);

      ConceptSchema womanSchema = new ConceptSchema(WOMAN);
      womanSchema.addSuperSchema(personSchema);

      add(personSchema, Person.class);
      add(manSchema, Man.class);
      add(womanSchema, Woman.class);
      add(addressSchema, Address.class);

      AggregateSchema childrenSchema = new AggregateSchema(BasicOntology.SEQUENCE);

      PredicateSchema fatherOfSchema = new PredicateSchema(FATHER_OF);
      fatherOfSchema.add(FATHER, manSchema);
      fatherOfSchema.add(CHILDREN, childrenSchema);

      PredicateSchema motherOfSchema = new PredicateSchema(MOTHER_OF);
      motherOfSchema.add(MOTHER, womanSchema);
      motherOfSchema.add(CHILDREN, childrenSchema);

      add(fatherOfSchema, FatherOf.class);
      add(motherOfSchema, MotherOf.class);

      AgentActionSchema marrySchema = new AgentActionSchema(MARRY);
      marrySchema.add(HUSBAND, manSchema);
      marrySchema.add(WIFE, womanSchema);

      add(marrySchema);
    } catch (OntologyException oe) {
      oe.printStackTrace();
    }
  }
}
public class BookingOntology extends Ontology {

  private static final long serialVersionUID = -3052063184483117688L;

  public BookingOntology(String name, Introspector introspector) {
    super(name, introspector);
  }

  public static final String ONTOLOGY_NAME = "BOOKING_ONTOLOGY";

  // Concepts
  public static final String CENTRO_PRENOTAZIONE = "CENTRO";
  public static final String CLIENTE = "CLIENTE";
  public static final String INTERVALLOPRENOTAZIONE = "INTERVALLOPRENOTAZIONE";

  // Slots Centro
  public static final String NOME = "NOME";
  public static final String TELEFONO = "TELEFONO";
  public static final String VIA = "VIA";
  public static final String PRESTAZIONI = "PRESTAZIONI";

  // Slots Cliente
  public static final String NOMEC = "NOMECLIENTE";
  public static final String COGNOME = "COGNOMECLIENTE";
  public static final String TELEFONOC = "TELEFONOCLIENTE";

  // Predicates
  public static final String PRENOTAZIONE = "PRENOTAZIONE";
  public static final String PRENOTAZIONE_CON_DATA = "PRENOTAZIONECONDATA";
  public static final String CONFERMA = "CONFERMA";
  public static final String PROPOSTAINTERVALLI = "PROPOSTAINTERVALLI";

  // Slots Prenotazione
  public static final String PRESTAZIONE = "PRESTAZIONE";
  // Slots Prenotazione Completa
  public static final String DATAPRENOTAZIONE = "DATAPRENOTAZIONE";
  // Slots Conferma
  public static final String INIZIOPRENOTAZIONE = "INIZIOPRENOTAZIONE";
  public static final String FINEPRENOTAZIONE = "FINEPRENOTAZIONE";
  public static final String ID_PRENOTAZIONE = "ID_PRENOTAZIONE";
  // Slots PropostaIntervalli
  public static final String INTERVALLI = "INTERVALLI";

  private static BookingOntology theInstance = new BookingOntology(BasicOntology.getInstance());

  public static BookingOntology getInstance() {
    return theInstance;
  }

  public BookingOntology(Ontology base) {
    super(ONTOLOGY_NAME, base, new ReflectiveIntrospector());

    try {
      PrimitiveSchema stringSchema = (PrimitiveSchema) getSchema(BasicOntology.STRING);
      PrimitiveSchema dateSchema = (PrimitiveSchema) getSchema(BasicOntology.DATE);
      PrimitiveSchema intSchema = (PrimitiveSchema) getSchema(BasicOntology.INTEGER);
      // ContentElementListSchema listSchema =
      // (ContentElementListSchema)getSchema(BasicOntology.CONTENT_ELEMENT_LIST);

      // Definizione schema Centro Prenotazione
      ConceptSchema centroSchema = new ConceptSchema(CENTRO_PRENOTAZIONE);
      centroSchema.add(NOME, stringSchema, ObjectSchema.MANDATORY);
      centroSchema.add(TELEFONO, stringSchema, ObjectSchema.MANDATORY);
      centroSchema.add(VIA, stringSchema);
      centroSchema.add(PRESTAZIONI, stringSchema, 1, ObjectSchema.UNLIMITED);

      add(centroSchema, CentroPrenotazione.class);

      // Definizione schema Cliente
      ConceptSchema clienteSchema = new ConceptSchema(CLIENTE);
      clienteSchema.add(NOMEC, stringSchema, ObjectSchema.MANDATORY);
      clienteSchema.add(COGNOME, stringSchema, ObjectSchema.MANDATORY);
      clienteSchema.add(TELEFONOC, stringSchema, ObjectSchema.MANDATORY);

      add(clienteSchema, Cliente.class);

      ConceptSchema intervalliSchema = new ConceptSchema(INTERVALLOPRENOTAZIONE);
      intervalliSchema.add(INIZIOPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);
      intervalliSchema.add(FINEPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);

      add(intervalliSchema, IntervalloPrenotazione.class);

      // Definizione predicati
      PredicateSchema prenotazioneSchema = new PredicateSchema(PRENOTAZIONE);
      prenotazioneSchema.add(CLIENTE, clienteSchema, ObjectSchema.MANDATORY);
      prenotazioneSchema.add(PRESTAZIONE, stringSchema, ObjectSchema.MANDATORY);

      add(prenotazioneSchema, Prenotazione.class);

      PredicateSchema prenotazioneConDataSchema = new PredicateSchema(PRENOTAZIONE_CON_DATA);
      prenotazioneConDataSchema.add(CLIENTE, clienteSchema, ObjectSchema.MANDATORY);
      prenotazioneConDataSchema.add(PRESTAZIONE, stringSchema, ObjectSchema.MANDATORY);
      prenotazioneConDataSchema.add(DATAPRENOTAZIONE, dateSchema, ObjectSchema.OPTIONAL);

      add(prenotazioneConDataSchema, PrenotazioneConData.class);

      PredicateSchema confermaSchema = new PredicateSchema(CONFERMA);
      confermaSchema.add(CENTRO_PRENOTAZIONE, centroSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(INIZIOPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(FINEPRENOTAZIONE, dateSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(PRESTAZIONE, stringSchema, ObjectSchema.MANDATORY);
      confermaSchema.add(ID_PRENOTAZIONE, intSchema);

      add(confermaSchema, Conferma.class);

      PredicateSchema propostaSchema = new PredicateSchema(PROPOSTAINTERVALLI);
      propostaSchema.add(INTERVALLI, intervalliSchema, 1, ObjectSchema.UNLIMITED);
      propostaSchema.add(CENTRO_PRENOTAZIONE, centroSchema, ObjectSchema.MANDATORY);

      add(propostaSchema, PropostaIntervalli.class);

    } catch (OntologyException oe) {
      oe.printStackTrace();
    }
  }
}