Exemplo n.º 1
0
  /**
   * List all the descendants of a class in the TBox with having equivalent classes into account.
   */
  public void testDescendantClasses() throws Exception {
    final String ontoURI = "http://obda.inf.unibz.it/ontologies/test-class-hierarchy.owl#";
    OWLAPI3Translator t = new OWLAPI3Translator();
    OWLOntologyManager man = OWLManager.createOWLOntologyManager();
    OWLOntology owlonto = man.loadOntologyFromOntologyDocument(new File(inputFile1));
    Ontology onto = t.translate(owlonto);
    // generate Graph
    GraphBuilder change = new GraphBuilderImpl(onto);

    GraphImpl graph = (GraphImpl) change.getGraph();

    // generate DAG
    DAGBuilder change2 = new DAGBuilderImpl(graph);

    DAG dag = change2.getDAG();
    // generate named DAG
    NamedDAGBuilderImpl namedchange = new NamedDAGBuilderImpl(dag);

    DAG pureIsa = namedchange.getDAG();

    TBoxReasoner namedReasoner = new TBoxReasonerImpl(pureIsa);

    final OntologyFactory ofac = OntologyFactoryImpl.getInstance();

    /** The initial node is Node A. */
    Description initialNode = ofac.createClass(ontoURI + "A");
    Set<Set<Description>> descendants = namedReasoner.getDescendants(initialNode, true);

    assertEquals(descendants.size(), 0);

    /** The initial node is Node B. */
    initialNode = ofac.createClass(ontoURI + "B");
    descendants = namedReasoner.getDescendants(initialNode, true);

    assertEquals(descendants.size(), 1);

    Description A = ofac.createClass(ontoURI + "A");
    assertTrue(descendants.contains(namedReasoner.getEquivalences(A, true)));

    /** The initial node is Node C. */
    // There is no test for this node because the API will always suggest
    // Node C is not
    // exist and it has been replaced by Node D (i.e., Class C is equivalent
    // with Class D)

    /** The initial node is Node D. */
    initialNode = ofac.createClass(ontoURI + "D");
    descendants = namedReasoner.getDescendants(initialNode, true);

    assertEquals(descendants.size(), 1);

    Description C = ofac.createClass(ontoURI + "C");
    Set<Description> equivalents = new HashSet<Description>();
    equivalents.add(C);
    assertTrue(descendants.contains(equivalents));

    /** The initial node is Node E. */
    // There is no test for this node because the API will always suggest
    // Node E is not
    // exist and it has been replaced by Node F (i.e., Class E is equivalent
    // with Class F)

    /** The initial node is Node F. */
    initialNode = ofac.createClass(ontoURI + "F");
    descendants = namedReasoner.getDescendants(initialNode, true);
    int size = 0;
    for (Set<Description> d : descendants) size += d.size();

    assertEquals(size, 5);

    A = ofac.createClass(ontoURI + "A");
    assertTrue(descendants.contains(namedReasoner.getEquivalences(A, true)));
    Description B = ofac.createClass(ontoURI + "B");
    assertTrue(descendants.contains(namedReasoner.getEquivalences(B, true)));
    C = ofac.createClass(ontoURI + "C"); // equivalent class
    assertTrue(descendants.contains(namedReasoner.getEquivalences(C, true)));
    Description D = ofac.createClass(ontoURI + "D");
    assertTrue(descendants.contains(namedReasoner.getEquivalences(D, true)));
    Description E = ofac.createClass(ontoURI + "E"); // equivalent class
    equivalents = new HashSet<Description>();
    equivalents.add(E);
    assertTrue(descendants.contains(equivalents));
  }
