Skip to content

Commit

Permalink
create skeleton for adding indirect existentials in materialize
Browse files Browse the repository at this point in the history
  • Loading branch information
souzadevinicius committed Aug 15, 2024
1 parent 23dad04 commit 5a4e0c1
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
85 changes: 85 additions & 0 deletions docs/examples/hubcap.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2/"
xml:base="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#has_part -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#has_part">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/>
</owl:ObjectProperty>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#car -->

<owl:Class rdf:about="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#car">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#has_part"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#wheel"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>



<!-- http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#convertible -->

<owl:Class rdf:about="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#convertible">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#car"/>
</owl:Class>



<!-- http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#hubcap -->

<owl:Class rdf:about="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#hubcap"/>



<!-- http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#wheel -->

<owl:Class rdf:about="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#wheel">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#has_part"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/vinicius/ontologies/2024/7/untitled-ontology-2#hubcap"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.29.2024-05-13T12:11:03Z) https://github.com/owlcs/owlapi -->

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public MaterializeCommand() {
o.addOption("o", "output", true, "save reasoned ontology to a file");
o.addOption("t", "term", true, "a property to materialize");
o.addOption("T", "term-file", true, "load properties from a file");
o.addOption(
"c", "include-indirect", true, "if true include redundant existential restrictions");
options = o;
}

Expand Down Expand Up @@ -131,6 +133,8 @@ public CommandState execute(CommandState state, String[] args) throws Exception
}
}

boolean includeIndirect = CommandLineHelper.getBooleanValue(line, "include-indirect", false);

Set<IRI> terms = CommandLineHelper.getTerms(ioHelper, line, true);
Set<OWLObjectProperty> properties = new HashSet<>();
for (IRI term : terms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static void materialize(
* @param options A map of options for the operation
* @param reasonOverImportsClosure if true will first perform materialization over all ontologies
* in the import closure
* @param includeIndirect if true include redundant existential restrictions
* @throws OWLOntologyCreationException on ontology problem
* @throws OntologyLogicException on logic problem
*/
Expand All @@ -87,12 +88,37 @@ public static void materialize(
Map<String, String> options,
boolean reasonOverImportsClosure)
throws OntologyLogicException, OWLOntologyCreationException {
materialize(ontology, reasonerFactory, properties, options, reasonOverImportsClosure, false);
}

/**
* Replace EquivalentClass axioms with weaker SubClassOf axioms.
*
* @param ontology The OWLOntology to relax
* @param reasonerFactory reasoner factory for the reasoner that is to be wrapped
* @param properties object properties whose existentials are to be materialized (null
* materializes all)
* @param options A map of options for the operation
* @param reasonOverImportsClosure if true will first perform materialization over all ontologies
* in the import closure
* @throws OWLOntologyCreationException on ontology problem
* @throws OntologyLogicException on logic problem
*/
public static void materialize(
OWLOntology ontology,
OWLReasonerFactory reasonerFactory,
Set<OWLObjectProperty> properties,
Map<String, String> options,
boolean reasonOverImportsClosure,
boolean includeIndirect)
throws OntologyLogicException, OWLOntologyCreationException {

if (reasonOverImportsClosure) {
logger.info("Materializing imported ontologies...");
for (OWLOntology importedOntology : ontology.getImportsClosure()) {
if (!importedOntology.equals(ontology)) {
materialize(importedOntology, reasonerFactory, properties, options, false);
materialize(
importedOntology, reasonerFactory, properties, options, false, includeIndirect);
}
}
}
Expand Down Expand Up @@ -143,7 +169,7 @@ public static void materialize(
logger.debug("Excluding classes not in main ontology: " + c);
continue;
}
Set<OWLClassExpression> sces = emr.getSuperClassExpressions(c, true);
Set<OWLClassExpression> sces = emr.getSuperClassExpressions(c, !includeIndirect);
if (!emr.isSatisfiable(c)) {
logger.error("Ontology is not coherent! Unsatisfiable: " + c);
throw new IncoherentTBoxException(Collections.singleton(c));
Expand Down

0 comments on commit 5a4e0c1

Please sign in to comment.