Exemplo n.º 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();
    }
  }
  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();
    }
  }