Exemplo n.º 2
0
  /** List all the ancestors of a role in the TBox with having equivalent roles into account. */
  public void testAncestorRoles() throws Exception {
    final String ontoURI = "http://obda.inf.unibz.it/ontologies/test-role-hierarchy.owl#";
    OWLAPI3Translator t = new OWLAPI3Translator();
    OWLOntologyManager man = OWLManager.createOWLOntologyManager();
    OWLOntology owlonto = man.loadOntologyFromOntologyDocument(new File(inputFile2));
    Ontology onto = t.translate(owlonto);
    // generate Graph
    GraphBuilder change = new GraphBuilderImpl(onto);

    GraphImpl graph = (GraphImpl) change.getGraph();

    // generate DAG
    DAGBuilder change2 = new DAGBuilderImpl(graph);

    DAG dag = change2.getDAG();
    // generate named DAG
    NamedDAGBuilderImpl namedchange = new NamedDAGBuilderImpl(dag);

    DAG pureIsa = namedchange.getDAG();

    TBoxReasoner namedReasoner = new TBoxReasonerImpl(pureIsa);

    final OntologyFactory ofac = OntologyFactoryImpl.getInstance();

    /** The initial node is Node P. */
    Description initialNode = ofac.createObjectProperty(ontoURI + "P");
    Set<Set<Description>> ancestors = namedReasoner.getAncestors(initialNode, true);

    int size = 0;
    for (Set<Description> a : ancestors) size += a.size();

    assertEquals(size, 3);

    Description Q = ofac.createObjectProperty(ontoURI + "Q");
    assertTrue(ancestors.contains(namedReasoner.getEquivalences(Q, true)));
    Description T = ofac.createObjectProperty(ontoURI + "T"); // equivalent
    // role
    assertTrue(ancestors.contains(namedReasoner.getEquivalences(T, true)));
    Description U = ofac.createObjectProperty(ontoURI + "U");
    assertTrue(ancestors.contains(namedReasoner.getEquivalences(U, true)));

    /** The initial node is Node Q. */
    initialNode = ofac.createObjectProperty(ontoURI + "Q");
    ancestors = namedReasoner.getAncestors(initialNode, true);

    size = 0;
    for (Set<Description> a : ancestors) size += a.size();

    assertEquals(size, 2);

    T = ofac.createObjectProperty(ontoURI + "T"); // equivalent
    // role

    assertTrue(ancestors.contains(namedReasoner.getEquivalences(T, true)));
    U = ofac.createObjectProperty(ontoURI + "U");
    assertTrue(ancestors.contains(namedReasoner.getEquivalences(U, true)));

    /** The initial node is Node R. */
    // There is no test for this node because the API will always suggest
    // Node R is not
    // exist and it has been replaced by Node S (i.e., Role R is equivalent
    // with Role S)

    /** The initial node is Node S. */
    initialNode = ofac.createObjectProperty(ontoURI + "S");
    ancestors = namedReasoner.getAncestors(initialNode, true);

    size = 0;
    for (Set<Description> a : ancestors) size += a.size();

    assertEquals(size, 3);

    Description R = ofac.createObjectProperty(ontoURI + "R"); // equivalent
    // role
    Set<Description> equivalents = new HashSet<Description>();
    equivalents.add(R);
    assertTrue(ancestors.contains(equivalents));
    T = ofac.createObjectProperty(ontoURI + "T"); // equivalent
    // role

    assertTrue(ancestors.contains(namedReasoner.getEquivalences(T, true)));
    U = ofac.createObjectProperty(ontoURI + "U");
    assertTrue(ancestors.contains(namedReasoner.getEquivalences(U, true)));

    /** The initial node is Node T. */
    // There is no test for this node because the API will always suggest
    // Node T is not
    // exist and it has been replaced by Node U (i.e., Role T is equivalent
    // with Role U)

    /** The initial node is Node U. */
    initialNode = ofac.createObjectProperty(ontoURI + "U");
    ancestors = namedReasoner.getAncestors(initialNode, true);

    assertEquals(ancestors.size(), 1);

    T = ofac.createObjectProperty(ontoURI + "T"); // equivalent
    // role
    equivalents = new HashSet<Description>();
    equivalents.add(T);
    assertTrue(ancestors.contains(equivalents));
  }