Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
472e047
commit 356cd4a
Showing
7 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
components-core/src/main/java/org/dllearner/utilities/examples/AbstractExamplesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
package org.dllearner.utilities.examples; | ||
|
||
import java.util.Set; | ||
|
||
import org.semanticweb.owlapi.model.OWLIndividual; | ||
|
||
/** | ||
* @author Lorenz Buehmann | ||
*/ | ||
public class AbstractExamplesProvider { | ||
public class AbstractExamplesProvider implements ExamplesProvider { | ||
|
||
private final Set<OWLIndividual> posExamples; | ||
private final Set<OWLIndividual> negExamples; | ||
|
||
public AbstractExamplesProvider(Set<OWLIndividual> posExamples, Set<OWLIndividual> negExamples) { | ||
this.posExamples = posExamples; | ||
this.negExamples = negExamples; | ||
} | ||
|
||
@Override | ||
public Set<OWLIndividual> getPosExamples() { | ||
return posExamples; | ||
} | ||
|
||
@Override | ||
public Set<OWLIndividual> getNegExamples() { | ||
return negExamples; | ||
} | ||
} |
78 changes: 77 additions & 1 deletion
78
...nts-core/src/main/java/org/dllearner/utilities/examples/DLQueryBasedExamplesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,83 @@ | ||
package org.dllearner.utilities.examples; | ||
|
||
import java.util.Set; | ||
|
||
import org.dllearner.reasoning.OWLAPIReasoner; | ||
import org.semanticweb.owlapi.apibinding.OWLManager; | ||
import org.semanticweb.owlapi.expression.OWLEntityChecker; | ||
import org.semanticweb.owlapi.expression.ShortFormEntityChecker; | ||
import org.semanticweb.owlapi.model.OWLClassExpression; | ||
import org.semanticweb.owlapi.model.OWLIndividual; | ||
import org.semanticweb.owlapi.util.BidirectionalShortFormProvider; | ||
import org.semanticweb.owlapi.util.BidirectionalShortFormProviderAdapter; | ||
import org.semanticweb.owlapi.util.SimpleShortFormProvider; | ||
import org.semanticweb.owlapi.util.mansyntax.ManchesterOWLSyntaxParser; | ||
|
||
/** | ||
* @author Lorenz Buehmann | ||
*/ | ||
public class DLQueryBasedExamplesProvider { | ||
public class DLQueryBasedExamplesProvider implements ExamplesProvider{ | ||
|
||
private final OWLAPIReasoner rc; | ||
private final OWLClassExpression posExamplesCE; | ||
private final OWLClassExpression negExamplesCE; | ||
|
||
private Set<OWLIndividual> posExamples; | ||
private Set<OWLIndividual> negExamples; | ||
|
||
public DLQueryBasedExamplesProvider(OWLAPIReasoner rc, | ||
OWLClassExpression posExamplesCE, | ||
OWLClassExpression negExamplesCE) { | ||
this.rc = rc; | ||
this.posExamplesCE = posExamplesCE; | ||
this.negExamplesCE = negExamplesCE; | ||
} | ||
|
||
public DLQueryBasedExamplesProvider(OWLAPIReasoner rc, | ||
String posExamplesClassExpressionString, | ||
String negExamplesClassExpressionString) { | ||
this.rc = rc; | ||
this.posExamplesCE = parseClassExpression(posExamplesClassExpressionString); | ||
this.negExamplesCE = parseClassExpression(negExamplesClassExpressionString); | ||
} | ||
|
||
/** | ||
* Parses a class expression string to obtain a class expression. | ||
* | ||
* @param classExpressionString | ||
* The class expression string | ||
* @return The corresponding class expression if the class expression string | ||
* is malformed or contains unknown entity names. | ||
*/ | ||
private OWLClassExpression parseClassExpression(String classExpressionString) { | ||
BidirectionalShortFormProvider bidiShortFormProvider = new BidirectionalShortFormProviderAdapter( | ||
rc.getManager(), | ||
rc.getOntology().getImportsClosure(), | ||
new SimpleShortFormProvider()); | ||
// Set up the real parser | ||
ManchesterOWLSyntaxParser parser = OWLManager.createManchesterParser(); | ||
parser.setDefaultOntology(rc.getOntology()); | ||
// Specify an entity checker that wil be used to check a class | ||
// expression contains the correct names. | ||
OWLEntityChecker entityChecker = new ShortFormEntityChecker(bidiShortFormProvider); | ||
parser.setOWLEntityChecker(entityChecker); | ||
// Do the actual parsing | ||
return parser.parseClassExpression(); | ||
} | ||
|
||
@Override | ||
public Set<OWLIndividual> getPosExamples() { | ||
if(posExamples == null) { | ||
posExamples = rc.getIndividuals(); | ||
} | ||
return posExamples; | ||
} | ||
|
||
@Override | ||
public Set<OWLIndividual> getNegExamples() { | ||
if(negExamples == null) { | ||
negExamples = rc.getIndividuals(); | ||
} | ||
return negExamples; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
components-core/src/main/java/org/dllearner/utilities/examples/ExamplesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package org.dllearner.utilities.examples; | ||
|
||
import java.util.Set; | ||
|
||
import org.semanticweb.owlapi.model.OWLIndividual; | ||
|
||
/** | ||
* @author Lorenz Buehmann | ||
*/ | ||
public interface ExamplesProvider { | ||
|
||
Set<OWLIndividual> getPosExamples(); | ||
|
||
Set<OWLIndividual> getNegExamples(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters