From: <lor...@us...> - 2013-12-10 14:35:07
|
Revision: 4206 http://sourceforge.net/p/dl-learner/code/4206 Author: lorenz_b Date: 2013-12-10 14:35:02 +0000 (Tue, 10 Dec 2013) Log Message: ----------- Set DBpedia experiment to SOLR index. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyDLReasonerManager.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2.java trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2toFuzzyDL.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/Experiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetricTest.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/OWLClassExpression2FuzzyDLConverter.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -175,7 +175,7 @@ private int maxClassDescriptionTests = 0; - private int maxExecutionTimeInSeconds = 100; + private int maxExecutionTimeInSeconds = 200; private boolean terminateOnNoiseReached = false; @@ -390,6 +390,13 @@ else if (learningProblem instanceof FuzzyPosNegLP) { examples = Helper.union(((FuzzyPosNegLP)learningProblem).getPositiveExamples(),((FuzzyPosNegLP)learningProblem).getNegativeExamples()); } + + + //cardinality has to be deactivated as it is not supported by FuzzyDL + if(operator instanceof RhoDRDown){ + ((RhoDRDown) operator).setUseCardinalityRestrictions(false); + } + } @Override Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -64,7 +64,6 @@ try { QueryResponse response = solr.query(query); SolrDocumentList list = response.getResults(); - System.out.println(list.getNumFound()); for (SolrDocument doc : list) { String uri = (String) doc.getFieldValue("uri"); String comment = (String) doc.getFieldValue(searchField); @@ -120,7 +119,7 @@ queryString += Joiner.on("OR").join(terms); queryString += ")"; - SolrQuery query = new SolrQuery(searchField + ":" + queryString);System.out.println(query); + SolrQuery query = new SolrQuery(searchField + ":" + queryString);//System.out.println(query); try { QueryResponse response = solr.query(query); SolrDocumentList list = response.getResults(); @@ -162,7 +161,7 @@ String queryStringConjuction = "(" + Joiner.on("AND").join(queryStringParts) + ")"; - SolrQuery query = new SolrQuery(searchField + ":" + queryStringConjuction);System.out.println(query); + SolrQuery query = new SolrQuery(searchField + ":" + queryStringConjuction);//System.out.println(query); try { QueryResponse response = solr.query(query); SolrDocumentList list = response.getResults(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -3,14 +3,9 @@ */ package org.dllearner.algorithms.isle.metrics; -import java.util.Set; - -import org.dllearner.algorithms.isle.index.AnnotatedDocument; import org.dllearner.algorithms.isle.index.Index; import org.dllearner.core.owl.Entity; -import com.google.common.collect.Sets; - /** * @author Lorenz Buehmann * @@ -40,18 +35,15 @@ @Override public double getNormalizedRelevance(Entity entityA, Entity entityB){ - Set<AnnotatedDocument> documentsA = index.getDocuments(entityA); - Set<AnnotatedDocument> documentsB = index.getDocuments(entityB); - Set<AnnotatedDocument> documentsAB = Sets.intersection(documentsA, documentsB); + long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); + long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + long nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); + long nrOfDocuments = index.getTotalNumberOfDocuments(); -// System.out.println("A:" + documentsA.size()); -// System.out.println("B:" + documentsB.size()); -// System.out.println("AB:" + documentsAB.size()); -// System.out.println(nrOfDocuments); - double pA = nrOfDocuments == 0 ? 0 : ((double) documentsA.size() / (double) nrOfDocuments); - double pB = nrOfDocuments == 0 ? 0 : ((double) documentsB.size() / (double) nrOfDocuments); - double pAB = nrOfDocuments == 0 ? 0 : ((double) documentsAB.size() / (double) nrOfDocuments); + double pA = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsA / (double) nrOfDocuments); + double pB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsB / (double) nrOfDocuments); + double pAB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsAB / (double) nrOfDocuments); if(pAB == 0 || pA * pB == 0){ return 0; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -8,6 +8,7 @@ import java.util.Map; import java.util.Set; +import org.apache.log4j.Logger; import org.dllearner.core.owl.Entity; import org.dllearner.utilities.owl.OWLAPIConverter; import org.semanticweb.owlapi.model.OWLEntity; @@ -19,6 +20,9 @@ */ public class RelevanceUtils { + + private static final Logger logger = Logger.getLogger(RelevanceUtils.class.getName()); + public static Map<Entity, Double> getRelevantEntities(Entity entity, Set<Entity> otherEntities, RelevanceMetric metric){ Map<Entity, Double> relevantEntities = new HashMap<Entity, Double>(); @@ -31,7 +35,7 @@ } public static Map<Entity, Double> getRelevantEntities(Entity entity, OWLOntology ontology, RelevanceMetric metric){ - System.out.println(entity); + logger.info("Get relevant entities for " + entity); Map<Entity, Double> relevantEntities = new HashMap<Entity, Double>(); Set<OWLEntity> owlEntities = new HashSet<OWLEntity>(); @@ -43,7 +47,7 @@ otherEntities.remove(entity); for (Entity otherEntity : otherEntities) { double relevance = metric.getNormalizedRelevance(entity, otherEntity); - System.out.println(otherEntity + ":" + relevance); + logger.info(otherEntity + ":" + relevance); relevantEntities.put(otherEntity, relevance); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyDLReasonerManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyDLReasonerManager.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyDLReasonerManager.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -33,6 +33,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.utilities.FuzzyOwl2toFuzzyDL; +import org.dllearner.utilities.OWLClassExpression2FuzzyDLConverter; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; @@ -107,6 +108,7 @@ // private int counter2 = 1; private ByteArrayOutputStream baos; + private OWLClassExpression2FuzzyDLConverter classExpression2fuzzyDLConverter; public FuzzyDLReasonerManager(String ontologyFile, OWLOntology ontology, OWLReasonerConfiguration conf, OWLDataFactory factory, String baseURI) throws Exception { @@ -140,21 +142,24 @@ baos = new ByteArrayOutputStream(); fuzzyFileParser.setPrintStream(new PrintStream(baos)); + classExpression2fuzzyDLConverter = new OWLClassExpression2FuzzyDLConverter(fuzzyFileParser); + solveKB(); // errorFile = new FileOutputStream("errorFile.txt")name; } private Concept convert(OWLClassExpression classExpression){ - baos.reset(); - if(classExpression.isOWLThing()){ - return Concept.CONCEPT_TOP; - } else if(classExpression.isOWLNothing()){ - return Concept.CONCEPT_BOTTOM; - } else { - String name = fuzzyFileParser.getClassName(classExpression); - return fuzzyKB.getConcept(name); - } +// baos.reset(); +// if(classExpression.isOWLThing()){ +// return Concept.CONCEPT_TOP; +// } else if(classExpression.isOWLNothing()){ +// return Concept.CONCEPT_BOTTOM; +// } else { +// String name = fuzzyFileParser.getClassName(classExpression); +// return fuzzyKB.getConcept(name); +// } + return classExpression2fuzzyDLConverter.convert(classExpression); } private Individual convert(OWLIndividual individual){ @@ -201,12 +206,16 @@ Query q = new MinInstanceQuery(fConcept, fIndividual); KnowledgeBase clonedFuzzyKB = fuzzyKB.clone(); - +// q = new MinInstanceQuery(Concept.some("hasCar", Concept.CONCEPT_TOP), fuzzyKB.getIndividual("east1")); +// System.out.println(fConcept); +// System.out.println(Concept.some("hasCar", Concept.CONCEPT_TOP)); +// q = new MinInstanceQuery(fuzzyKB.getConcept("Train"), fuzzyKB.getIndividual("east1")); // TODO: just for testing, remove // long start = System.nanoTime(); queryResult = q.solve(clonedFuzzyKB); System.out.println(q.toString() + queryResult.getSolution()); +// System.exit(0); // TODO: just for testing, remove // out.println(counter + " * " + (System.nanoTime() - start)); // counter++; Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -542,8 +542,8 @@ // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; // remove reasoner calls -// Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); - Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); + Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); +// Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) refinements.add(new ObjectSomeRestriction(moreSpecialRole, description.getChild(0))); @@ -587,15 +587,15 @@ // rule 3: ALL r.D => ALL s.D or ALL r^-1.D => ALL s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; -// Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); - Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); + Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); +// Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) { refinements.add(new ObjectAllRestriction(moreSpecialRole, description.getChild(0))); } // rule 4: ALL r.D => <= (maxFillers-1) r.D // (length increases by 1 so we have to check whether max length is sufficient) - // => commented out because this is acutally not a downward refinement + // => commented out because this is actually not a downward refinement // if(useCardinalityRestrictions) { // if(maxLength > description.getLength() && maxNrOfFillers.get(ar)>1) { // ObjectMaxCardinalityRestriction max = new ObjectMaxCardinalityRestriction(maxNrOfFillers.get(ar)-1,role,description.getChild(0)); Modified: trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -229,7 +229,7 @@ protected OWLDataFactory dataFactory; protected Hashtable<String, FuzzyConcept> definedConcepts; protected Hashtable<String, FuzzyProperty> definedProperties; - protected Hashtable<String, FuzzyDatatype> fuzzyDatatypes; + public Hashtable<String, FuzzyDatatype> fuzzyDatatypes; protected Hashtable<String, FuzzyModifier> fuzzyModifiers; protected OWLAnnotationProperty label; protected OWLOntologyManager manager; @@ -1187,7 +1187,7 @@ * @param p An OWL 2 object property. * @return A String representation of p. */ - protected String getObjectPropertyName(OWLObjectPropertyExpression p) + public String getObjectPropertyName(OWLObjectPropertyExpression p) { if (p.isOWLTopObjectProperty()) return getTopObjectPropertyName(); @@ -1204,7 +1204,7 @@ * @param p An OWL 2 data property. * @return A String representation of p. */ - protected String getDataPropertyName(OWLDataPropertyExpression p) + public String getDataPropertyName(OWLDataPropertyExpression p) { if (p.isOWLTopDataProperty()) return getTopDataPropertyName(); @@ -1345,7 +1345,7 @@ * @param e An OWL 2 entity. * @return Short name of e. */ - protected String getShortName(OWLEntity e) + public String getShortName(OWLEntity e) { return pm.getShortForm(e); } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2toFuzzyDL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2toFuzzyDL.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/main/java/org/dllearner/utilities/FuzzyOwl2toFuzzyDL.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -2,6 +2,7 @@ import java.util.*; +import fuzzydl.Concept; import fuzzyowl2.*; import org.semanticweb.owlapi.model.*; @@ -49,7 +50,7 @@ @Override protected String getTopConceptName() { - return("*top*"); + return Concept.CONCEPT_TOP.toString();//("*top*"); } @@ -92,7 +93,7 @@ @Override protected String getObjectSomeValuesFromName(OWLObjectPropertyExpression p, OWLClassExpression c) { - return "(some " + getObjectPropertyName(p) + " " + getClassName(c) + " )"; + return "(some " + getObjectPropertyName(p) + " " + getClassName(c) + ")"; } @@ -1076,7 +1077,7 @@ @Override - protected String getShortName(OWLEntity e) + public String getShortName(OWLEntity e) { String aux = pm.getShortForm(e); if (isReservedWord(aux)) Added: trunk/components-core/src/main/java/org/dllearner/utilities/OWLClassExpression2FuzzyDLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/OWLClassExpression2FuzzyDLConverter.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/OWLClassExpression2FuzzyDLConverter.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -0,0 +1,230 @@ +/** + * + */ +package org.dllearner.utilities; + +import java.util.ArrayList; +import java.util.Set; + +import org.semanticweb.owlapi.model.DataRangeType; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLClassExpressionVisitor; +import org.semanticweb.owlapi.model.OWLDataAllValuesFrom; +import org.semanticweb.owlapi.model.OWLDataExactCardinality; +import org.semanticweb.owlapi.model.OWLDataHasValue; +import org.semanticweb.owlapi.model.OWLDataMaxCardinality; +import org.semanticweb.owlapi.model.OWLDataMinCardinality; +import org.semanticweb.owlapi.model.OWLDataOneOf; +import org.semanticweb.owlapi.model.OWLDataRange; +import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectComplementOf; +import org.semanticweb.owlapi.model.OWLObjectExactCardinality; +import org.semanticweb.owlapi.model.OWLObjectHasSelf; +import org.semanticweb.owlapi.model.OWLObjectHasValue; +import org.semanticweb.owlapi.model.OWLObjectIntersectionOf; +import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; +import org.semanticweb.owlapi.model.OWLObjectMinCardinality; +import org.semanticweb.owlapi.model.OWLObjectOneOf; +import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectUnionOf; + +import fuzzydl.Concept; + +/** + * @author Lorenz Buehmann + * + */ +public class OWLClassExpression2FuzzyDLConverter implements OWLClassExpressionVisitor{ + + Concept fuzzyConcept; + private FuzzyOwl2 fuzzyOwl2; + + + public OWLClassExpression2FuzzyDLConverter(FuzzyOwl2 fuzzyOwl2) { + this.fuzzyOwl2 = fuzzyOwl2; + } + + public Concept convert(OWLClassExpression expr){ + expr.accept(this); + return fuzzyConcept; + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLClass) + */ + @Override + public void visit(OWLClass cls) { + if(cls.isOWLThing()){ + fuzzyConcept = Concept.CONCEPT_TOP; + } else if(cls.isOWLNothing()){ + fuzzyConcept = Concept.CONCEPT_BOTTOM; + } else { + fuzzyConcept = new Concept(fuzzyOwl2.getClassName(cls)); + } + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectIntersectionOf) + */ + @Override + public void visit(OWLObjectIntersectionOf expr) { + ArrayList<Concept> conjuncts = new ArrayList<>(); + for (OWLClassExpression operand : expr.getOperands()) { + conjuncts.add(convert(operand)); + } + fuzzyConcept = Concept.and(conjuncts); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectUnionOf) + */ + @Override + public void visit(OWLObjectUnionOf expr) { + ArrayList<Concept> disjuncts = new ArrayList<>(); + for (OWLClassExpression operand : expr.getOperands()) { + disjuncts.add(convert(operand)); + } + fuzzyConcept = Concept.or(disjuncts); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectComplementOf) + */ + @Override + public void visit(OWLObjectComplementOf expr) { + Concept c = convert(expr.getOperand()); + fuzzyConcept = Concept.complement(c); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom) + */ + @Override + public void visit(OWLObjectSomeValuesFrom expr) { + Concept filler = convert(expr.getFiller()); + fuzzyConcept = Concept.some(fuzzyOwl2.getObjectPropertyName(expr.getProperty()), filler); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectAllValuesFrom) + */ + @Override + public void visit(OWLObjectAllValuesFrom expr) { + Concept filler = convert(expr.getFiller()); + fuzzyConcept = Concept.all(fuzzyOwl2.getObjectPropertyName(expr.getProperty()), filler); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectHasValue) + */ + @Override + public void visit(OWLObjectHasValue arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectMinCardinality) + */ + @Override + public void visit(OWLObjectMinCardinality arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectExactCardinality) + */ + @Override + public void visit(OWLObjectExactCardinality arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectMaxCardinality) + */ + @Override + public void visit(OWLObjectMaxCardinality arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectHasSelf) + */ + @Override + public void visit(OWLObjectHasSelf arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectOneOf) + */ + @Override + public void visit(OWLObjectOneOf arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataSomeValuesFrom) + */ + @Override + public void visit(OWLDataSomeValuesFrom expr) { + OWLDataRange range = expr.getFiller(); + DataRangeType type = range.getDataRangeType(); + if (type == DataRangeType.DATATYPE) + { + String datatypeName = fuzzyOwl2.getShortName(range.asOWLDatatype()); + if (fuzzyOwl2.fuzzyDatatypes.containsKey(datatypeName)) + fuzzyConcept = Concept.some(fuzzyOwl2.getDataPropertyName(expr.getProperty()), new Concept(datatypeName)); + } + else if (type == DataRangeType.DATA_ONE_OF) + { + OWLDataOneOf o = (OWLDataOneOf) range; + Set<OWLLiteral> set = o.getValues(); + if (!set.isEmpty()) + { + OWLLiteral lit = set.iterator().next(); + fuzzyConcept = Concept.exactValue(fuzzyOwl2.getDataPropertyName(expr.getProperty()), lit.getLiteral()); + } + } + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataAllValuesFrom) + */ + @Override + public void visit(OWLDataAllValuesFrom expr) { + OWLDataRange range = expr.getFiller(); + DataRangeType type = range.getDataRangeType(); + if (type == DataRangeType.DATATYPE) + { + String datatypeName = fuzzyOwl2.getShortName(range.asOWLDatatype()); + if (fuzzyOwl2.fuzzyDatatypes.containsKey(datatypeName)) + fuzzyConcept = Concept.all(fuzzyOwl2.getDataPropertyName(expr.getProperty()), new Concept(datatypeName)); + } + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataHasValue) + */ + @Override + public void visit(OWLDataHasValue arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataMinCardinality) + */ + @Override + public void visit(OWLDataMinCardinality arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataExactCardinality) + */ + @Override + public void visit(OWLDataExactCardinality arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataMaxCardinality) + */ + @Override + public void visit(OWLDataMaxCardinality arg0) { + } + +} Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -19,6 +19,8 @@ import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.algorithms.isle.index.syntactic.SolrSyntacticIndex; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.owl.OWLEntityTypeAdder; @@ -48,8 +50,16 @@ final SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); final int maxNrOfInstancesPerClass = 10; + static final String solrServerURL = "http://solr.aksw.org/en_dbpedia_resources/"; + static final String searchField = "comment"; - + /* (non-Javadoc) + * @see org.dllearner.algorithms.isle.Experiment#getIndex() + */ + @Override + protected Index getIndex() { + return new SolrSyntacticIndex(ontology, solrServerURL, searchField); + } /* (non-Javadoc) * @see org.dllearner.algorithms.isle.Experiment#getOntology() @@ -81,10 +91,10 @@ cleanUpModel(sample); filter(sample, "http://dbpedia.org/ontology/"); OWLEntityTypeAdder.addEntityTypes(sample); - StmtIterator iterator = sample.listStatements(); - while(iterator.hasNext()){ - System.out.println(iterator.next()); - } +// StmtIterator iterator = sample.listStatements(); +// while(iterator.hasNext()){ +// System.out.println(iterator.next()); +// } try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/Experiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/Experiment.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/Experiment.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -12,8 +12,9 @@ import java.util.Set; import java.util.SortedSet; +import org.apache.log4j.Logger; import org.dllearner.algorithms.celoe.CELOE; -import org.dllearner.algorithms.isle.index.semantic.SemanticIndex; +import org.dllearner.algorithms.isle.index.Index; import org.dllearner.algorithms.isle.index.semantic.SemanticIndexGenerator; import org.dllearner.algorithms.isle.metrics.PMIRelevanceMetric; import org.dllearner.algorithms.isle.metrics.RelevanceMetric; @@ -50,6 +51,9 @@ */ public abstract class Experiment { + + private static final Logger logger = Logger.getLogger(Experiment.class.getName()); + /** * */ @@ -71,7 +75,7 @@ private String testFolder = "experiments/logs/"; - private OWLOntology ontology; + protected OWLOntology ontology; private Set<String> documents; private boolean initialized = false; @@ -93,10 +97,11 @@ documents = getDocuments(); // build semantic index -// SemanticIndex semanticIndex = SemanticIndexGenerator.generateIndex(documents, ontology, false); + Index index = getIndex(); + logger.info("Index created."); // // // set the relevance metric -// relevance = new PMIRelevanceMetric(semanticIndex); + relevance = new PMIRelevanceMetric(index); try { // set KB KnowledgeSource ks = new OWLAPIOntology(ontology); @@ -149,6 +154,10 @@ } } + protected Index getIndex(){ + return SemanticIndexGenerator.generateIndex(documents, ontology, false); + } + private Description getStartClass(NamedClass cls, boolean isEquivalenceProblem, boolean reuseExistingDescription){ //get instances of class to describe SortedSet<Individual> individuals = reasoner.getIndividuals(cls); @@ -224,6 +233,7 @@ public void run(NamedClass cls) throws ComponentInitException { initIfNecessary(); + logger.info("Learning definiton of class " + cls); // lp.setClassToDescribe(cls); //get the positive examples, here just the instances of the class to describe SortedSet<Individual> individuals = reasoner.getIndividuals(cls); @@ -233,8 +243,8 @@ //get the start class for the learning algorithms Description startClass = getStartClass(cls, equivalence, true); -// Map<Entity, Double> entityRelevance = RelevanceUtils.getRelevantEntities(cls, ontology, relevance); -// NLPHeuristic heuristic = new NLPHeuristic(entityRelevance); + Map<Entity, Double> entityRelevance = RelevanceUtils.getRelevantEntities(cls, ontology, relevance); + NLPHeuristic heuristic = new NLPHeuristic(entityRelevance); ClassLearningProblem clp = new ClassLearningProblem(reasoner); clp.setClassToDescribe(cls); @@ -248,7 +258,7 @@ // perform cross validation with ISLE ISLE isle = new ISLE(clp, reasoner); -// isle.setHeuristic(heuristic); + isle.setHeuristic(heuristic); isle.setMaxNrOfResults(20); isle.setOperator(rop); isle.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetricTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetricTest.java 2013-12-10 13:47:53 UTC (rev 4205) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetricTest.java 2013-12-10 14:35:02 UTC (rev 4206) @@ -27,7 +27,7 @@ public class PMIRelevanceMetricTest { AbstractRelevanceMetric metric; - static final String solrServerURL = "http://[2001:638:902:2010:0:168:35:138]:8080/solr/en_dbpedia_resources/"; + static final String solrServerURL = "http://solr.aksw.org/en_dbpedia_resources/"; static final String searchField = "comment"; static final String DBPEDIA_NS = "http://dbpedia.org/ontology/"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |