Skip to content

Commit

Permalink
Code improvements for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzBuehmann committed Dec 30, 2015
1 parent aa7aaca commit 8d65034
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 156 deletions.
Expand Up @@ -19,35 +19,14 @@

package org.dllearner.algorithms.celoe;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.google.common.collect.Sets;
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.dllearner.core.AbstractCELA;
import org.dllearner.core.AbstractClassExpressionLearningProblem;
import org.dllearner.core.AbstractHeuristic;
import org.dllearner.core.AbstractKnowledgeSource;
import org.dllearner.core.AbstractReasonerComponent;
import org.dllearner.core.ComponentAnn;
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.Score;
import org.dllearner.core.*;
import org.dllearner.core.config.ConfigOption;
import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.DatatypePropertyHierarchy;
Expand All @@ -59,36 +38,23 @@
import org.dllearner.learningproblems.PosOnlyLP;
import org.dllearner.reasoning.ClosedWorldReasoner;
import org.dllearner.reasoning.SPARQLReasoner;
import org.dllearner.refinementoperators.CustomHierarchyRefinementOperator;
import org.dllearner.refinementoperators.CustomStartRefinementOperator;
import org.dllearner.refinementoperators.LengthLimitedRefinementOperator;
import org.dllearner.refinementoperators.OperatorInverter;
import org.dllearner.refinementoperators.ReasoningBasedRefinementOperator;
import org.dllearner.refinementoperators.RhoDRDown;
import org.dllearner.refinementoperators.SynchronizedRefinementOperator;
import org.dllearner.refinementoperators.*;
import org.dllearner.utilities.Files;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.OWLAPIUtils;
import org.dllearner.utilities.TreeUtils;
import org.dllearner.utilities.datastructures.SynchronizedSearchTree;
import org.dllearner.utilities.owl.ConceptTransformation;
import org.dllearner.utilities.owl.EvaluatedDescriptionSet;
import org.dllearner.utilities.owl.OWLAPIRenderers;
import org.dllearner.utilities.owl.OWLClassExpressionMinimizer;
import org.dllearner.utilities.owl.OWLClassExpressionUtils;
import org.dllearner.utilities.owl.PropertyContext;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNaryBooleanClassExpression;
import org.dllearner.utilities.owl.*;
import org.semanticweb.owlapi.model.*;
import org.springframework.beans.factory.annotation.Autowired;

import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;

import com.google.common.collect.Sets;
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
import java.io.File;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
* The PCELOE is an experimental, parallel implementation of the CELOE algorithm.
Expand Down
Expand Up @@ -87,10 +87,8 @@ public static <T> List<T> union(List<T> list1,List<T> list2){
*/
public static <T> boolean areEquals(List<T>l1, List<T> l2){
// due insiemi sono uguali se uno � incluso nell'altro
if (l1.containsAll(l2)&&l2.containsAll(l1))
return true;

return false;
return l1.containsAll(l2) && l2.containsAll(l1);

}

/**
Expand Down
Expand Up @@ -158,7 +158,7 @@ else if(downwardProbability<0)


// ein refinement zufällig auswählen
OWLClassExpression[] array = refinements.toArray(new OWLClassExpression[0]);
OWLClassExpression[] array = refinements.toArray(new OWLClassExpression[refinements.size()]);
// kein refinement gefunden
if(array.length==0) {
if(debug) {
Expand Down
Expand Up @@ -1253,10 +1253,11 @@ public ExampleBasedNode getStartNode() {
* @return true if the algorithm should stop, this is mostly indepent of the question if a solution was found
*/
private boolean isTerminationCriteriaReached(){
// algorithm was stopped from outside
if(this.stop){
return true;
}
// System.out.println("ssssss");

long totalTimeNeeded = System.currentTimeMillis() - this.runtime;
long maxMilliSeconds = maxExecutionTimeInSeconds * 1000;
long minMilliSeconds = minExecutionTimeInSeconds * 1000;
Expand Down
Expand Up @@ -93,7 +93,7 @@ public class AxiomAlgorithms {
/** set of tbox and rbox axiom types */
public static final Set<AxiomType<? extends OWLAxiom>> TBoxAndRBoxAxiomTypes = tboxAndRbox();

private static final Set<AxiomType<? extends OWLAxiom>> tboxAndRbox() {
private static Set<AxiomType<? extends OWLAxiom>> tboxAndRbox() {
Set<AxiomType<?>> axioms = new HashSet<>(TBoxAxiomTypes);
axioms.addAll(RBoxAxiomTypes);
return axioms;
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.dllearner.learningproblems.QueryTreeScore;

import com.google.common.collect.ComparisonChain;
import org.jetbrains.annotations.NotNull;

public class EvaluatedRDFResourceTree implements Comparable<EvaluatedRDFResourceTree>{

Expand Down Expand Up @@ -128,7 +129,7 @@ public QueryTreeScore getTreeScore() {
}

@Override
public int compareTo(EvaluatedRDFResourceTree other) {
public int compareTo(@NotNull EvaluatedRDFResourceTree other) {
return ComparisonChain.start()
// .compare(this.getScore(), other.getScore())
.compare(other.getScore(), this.getScore())
Expand Down
Expand Up @@ -40,9 +40,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Edge other = (Edge) obj;
if (id != other.id)
return false;
return true;
return id == other.id;
}


Expand Down
Expand Up @@ -40,8 +40,6 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Vertex other = (Vertex) obj;
if (id != other.id)
return false;
return true;
return id == other.id;
}
}
Expand Up @@ -34,11 +34,8 @@ public boolean test(Statement s) {
} else if(s.getObject().isLiteral()){
object = s.getObject().asLiteral().getLexicalForm();
}
if(isSimiliar2QuestionWord(object) || isSimiliar2QuestionWord(predicate)){
return true;
}

return false;
return isSimiliar2QuestionWord(object) || isSimiliar2QuestionWord(predicate);

}

private boolean isSimiliar2QuestionWord(String s){
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.dllearner.learningproblems.QueryTreeScore;

import com.google.common.collect.ComparisonChain;
import org.jetbrains.annotations.NotNull;

public class EvaluatedQueryTree<N> implements Comparable<EvaluatedQueryTree<N>>{

Expand Down Expand Up @@ -128,7 +129,7 @@ public QueryTreeScore getTreeScore() {
}

@Override
public int compareTo(EvaluatedQueryTree<N> other) {
public int compareTo(@NotNull EvaluatedQueryTree<N> other) {
return ComparisonChain.start()
// .compare(this.getScore(), other.getScore())
.compare(other.getScore(), this.getScore())
Expand Down
Expand Up @@ -63,15 +63,14 @@ public Set<String> getPredicateFilters(){

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ENDPOINT\n");
sb.append("Label: ").append(getLabel()).append("\n");
sb.append("URL: ").append(getURL()).append("\n");
sb.append("Default Graph URI: ").append(getDefaultGraphURIs()).append("\n");
sb.append("Named Graph URI: ").append(getNamedGraphURIs()).append("\n");
sb.append("Predicate Filters: ").append(getPredicateFilters()).append("\n");

return sb.toString();
String sb = "ENDPOINT\n" +
"Label: " + getLabel() + "\n" +
"URL: " + getURL() + "\n" +
"Default Graph URI: " + getDefaultGraphURIs() + "\n" +
"Named Graph URI: " + getNamedGraphURIs() + "\n" +
"Predicate Filters: " + getPredicateFilters() + "\n";

return sb;
}

@Override
Expand Down
Expand Up @@ -532,8 +532,7 @@ protected long getRemainingRuntimeInMilliSeconds(){
}

protected boolean terminationCriteriaSatisfied(){
boolean timeLimitExceeded = maxExecutionTimeInSeconds == 0 ? false : getRemainingRuntimeInMilliSeconds() <= 0;
return timeLimitExceeded ;
return maxExecutionTimeInSeconds != 0 && getRemainingRuntimeInMilliSeconds() <= 0;
}

protected List<Entry<OWLClassExpression, Integer>> sortByValues(Map<OWLClassExpression, Integer> map, final boolean useHierachy){
Expand Down
Expand Up @@ -380,7 +380,7 @@ protected String getSolutionString() {
if(learningProblem instanceof PosNegLP) {
Set<OWLIndividual> positiveExamples = ((PosNegLP)learningProblem).getPositiveExamples();
Set<OWLIndividual> negativeExamples = ((PosNegLP)learningProblem).getNegativeExamples();
ReasoningUtils reasoningUtil = ((PosNegLP)learningProblem).getReasoningUtil();
ReasoningUtils reasoningUtil = learningProblem.getReasoningUtil();

str += current + ": " + descriptionString + " (pred. acc.: "
+ dfPercent.format(reasoningUtil.getAccuracyOrTooWeak2(new AccMethodPredAcc(true), description, positiveExamples, negativeExamples, 1))
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.io.Serializable;
import java.text.DecimalFormat;

import org.jetbrains.annotations.NotNull;
import org.semanticweb.owlapi.model.OWLObject;

import com.google.common.collect.ComparisonChain;
Expand Down Expand Up @@ -92,7 +93,7 @@ public String toString() {
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(EvaluatedHypothesis<T, S> o) {
public int compareTo(@NotNull EvaluatedHypothesis<T, S> o) {
return ComparisonChain.start()
.compare(score.getAccuracy(), o.score.getAccuracy())
.compare(hypothesis, o.getDescription())
Expand Down
Expand Up @@ -183,7 +183,6 @@ private void assignIds(int currentId, ResultSetRewindable rsw, int lastDepth){
// could be two different blank nodes here, but unlikely
if(!q.get("o0").isAnon()){
lastNodes.put(q.get("o0").toString(), currentId);
continue;
}else{

// remove the first node
Expand Down
Expand Up @@ -59,7 +59,7 @@ public abstract class AbstractOWLOntologyDataset implements OWLOntologyDataset{

protected Map<URL, String> ontologyURLs = new HashMap<>();

private final int nrOfThreads = 1;
private static final int nrOfThreads = 1;
private boolean analyze = false;

public AbstractOWLOntologyDataset(String name, boolean analyze) {
Expand Down Expand Up @@ -231,7 +231,7 @@ protected OWLOntology loadOWLOntology(URL url) {

private OWLOntology loadFromLocal(URL url){
String filename = getFilename(url);
for(File parent : Arrays.asList(directory)){
for(File parent : Collections.singletonList(directory)){
File file = new File(parent, filename);
if(file.exists()){
try {
Expand Down
Expand Up @@ -201,7 +201,7 @@ public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){
if(one.getURIString().equals(OWLVocabulary.OWL_DIFFERENT_FROM)){
OWLIndividual o = factory.getOWLNamedIndividual(one.getBPart().getIRI());

ax = factory.getOWLDifferentIndividualsAxiom(new OWLIndividual[]{me,o});
ax = factory.getOWLDifferentIndividualsAxiom(me, o);
}else{

//create axiom
Expand Down
Expand Up @@ -104,79 +104,34 @@ public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){

public boolean isDouble(){
try{
if(l.getDatatypeURI().contains("double")){return true;}
else{return false;}

//l.getFloat();

//l.getDouble();
//return true;
}catch (Exception e) {
return false;
}/*
try{
l.getDouble();
return true;
return l.getDatatypeURI() != null && l.getDatatypeURI().contains("double");
}catch (Exception e) {
return false;
}*/
}
}

public boolean isFloat(){
try{
if(l.getDatatypeURI().contains("float")){return true;}
else{return false;}

//l.getFloat();

//l.getDouble();
//return true;
return l.getDatatypeURI() != null && l.getDatatypeURI().contains("float");
}catch (Exception e) {
return false;
}
}

public boolean isInt(){
try{
if(l.getDatatypeURI().contains("int")){return true;}
else{return false;}

//l.getFloat();

//l.getDouble();
//return true;
return l.getDatatypeURI() != null && l.getDatatypeURI().contains("int");
}catch (Exception e) {
return false;
}


/*try{
l.getInt();
return true;
}catch (Exception e) {
return false;
}*/
}

public boolean isBoolean(){
try{
if(l.getDatatypeURI().contains("boolean")){return true;}
else{return false;}

//l.getFloat();

//l.getDouble();
//return true;
return l.getDatatypeURI() != null && l.getDatatypeURI().contains("boolean");
}catch (Exception e) {
return false;
}

/*try{
l.getBoolean();
return true;
}catch (Exception e) {
return false;
}*/
}

public boolean isString(){
Expand Down
Expand Up @@ -20,8 +20,8 @@ public class BioPortalRepository implements OntologyRepository {

private static final Logger log = Logger.getLogger(BioPortalRepository.class);

private String apiKey = "8fadfa2c-47de-4487-a1f5-b7af7378d693";
private String serviceURL = "http://rest.bioontology.org/bioportal/ontologies";
private static final String apiKey = "8fadfa2c-47de-4487-a1f5-b7af7378d693";
private static final String serviceURL = "http://rest.bioontology.org/bioportal/ontologies";

private boolean initialized = false;

Expand Down

0 comments on commit 8d65034

Please sign in to comment.