From: <ku...@us...> - 2012-05-03 14:32:07
|
Revision: 3682 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3682&view=rev Author: kurzum Date: 2012-05-03 14:31:56 +0000 (Thu, 03 May 2012) Log Message: ----------- missing examples in kb do not throw exception any more Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/utilities/analyse/TypeOntology.java Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2012-05-03 11:42:24 UTC (rev 3681) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2012-05-03 14:31:56 UTC (rev 3682) @@ -24,6 +24,7 @@ import java.util.Set; import java.util.TreeSet; +import org.apache.log4j.Logger; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; @@ -41,7 +42,8 @@ * */ public abstract class PosNegLP extends AbstractLearningProblem { - + private static Logger logger = Logger.getLogger(PosNegLP.class); + protected Set<Individual> positiveExamples = new TreeSet<Individual>(); protected Set<Individual> negativeExamples = new TreeSet<Individual>(); protected Set<Individual> allExamples = new TreeSet<Individual>(); @@ -114,10 +116,18 @@ allExamples = Helper.union(positiveExamples, negativeExamples); if(!reasoner.getIndividuals().containsAll(allExamples)) { - String str = "The examples below are not contained in the knowledge base (check spelling and prefixes)\n"; - Set<Individual> inds = Helper.difference(allExamples, reasoner.getIndividuals()); - str += inds.toString(); - throw new ComponentInitException(str); + Set<Individual> missing = Helper.difference(allExamples, reasoner.getIndividuals()); + double percentage = (double) (missing.size()/allExamples.size()); + percentage = Math.round(percentage * 1000) / 1000 ; + String str = "The examples ("+percentage+" % of total) below are not contained in the knowledge base (check spelling and prefixes)\n"; + str += missing.toString(); + if(missing.size()==allExamples.size()) { + throw new ComponentInitException(str); + } if(percentage < 0.10) { + logger.warn(str); + } else { + logger.error(str); + } } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/analyse/TypeOntology.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/analyse/TypeOntology.java 2012-05-03 11:42:24 UTC (rev 3681) +++ trunk/components-core/src/main/java/org/dllearner/utilities/analyse/TypeOntology.java 2012-05-03 14:31:56 UTC (rev 3682) @@ -33,7 +33,8 @@ Set<String> individuals = new HashSet<String>(); Set<Triple> triples = model.getGraph().find(Triple.ANY).toSet(); - ExtendedIterator<OntClass> itClass = model.listClasses(); + + ExtendedIterator<OntClass> itClass = model.listNamedClasses(); while (itClass.hasNext()) { classes.add(itClass.next().getURI()); } @@ -58,7 +59,7 @@ String sUri; String pUri; String oUri; - System.out.println(individuals); + //System.out.println(individuals); // foreach triple in the model for (Triple triple : triples) { @@ -72,16 +73,16 @@ // if subject is an Individual if (individuals.contains(sUri)) { - log.debug("Subject is an individuals {}",triple); + log.trace("Subject is an individual {}",triple); // if predicate is rdf:type if (pUri.equals(RDF.type.getURI())) { // if object is not in the list of class and not equals // owl:thing - if (!classes.contains(model.getResource(oUri)) + if (!classes.contains(oUri) && !oUri.equals(OWL.Thing.getURI())) { - model.getResource(oUri).addProperty(RDFS.subClassOf, OWL.Thing); + model.getResource(oUri).addProperty(RDF.type,OWL.Class); classes.add(oUri); changes++; log.debug("{} is a class",oUri); @@ -133,9 +134,16 @@ } // if subject is an owl:class } else if (classes.contains(sUri)) { - model.getResource(oUri).addProperty( - com.hp.hpl.jena.vocabulary.RDFS.subClassOf, OWL.Thing); - changes++; + log.trace("Subject is a class {}",triple); + + //TODO check this assumption + //if s is owl:class, then o is owl:class too ???? + if(!classes.contains(oUri) ){ + model.getResource(oUri).addProperty(RDF.type, OWL.Class); + classes.add(oUri); + log.debug("{} is a class",oUri); + changes++; + } } } return changes; @@ -156,11 +164,8 @@ } } // model.write(System.out); - int changes; - do{ - changes=this.addTypes(model); - } while(changes!=0); - + while(this.addTypes(model)!=0); + return model; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |