Skip to content

Commit

Permalink
more examples providers
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzBuehmann committed Aug 13, 2019
1 parent 472e047 commit 356cd4a
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 12 deletions.
13 changes: 13 additions & 0 deletions components-core/pom.xml
Expand Up @@ -577,5 +577,18 @@
<artifactId>commons-collections4</artifactId>
</dependency>



<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>

</dependencies>
</project>
@@ -1,8 +1,6 @@
package org.dllearner.algorithms.qtl.operations.tuples;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand All @@ -13,14 +11,11 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.aksw.commons.jena.jgrapht.PseudoGraphJenaGraph;
import org.aksw.jena_sparql_api.core.QueryExecutionFactory;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.graph.Triple;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.shared.PrefixMapping;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.util.FmtUtils;
Expand Down
Expand Up @@ -19,7 +19,6 @@
package org.dllearner.refinementoperators;

import com.google.common.collect.*;
import org.apache.commons.math3.stat.descriptive.rank.Percentile;
import org.dllearner.core.*;
import org.dllearner.core.annotations.NoConfigOption;
import org.dllearner.core.config.ConfigOption;
Expand Down Expand Up @@ -151,6 +150,9 @@ public class RhoDRDown extends RefinementOperatorAdapter implements Component, C
private Map<OWLClassExpression,Set<OWLDataProperty>> mgDT = new TreeMap<>();
private Map<OWLClassExpression,Set<OWLDataProperty>> mgsd = new TreeMap<>();

// numeric values splitter
private ValuesSplitter numericValuesSplitter;

// splits for double datatype properties in ascending order
private Map<OWLDataProperty,List<OWLLiteral>> splits = new TreeMap<>();

Expand Down Expand Up @@ -389,8 +391,11 @@ public void init() throws ComponentInitException {
// TODO SPARQL support for splits
logger.warn("Numeric Facet restrictions are not (yet) implemented for " + AnnComponentManager.getName(reasoner) + ", option ignored");
} else {
ValuesSplitter splitter = new DefaultNumericValuesSplitter(reasoner, df, maxNrOfSplits);
splits.putAll(splitter.computeSplits());
// create default splitter if none was set
if(numericValuesSplitter == null) {
numericValuesSplitter = new DefaultNumericValuesSplitter(reasoner, df, maxNrOfSplits);
}
splits.putAll(numericValuesSplitter.computeSplits());
if (logger.isDebugEnabled()) {
logger.debug( sparql_debug, "Numeric Splits: {}", splits);
}
Expand Down Expand Up @@ -2070,4 +2075,14 @@ public void setLengthMetric(OWLClassExpressionLengthMetric lengthMetric) {

logger.debug("mMaxLength = " + mMaxLength);
}

/**
* Set the splitter used to precompute possible splits for data properties with numeric ranges. Those splits
* will then be used to create facet restrictions during refinement.
*
* @param numericValuesSplitter
*/
public void setNumericValuesSplitter(ValuesSplitter numericValuesSplitter) {
this.numericValuesSplitter = numericValuesSplitter;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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();
}
Expand Up @@ -7,9 +7,9 @@
/**
* @author Lorenz Buehmann
*/
public class ListBasedExamplesProvider extends AbstractExamplesProvider {
public class SetBasedExamplesProvider extends AbstractExamplesProvider {

ListBasedExamplesProvider(Set<OWLIndividual> posExamples, Set<OWLIndividual> negExamples) {
public SetBasedExamplesProvider(Set<OWLIndividual> posExamples, Set<OWLIndividual> negExamples) {
super(posExamples, negExamples);
}
}

0 comments on commit 356cd4a

Please sign in to comment.