Skip to content

3. Example: Constructing a Descriptor

yushakareem edited this page Dec 9, 2019 · 4 revisions

A Simple Concept Descriptor

The following Java class InstanceConceptDesc, is an example of a simple Concept Descriptor. It can be found in the path: owloop/src/main/java/it/emarolab/owloop/descriptor/utility/conceptDescriptor/.

This class extends the abstract class ConceptGround and implements 1 ConceptExpression interface (i.e., Instance). Note that, when using Descriptor build(), the return type of the Instance is a compound Individual Descriptor called LinkIndividualDesc which implements 2 IndividualExpression interfaces (i.e., ObjectLink and DataLink).

public class InstanceConceptDesc
        extends ConceptGround
        implements ConceptExpression.Instance<LinkIndividualDesc> {
        
}

Inside the class; first, we create an object of the class EntitySet.Individual. This set can hold the OWLNamedIndividuals associated to the ground of type OWLCLass via the expression Instance.

private DescriptorEntitySet.Individuals classAssertedIndividuals = new DescriptorEntitySet.Individuals();

Second, we add the constructors inherited from the abstract class ConceptGround.

public InstanceConceptDesc(OWLClass instance, OWLReferences onto) {
    super(instance, onto);
}
public InstanceConceptDesc(String instanceName, OWLReferences onto) {
    super(instanceName, onto);
}
public InstanceConceptDesc(OWLClass instance, String ontoName) {
    super(instance, ontoName);
}
public InstanceConceptDesc(OWLClass instance, String ontoName, String filePath, String iriPath) {
    super(instance, ontoName, filePath, iriPath);
}
public InstanceConceptDesc(OWLClass instance, String ontoName, String filePath, String iriPath, boolean bufferingChanges) {
    super(instance, ontoName, filePath, iriPath, bufferingChanges);
}
public InstanceConceptDesc(String instanceName, String ontoName) {
    super(instanceName, ontoName);
}
public InstanceConceptDesc(String instanceName, String ontoName, String filePath, String iriPath) {
    super(instanceName, ontoName, filePath, iriPath);
}
public InstanceConceptDesc(String instanceName, String ontoName, String filePath, String iriPath, boolean bufferingChanges) {
    super(instanceName, ontoName, filePath, iriPath, bufferingChanges);
}

Third, we override methods in Concept and ConceptExpression interface. These methods enable manipulation of axioms, (i) within the internal state of the Descriptor and (ii) between the Descriptor(s) and ontology file(s).

// To read axioms from an ontology
@Override 
public List<MappingIntent> readExpressionAxioms() {
    return Instance.super.readExpressionAxioms();
}
// To read axioms from an ontology
@Override 
public List<MappingIntent> writeExpressionAxioms() {
    return Instance.super.writeExpressionAxioms();
}

// Is used by the descriptors's build() method. It's possible to change the return type based on need.
@Override 
public LinkIndividualDesc getIndividualDescriptor(OWLNamedIndividual instance, OWLReferences ontology) {
    return new LinkIndividualDesc( instance, ontology);
}
// It returns the Individuals from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Individuals getIndividualInstances() {
    return classAssertedIndividuals;
}

Finally, we override the default method toString() in the class Object, to be able to print some interesting knowledge within the Descriptor when toString() is called.

// To show internal state of the Descriptor
@Override
public String toString() {
    return getClass().getSimpleName() + "{" + "\n" +
            "\n" +
            "\t" + getGround() + ":" + "\n" +
            "\n" +
            "\t\t⇐ " + individuals + "\n" +
            "}" + "\n";
}

A Compound Concept Descriptor

The following Java class FullConceptDesc, is an example of a compound Concept Descriptor. It can be found in the path: owloop/src/main/java/it/emarolab/owloop/descriptor/utility/conceptDescriptor/.

This class FullConceptDesc extends the abstract class ConceptGround and implements 6 ConceptExpression interfaces (i.e., Equivalent, Disjoint, Sub, Super, Instance, Definition). Note that, when using Descriptor build(), the return type of the Instance is a compound Individual Descriptor called LinkIndividualDesc which implements 2 IndividualExpression interfaces (i.e., ObjectLink and DataLink). Whereas, the return type of the remaining ConceptExpression interfaces (except for Definition) is FullConpectDesc.

public class InstanceConceptDesc
        extends ConceptGround
        implements ConceptExpression.Definition,
        ConceptExpression.Disjoint<FullConceptDesc>,
        ConceptExpression.Equivalent<FullConceptDesc>,
        ConceptExpression.Sub<FullConceptDesc>,
        ConceptExpression.Super<FullConceptDesc>,
        ConceptExpression.Instance<LinkIndividualDesc> {

}

Inside the class; first, we create EntitySet objects for all the types of OWL entities we would like the descriptor FullConceptDesc to handle.

private DescriptorEntitySet.Restrictions conceptRestrictions = new DescriptorEntitySet.Restrictions();
private DescriptorEntitySet.Concepts disjointConcepts = new DescriptorEntitySet.Concepts();
private DescriptorEntitySet.Concepts equivalentConcepts = new DescriptorEntitySet.Concepts();
private DescriptorEntitySet.Concepts subConcepts = new DescriptorEntitySet.Concepts();
private DescriptorEntitySet.Concepts superConcepts = new DescriptorEntitySet.Concepts();
private DescriptorEntitySet.Individuals classAssertedIndividuals = new DescriptorEntitySet.Individuals();

Second, we add the constructors inherited from the abstract class ConceptGround.

public FullConceptDesc(OWLClass instance, OWLReferences onto) {
    super(instance, onto);
}
public FullConceptDesc(String instanceName, OWLReferences onto) {
    super(instanceName, onto);
}
public FullConceptDesc(OWLClass instance, String ontoName) {
    super(instance, ontoName);
}
public FullConceptDesc(OWLClass instance, String ontoName, String filePath, String iriPath) {
    super(instance, ontoName, filePath, iriPath);
}
public FullConceptDesc(OWLClass instance, String ontoName, String filePath, String iriPath, boolean bufferingChanges) {
    super(instance, ontoName, filePath, iriPath, bufferingChanges);
}
public FullConceptDesc(String instanceName, String ontoName) {
    super(instanceName, ontoName);
}
public FullConceptDesc(String instanceName, String ontoName, String filePath, String iriPath) {
    super(instanceName, ontoName, filePath, iriPath);
}
public FullConceptDesc(String instanceName, String ontoName, String filePath, String iriPath, boolean bufferingChanges) {
    super(instanceName, ontoName, filePath, iriPath, bufferingChanges);
}

Third, we override methods in Concept and ConceptExpression interface. These methods enable manipulation of axioms, (i) within the internal state of the Descriptor and (ii) between the Descriptor(s) and ontology file(s).

// To read axioms from an ontology
@Override
public List<MappingIntent> readExpressionAxioms() {
    List<MappingIntent> r = ConceptExpression.Disjoint.super.readExpressionAxioms();
    r.addAll( ConceptExpression.Equivalent.super.readExpressionAxioms());
    r.addAll( Definition.super.readExpressionAxioms()); // call this before Sub or Super !!!
    r.addAll( ConceptExpression.Sub.super.readExpressionAxioms());
    r.addAll( ConceptExpression.Super.super.readExpressionAxioms());
    r.addAll( Instance.super.readExpressionAxioms());
    return r;
}
// To write axioms to an ontology
@Override
public List<MappingIntent> writeExpressionAxioms() {
    List<MappingIntent> r = ConceptExpression.Disjoint.super.writeExpressionAxioms();
    r.addAll( ConceptExpression.Equivalent.super.writeExpressionAxioms());
    r.addAll( Definition.super.writeExpressionAxioms()); // call this before Sub or Super !!!
    r.addAll( ConceptExpression.Sub.super.writeExpressionAxioms());
    r.addAll( ConceptExpression.Super.super.writeExpressionAxioms());
    r.addAll( Instance.super.writeExpressionAxioms());
    return r;
}

// It returns the conceptRestrictions from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Restrictions getDefinitionConcepts() {
    return conceptRestrictions;
}

// Is used by the descriptors's build() method. It's possible to change the return type based on need.
@Override
public FullConceptDesc getDisjointConceptDescriptor(OWLClass instance, OWLReferences ontology) {
    return new FullConceptDesc( instance, ontology);
}
// It returns the disjointConcepts from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Concepts getDisjointConcepts() {
    return disjointConcepts;
}

// Is used by the descriptors's build() method. It's possible to change the return type based on need.
@Override
public FullConceptDesc getEquivalentConceptDescriptor(OWLClass instance, OWLReferences ontology) {
    return new FullConceptDesc( instance, ontology);
}
// It returns the equivalentConcepts from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Concepts getEquivalentConcepts() {
    return equivalentConcepts;
}

// Is used by the descriptors's build() method. It's possible to change the return type based on need.
@Override
public FullConceptDesc getSubConceptDescriptor(OWLClass instance, OWLReferences ontology) {
    return new FullConceptDesc( instance, ontology);
}
// It returns the subConcepts from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Concepts getSubConcepts() {
    return subConcepts;
}

// Is used by the descriptors's build() method. It's possible to change the return type based on need.
@Override
public FullConceptDesc getSuperConceptDescriptor(OWLClass instance, OWLReferences ontology) {
    return new FullConceptDesc( instance, ontology);
}
// It returns the superConcepts from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Concepts getSuperConcepts() {
    return superConcepts;
}

// Is used by the descriptors's build() method. It's possible to change the return type based on need.
@Override
public LinkIndividualDesc getIndividualDescriptor(OWLNamedIndividual instance, OWLReferences ontology) {
    return new LinkIndividualDesc( instance, ontology);
}
// It returns the Individuals from the EntitySet (after being read from the ontology)
@Override
public DescriptorEntitySet.Individuals getIndividualInstances() {
    return classAssertedIndividuals;
}

Finally, we override the default method toString() in the class Object, to be able to print some interesting knowledge within the Descriptor when toString() is called.

// To show internal state of the Descriptor
@Override
public String toString() {
    return getClass().getSimpleName() + "{" + "\n" +
            "\n" +
            "\t" + getGround() + ":" + "\n" +
            "\n" +
            "\t\t≠ " + disjointConcepts + "\n" +
            "\t\t≡ " + equivalentConcepts + "\n" +
            "\t\t⇐ " + individuals + "\n" +
            "\t\t≐ " + conceptRestrictions + "\n" +
            "\t\t⊃ " + subConcepts + "\n" +
            "\t\t⊂ " + superConcepts + "\n" +
            "}" + "\n";
}

In a similar way

We can create simple (ObjectProperty, DataProperty and Individual) Descriptors, and furthermore, compound (ObjectProperty, DataProperty and Individual) Descriptors. Their examples can be found owloop/src/main/java/it/emarolab/owloop/descriptor/utility/conceptDescriptor/ and owloop/src/test/java/it/emarolab/owloopArticleExamples/exampleDescriptors/.

Clone this wiki locally