From: <lor...@us...> - 2012-03-26 12:19:30
|
Revision: 3619 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3619&view=rev Author: lorenz_b Date: 2012-03-26 12:19:20 +0000 (Mon, 26 Mar 2012) Log Message: ----------- Some changed needed to be consistent with parent pom and updated libs. Modified Paths: -------------- trunk/interfaces/pom.xml trunk/interfaces/src/main/assemble/archive.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Added Paths: ----------- trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java Removed Paths: ------------- trunk/scripts/src/main/resources/dbpedia_0.75.owl trunk/scripts/src/main/resources/dbpedia_0.75_no_datapropaxioms.owl Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/pom.xml 2012-03-26 12:19:20 UTC (rev 3619) @@ -15,7 +15,7 @@ </parent> <properties> - <release.name>1.0-beta-1</release.name> + <release.name>1.0-beta-2</release.name> </properties> <profiles> @@ -312,6 +312,7 @@ </dependency> <!--END Logging Dependencies--> + </dependencies> Modified: trunk/interfaces/src/main/assemble/archive.xml =================================================================== --- trunk/interfaces/src/main/assemble/archive.xml 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/main/assemble/archive.xml 2012-03-26 12:19:20 UTC (rev 3619) @@ -1,6 +1,7 @@ <assembly> <id>archive</id> <formats> + <format>zip</format> <format>tar.gz</format> <format>zip</format> </formats> @@ -33,6 +34,11 @@ <fileSet> <directory>../examples</directory> <outputDirectory>examples</outputDirectory> + <excludes> + <exclude> + **/qtl/ + </exclude> + </excludes> </fileSet> <fileSet> <directory>doc</directory> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -25,6 +25,7 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import java.util.Map.Entry; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Layout; @@ -123,9 +124,12 @@ AbstractCELA la = context.getBean(AbstractCELA.class); new CrossValidation(la,lp,rs,nrOfFolds,false); } else { - knowledgeSource = context.getBeansOfType(KnowledgeSource.class).entrySet().iterator().next().getValue(); - algorithm = context.getBean(LearningAlgorithm.class); - algorithm.start(); +// knowledgeSource = context.getBeansOfType(Knowledge1Source.class).entrySet().iterator().next().getValue(); + for(Entry<String, LearningAlgorithm> entry : context.getBeansOfType(LearningAlgorithm.class).entrySet()){ + algorithm = entry.getValue(); + logger.info("Running algorithm instance \"" + entry.getKey() + "\"(" + algorithm.getClass().getSimpleName() + ")"); + algorithm.start(); + } } } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -352,7 +352,7 @@ System.out.println(resource + " appears to be a class. Running appropriate algorithms.\n"); try { runClassLearningAlgorithms(ks, (NamedClass) resource); - } catch (Exception e) { + } catch (Exception e) {e.printStackTrace(); System.out.println(e.getCause()); } catch (Error e) { System.out.println(e.getCause()); Modified: trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -81,7 +81,7 @@ // setting for SPARQL based tests (0 = no special treatment, 1 = test only SPARQL // examples, 2 = skip SPARQL tests) - int sparql = 0; + int sparql = 2; // we use a logger, which outputs few messages (warnings, errors) SimpleLayout layout = new SimpleLayout(); Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -18,6 +18,7 @@ import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.NodeIterator; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -307,9 +308,9 @@ while ( residuePosition.hasNext() ) { RDFNode positionNode = residuePosition.next(); positionNodes.add(positionNode); - NodeIterator positionLabelNodes = _pdbIdModel.listObjectsOfProperty( positionNode.asResource(), hasValue ); + NodeIterator positionLabelNodes = _pdbIdModel.listObjectsOfProperty( positionNode.as(Resource.class), hasValue ); while ( positionLabelNodes.hasNext() ) { - positionLabels.add(positionLabelNodes.next().asLiteral().getInt()); + positionLabels.add(positionLabelNodes.next().as(Literal.class).getInt()); } } Added: trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,60 @@ +// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> +// This source code is available under the terms of the Affero General Public License v3. +// +// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions. +// Questions, comments, or requests for clarification: lic...@cl... + +package org.dllearner.scripts; + +import java.util.Collection; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; + +import org.semanticweb.owlapi.model.OWLNamedObject; +import org.semanticweb.owlapi.model.OWLObject; + +/** + * <p>Title: </p> + * + * <p>Description: </p> + * + * <p>Copyright: Copyright (c) 2008</p> + * + * <p>Company: Clark & Parsia, LLC. <http://www.clarkparsia.com></p> + * + * @author Evren Sirin + */ +public class DescriptionSorter { + + /** + * Sorts a set of OWLObjects alphabetically based on toString values. + * Named objects always come before unnamed objects. + * + * @param set the set to sort + * @return the sorted version of the set + */ + public static <N extends OWLObject> Set<N> toSortedSet(Collection<N> set) { + Set<N> sorted = new TreeSet<N>(new Comparator<N>() { + public int compare(N o1, N o2) { + boolean named1 = o1 instanceof OWLNamedObject; + boolean named2 = o2 instanceof OWLNamedObject; + int cmp; + if (named1 && !named2) + cmp = -1; + else if (!named1 && named2) + cmp = 1; + else + cmp = o1.toString().compareTo(o2.toString()); + + if( cmp == 0 && named1 && named2) + cmp = ((OWLNamedObject) o1).getIRI().compareTo( ((OWLNamedObject) o2).getIRI() ); + + return cmp; + } + }); + sorted.addAll(set); + return sorted; + } + +} Added: trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,181 @@ +// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> +// This source code is available under the terms of the Affero General Public License v3. +// +// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions. +// Questions, comments, or requests for clarification: lic...@cl... + +package org.dllearner.scripts; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLException; +import org.semanticweb.owlapi.reasoner.OWLReasoner; + +import com.clarkparsia.owlapi.explanation.io.ExplanationRenderer; +import com.clarkparsia.owlapi.explanation.io.manchester.BlockWriter; +import com.clarkparsia.owlapi.explanation.io.manchester.TextBlockWriter; + +/** + * An explanation renderer implementation that prints the axioms in the + * explanation using Manchester syntax. + * + * @author Evren Sirin + */ +public class ManchesterSyntaxExplanationRenderer implements ExplanationRenderer { + protected ManchesterSyntaxObjectRenderer renderer; + + protected BlockWriter writer; + + protected OWLAxiom currentAxiom; + + private boolean wrapLines = true; + + private boolean smartIndent = true; + + private int index; + + private OWLReasoner reasoner; + + public ManchesterSyntaxExplanationRenderer(OWLReasoner reasoner) { + this.reasoner = reasoner; + } + + /** + * {@inheritDoc} + */ + public void endRendering() { + writer.flush(); + } + + /** + * Returns the current axioms being whose explanation is being rendered or + * <code>null</code> if no axiom has been provided. + * + * @return the current axioms being whose explanation is being rendered or + * <code>null</code> if no axiom has been provided + */ + protected OWLAxiom getCurrentAxiom() { + return currentAxiom; + } + + /** + * Returns the current smart indent value. + * + * @return the current smart indent value + */ + public boolean isSmartIndent() { + return smartIndent; + } + + /** + * Returns the current line wrapping value. + * + * @return the current line wrapping value + */ + public boolean isWrapLines() { + return wrapLines; + } + + /** + * Render an explanation without the axiom header. This function is not guaranteed + * to be supported by the subclasses since an explanation renderer may rely on the + * axiom being explained to reorder the axioms or find irrelevant bits. + * + * @param explanations Set of explanations we are rendering + * @throws OWLException + * @throws IOException + * @throws UnsupportedOperationException + */ + public void render(Set<Set<OWLAxiom>> explanations) throws OWLException, + IOException, UnsupportedOperationException { + render( (OWLAxiom) null, explanations ); + } + + /** + * {@inheritDoc} + */ + public void render(OWLAxiom axiom, Set<Set<OWLAxiom>> explanations) throws OWLException, + IOException { + setCurrentAxiom( axiom ); + + if (index == 1) { + if (axiom != null) { + writer.print("Axiom: "); + axiom.accept(renderer); + writer.println(); + writer.println(); + } + if (explanations.isEmpty()) { + writer.println( "Explanation: AXIOM IS NOT ENTAILED!" ); + return; + } + writer.println("Explanation(s): "); + } + + String header = index++ + ")"; + writer.print(header); + renderSingleExplanation(explanations.iterator().next()); + writer.println(); + } + + protected void renderSingleExplanation(Set<OWLAxiom> explanation) throws OWLException, + IOException { + writer.printSpace(); + writer.printSpace(); + writer.printSpace(); + + writer.startBlock(); + + for( OWLAxiom a : explanation ) { + a.accept( renderer ); + if(reasoner.isEntailed(a)){ + writer.append("(ENTAILED)"); + } + writer.println(); + } + + writer.endBlock(); + writer.println(); + } + + protected void setCurrentAxiom(OWLAxiom currentAxiom) { + this.currentAxiom = currentAxiom; + } + + /** + * Sets the smart indent option which will align the elements of + * intersections and unions in columns when line wrapping is turned on. + * + * @param smartIndent + * the smart indent value + * @see #setWrapLines(boolean) + */ + public void setSmartIndent(boolean smartIndent) { + this.smartIndent = smartIndent; + } + + /** + * Sets the line wrapping option which will print the elements of + * intersections and unions into multiple lines. + * + * @param wrapLines + * the line wrapping value + */ + public void setWrapLines(boolean wrapLines) { + this.wrapLines = wrapLines; + } + + /** + * {@inheritDoc} + */ + public void startRendering(Writer w) { + writer = new TextBlockWriter( w ); + renderer = new ManchesterSyntaxObjectRenderer( this.writer ); + renderer.setWrapLines( isWrapLines() ); + renderer.setSmartIndent( isSmartIndent() ); + index = 1; + } +} Added: trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,867 @@ +// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> +// This source code is available under the terms of the Affero General Public License v3. +// +// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions. +// Questions, comments, or requests for clarification: lic...@cl... + +package org.dllearner.scripts; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; +import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationProperty; +import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLAnonymousIndividual; +import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLCardinalityRestriction; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataAllValuesFrom; +import org.semanticweb.owlapi.model.OWLDataComplementOf; +import org.semanticweb.owlapi.model.OWLDataExactCardinality; +import org.semanticweb.owlapi.model.OWLDataHasValue; +import org.semanticweb.owlapi.model.OWLDataIntersectionOf; +import org.semanticweb.owlapi.model.OWLDataMaxCardinality; +import org.semanticweb.owlapi.model.OWLDataMinCardinality; +import org.semanticweb.owlapi.model.OWLDataOneOf; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLDataUnionOf; +import org.semanticweb.owlapi.model.OWLDatatype; +import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom; +import org.semanticweb.owlapi.model.OWLDatatypeRestriction; +import org.semanticweb.owlapi.model.OWLDeclarationAxiom; +import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom; +import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLFacetRestriction; +import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; +import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLHasKeyAxiom; +import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObject; +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.OWLObjectInverseOf; +import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; +import org.semanticweb.owlapi.model.OWLObjectMinCardinality; +import org.semanticweb.owlapi.model.OWLObjectOneOf; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectUnionOf; +import org.semanticweb.owlapi.model.OWLObjectVisitor; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLPropertyExpression; +import org.semanticweb.owlapi.model.OWLQuantifiedRestriction; +import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLSameIndividualAxiom; +import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom; +import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLUnaryPropertyAxiom; +import org.semanticweb.owlapi.model.SWRLArgument; +import org.semanticweb.owlapi.model.SWRLAtom; +import org.semanticweb.owlapi.model.SWRLBuiltInAtom; +import org.semanticweb.owlapi.model.SWRLClassAtom; +import org.semanticweb.owlapi.model.SWRLDataPropertyAtom; +import org.semanticweb.owlapi.model.SWRLDataRangeAtom; +import org.semanticweb.owlapi.model.SWRLDifferentIndividualsAtom; +import org.semanticweb.owlapi.model.SWRLIndividualArgument; +import org.semanticweb.owlapi.model.SWRLLiteralArgument; +import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom; +import org.semanticweb.owlapi.model.SWRLRule; +import org.semanticweb.owlapi.model.SWRLSameIndividualAtom; +import org.semanticweb.owlapi.model.SWRLVariable; +import org.semanticweb.owlapi.vocab.XSDVocabulary; + +import com.clarkparsia.owlapi.explanation.io.manchester.BlockWriter; +import com.clarkparsia.owlapi.explanation.io.manchester.Keyword; + +public class ManchesterSyntaxObjectRenderer implements OWLObjectVisitor { + private boolean wrapLines = true; + private boolean smartIndent = true; + + protected BlockWriter writer; + + /** + * @param writer + */ + public ManchesterSyntaxObjectRenderer(BlockWriter writer) { + this.writer = writer; + } + + public boolean isSmartIndent() { + return smartIndent; + } + + public boolean isWrapLines() { + return wrapLines; + } + + public void setSmartIndent(boolean smartIndent) { + this.smartIndent = smartIndent; + } + + public void setWrapLines(boolean wrapLines) { + this.wrapLines = wrapLines; + } + + /** + * Return the short form (local name) for a URI identifier + * + * @param theIRI + * the URI + * @return the local name part of the URI identifier + */ + protected String shortForm(IRI theIRI) { + String fragment = theIRI.getFragment(); + if( fragment != null ) { + return fragment; + } + String str = theIRI.toString(); + int lastSlashIndex = str.lastIndexOf( '/' ); + if( lastSlashIndex != -1 ) { + return str.substring( lastSlashIndex + 1, str.length() ); + } + return str; + } + + public void visit(OWLAsymmetricObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.ASYMMETRIC_PROPERTY ); + } + + public void visit(OWLClass theOWLClass) { + write( theOWLClass.getIRI() ); + } + + public void visit(OWLClassAssertionAxiom theAxiom) { + writeKeywordInfix( Keyword.TYPE, theAxiom.getIndividual(), theAxiom.getClassExpression() ); + } + + public void visit(OWLAnnotation theAnnotation) { + write( Keyword.ANNOTATION ); + writeSpace(); + write( "(" ); + write( theAnnotation.getProperty() ); + write( " " ); + write( theAnnotation.getValue() ); + write( ")" ); + } + + public void visit(OWLDataAllValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.ONLY ); + } + + public void visit(OWLDataComplementOf theDescription) { + writeKeywordPrefix( Keyword.NOT, theDescription.getDataRange() ); + } + + public void visit(OWLDataExactCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.EXACTLY ); + } + + public void visit(OWLDataMaxCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MAX ); + } + + public void visit(OWLDataMinCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MIN ); + } + + public void visit(OWLDataOneOf theDescription) { + writeEnumeration( theDescription.getValues() ); + } + + public void visit(OWLDataProperty theProperty) { + write( theProperty.getIRI() ); + } + + public void visit(OWLDataPropertyAssertionAxiom theAxiom) { + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + } + + public void visit(OWLDataPropertyDomainAxiom theAxiom) { + writeKeywordInfix( Keyword.DOMAIN, theAxiom.getProperty(), theAxiom.getDomain() ); + } + + public void visit(OWLDataPropertyRangeAxiom theAxiom) { + writeKeywordInfix( Keyword.RANGE, theAxiom.getProperty(), theAxiom.getRange() ); + } + + public void visit(OWLFacetRestriction theRestriction) { + write( theRestriction.getFacet().getSymbolicForm() ); + writeSpace(); + write( theRestriction.getFacetValue() ); + } + + public void visit(OWLDatatypeRestriction theRestriction) { + + write( theRestriction.getDatatype() ); + write( "[" ); + boolean first = true; + for( OWLFacetRestriction restriction : theRestriction.getFacetRestrictions() ) { + if( first ) { + first = false; + } + else { + write( "," ); + writeSpace(); + } + write( restriction ); + } + write( "]" ); + + } + + public void visit(OWLDataSomeValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.SOME ); + } + + public void visit(OWLSubDataPropertyOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_PROPERTY_OF, theAxiom.getSubProperty(), theAxiom + .getSuperProperty() ); + } + + public void visit(OWLDatatype node) { + write( node.getIRI() ); + } + + public void visit(OWLDataHasValue theDescription) { + writeRestriction( theDescription.getProperty(), Keyword.VALUE, theDescription.getValue() ); + } + + public void visit(OWLDeclarationAxiom theAxiom) { + writeKeywordPrefix( Keyword.DECLARATION, theAxiom.getEntity() ); + } + + public void visit(OWLDifferentIndividualsAxiom theAxiom) { + writeNaryAxiom( theAxiom.getIndividuals(), Keyword.DIFFERENT_INDIVIDUAL, + Keyword.DIFFERENT_INDIVIDUALS ); + } + + public void visit(OWLDisjointClassesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getClassExpressions(), Keyword.DISJOINT_CLASS, + Keyword.DISJOINT_CLASSES ); + } + + public void visit(OWLDisjointDataPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.DISJOINT_PROPERTY, + Keyword.DISJOINT_PROPERTIES ); + } + + public void visit(OWLDisjointObjectPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.DISJOINT_PROPERTY, + Keyword.DISJOINT_PROPERTIES ); + } + + public void visit(OWLDisjointUnionAxiom theAxiom) { + write( theAxiom.getOWLClass() ); + writeSpace(); + write( Keyword.DISJOINT_UNION ); + writeSpace(); + writeNaryKeyword( Keyword.OR, theAxiom.getClassExpressions() ); + } + + public void visit(OWLEquivalentClassesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getClassExpressions(), Keyword.EQUIVALENT_TO, + Keyword.EQUIVALENT_CLASSES ); + } + + public void visit(OWLEquivalentDataPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.EQUIVALENT_TO, + Keyword.EQUIVALENT_PROPERTIES ); + } + + public void visit(OWLEquivalentObjectPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.EQUIVALENT_TO, + Keyword.EQUIVALENT_PROPERTIES ); + } + + public void visit(OWLFunctionalDataPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.FUNCTIONAL ); + } + + public void visit(OWLFunctionalObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.FUNCTIONAL ); + } + + public void visit(OWLAnonymousIndividual theIndividual) { + write( theIndividual.getID().getID() ); + } + + public void visit(OWLNamedIndividual theIndividual) { +// write( shortForm(theIndividual.getIRI()).toUpperCase() ); + write(theIndividual.getIRI()); + } + + public void visit(OWLInverseFunctionalObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.INVERSE_FUNCTIONAL ); + } + + public void visit(OWLInverseObjectPropertiesAxiom theAxiom) { + writeKeywordInfix( Keyword.INVERSE_OF, theAxiom.getFirstProperty(), theAxiom + .getSecondProperty() ); + } + + public void visit(OWLIrreflexiveObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.IRREFLEXIVE ); + } + + public void visit(OWLNegativeDataPropertyAssertionAxiom theAxiom) { + write( Keyword.NOT_RELATIONSHIP ); + writeSpace(); + write( "(" ); + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + write( ")" ); + } + + public void visit(OWLNegativeObjectPropertyAssertionAxiom theAxiom) { + write( Keyword.NOT_RELATIONSHIP ); + writeSpace(); + write( "(" ); + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + write( ")" ); + } + + public void visit(OWLObjectAllValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.ONLY ); + } + + public void visit(OWLObjectComplementOf theDescription) { + writeKeywordPrefix( Keyword.NOT, theDescription.getOperand() ); + } + + public void visit(OWLObjectExactCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.EXACTLY ); + } + + public void visit(OWLObjectIntersectionOf theDescription) { + writeNaryKeyword( Keyword.AND, theDescription.getOperands() ); + } + + public void visit(OWLObjectMaxCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MAX ); + } + + public void visit(OWLObjectMinCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MIN ); + } + + public void visit(OWLObjectOneOf theDescription) { + writeEnumeration( theDescription.getIndividuals() ); + } + + public void visit(OWLObjectProperty theProperty) { + write( theProperty.getIRI() ); + } + + public void visit(OWLObjectPropertyAssertionAxiom theAxiom) { + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + } + + public void visit(OWLSubPropertyChainOfAxiom theAxiom) { + writeCollection( theAxiom.getPropertyChain(), " o", false ); + writeSpace(); + write( Keyword.SUB_PROPERTY_OF ); + writeSpace(); + write( theAxiom.getSuperProperty() ); + } + + public void visit(OWLObjectPropertyDomainAxiom theAxiom) { + writeKeywordInfix( Keyword.DOMAIN, theAxiom.getProperty(), theAxiom.getDomain() ); + } + + public void visit(OWLObjectInverseOf theInverse) { + writeKeywordPrefix( Keyword.INVERSE, theInverse.getInverse() ); + } + + public void visit(OWLObjectPropertyRangeAxiom theAxiom) { + writeKeywordInfix( Keyword.RANGE, theAxiom.getProperty(), theAxiom.getRange() ); + } + + public void visit(OWLObjectHasSelf theRestriction) { + writeRestriction( theRestriction.getProperty(), Keyword.SELF ); + } + + public void visit(OWLObjectSomeValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.SOME ); + } + + public void visit(OWLSubObjectPropertyOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_PROPERTY_OF, theAxiom.getSubProperty(), theAxiom + .getSuperProperty() ); + } + + public void visit(OWLObjectUnionOf theDescription) { + writeNaryKeyword( Keyword.OR, theDescription.getOperands() ); + } + + public void visit(OWLObjectHasValue theDescription) { + writeRestriction( theDescription.getProperty(), Keyword.VALUE, theDescription.getValue() ); + } + + public void visit(OWLOntology ontology) { + write( ontology.getOntologyID().getOntologyIRI() ); + } + + public void visit(OWLReflexiveObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.REFLEXIVE_PROPERTY ); + } + + public void visit(OWLSameIndividualAxiom theAxiom) { + writeNaryAxiom( theAxiom.getIndividuals(), Keyword.SAME_INDIVIDUAL, + Keyword.SAME_INDIVIDUALS ); + } + + public void visit(OWLSubClassOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_CLASS_OF, theAxiom.getSubClass(), theAxiom.getSuperClass() ); + } + + public void visit(OWLSymmetricObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.SYMMETRIC ); + } + + public void visit(OWLTransitiveObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.TRANSITIVE ); + } + + public void visit(OWLLiteral node) { + if( node.isRDFPlainLiteral() ) { + write( "\"" ); + write( node.getLiteral() ); + write( "\"" ); + if( node.getLang() != null && !node.getLang().equals("")) { + write( "@" ); + write( node.getLang() ); + } + } + else if( node.getDatatype().getIRI().equals( XSDVocabulary.INTEGER.getIRI() ) + || node.getDatatype().getIRI().equals( XSDVocabulary.DECIMAL.getIRI() ) ) { + write( node.getLiteral() ); + } + else if( node.getDatatype().getIRI().equals( XSDVocabulary.FLOAT.getIRI() ) ) { + write( node.getLiteral() ); + write( "f" ); + } + else { + write( "\"" ); + write( node.getLiteral() ); + write( "\"" ); + write( "^^" ); + write( node.getDatatype() ); + } + } + + public void visit(SWRLLiteralArgument node) { + write( node.getLiteral() ); + } + + public void visit(SWRLIndividualArgument node) { + write( node.getIndividual() ); + } + + public void visit(SWRLVariable node) { + write( "?" ); + write( node.getIRI() ); + } + + public void visit(SWRLBuiltInAtom node) { + write( node.getPredicate() ); + write( "(" ); + for( SWRLArgument arg : node.getArguments() ) { + write( arg ); + write( " " ); + } + write( ")" ); + } + + public void visit(SWRLClassAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getArgument() ); + write( ")" ); + } + + /* + * this is all the SWRL rendering stuff that we'll provide some defaults for + * using evren's concise format stuff + */ + + public void visit(SWRLDataRangeAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getArgument() ); + write( ")" ); + } + + public void visit(SWRLDataPropertyAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + public void visit(SWRLDifferentIndividualsAtom node) { + write( "differentFrom" ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + public void visit(SWRLObjectPropertyAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + /** + * @inheritDoc + */ + public void visit(SWRLRule rule) { + write( "Rule" ); + write( "(" ); + +// if( !rule.isAnonymous() ) { +// write( rule.getIRI() ); +// writeSpace(); +// } + + boolean first = true; + for( SWRLAtom at : rule.getBody() ) { + if( first ) + first = false; + else + write( ", " ); + write( at ); + + } + write( " -> " ); + + first = true; + for( SWRLAtom at : rule.getHead() ) { + if( first ) + first = false; + else + write( ", " ); + write( at ); + } + + write( ")" ); + } + + public void visit(SWRLSameIndividualAtom node) { + write( "sameAs" ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + protected void writeNaryKeyword(Keyword theKeyword, Set<? extends OWLObject> theObjects) { + + theObjects = DescriptionSorter.toSortedSet( theObjects ); + + Iterator<? extends OWLObject> aIter = theObjects.iterator(); + + // write( "(" ); + + if( smartIndent ) + writer.startBlock(); + + write( aIter.next() ); + while( aIter.hasNext() ) { + if( wrapLines ) { + writeNewLine(); + } + else { + writeSpace(); + } + + if( theKeyword != null ) { + write( theKeyword ); + writeSpace(); + } + + write( aIter.next() ); + } + + if( smartIndent ) + writer.endBlock(); + + // write( ")" ); + } + + protected void writeCardinalityRestriction(OWLCardinalityRestriction<?, ?, ?> theRestriction, + Keyword theKeyword) { + if( theRestriction.isQualified() ) + writeRestriction( theRestriction.getProperty(), theKeyword, theRestriction + .getCardinality(), theRestriction.getFiller() ); + else + writeRestriction( theRestriction.getProperty(), theKeyword, theRestriction + .getCardinality() ); + } + + /** + * Render an n-ary axiom with special handling for the binary case. + * + * @param set + * objects to be rendered + * @param binary + * keyword used for binary case + * @param nary + * keyword used for n-ary case + */ + protected void writeNaryAxiom(Set<? extends OWLObject> set, Keyword binary, Keyword nary) { + Set<? extends OWLObject> sortedSet = DescriptionSorter.toSortedSet( set ); + Iterator<? extends OWLObject> aIter = sortedSet.iterator(); + + if( set.size() == 2 ) { + writeKeywordInfix( binary, aIter.next(), aIter.next() ); + } + else { + write( nary ); + write( "(" ); + + writeNaryKeyword( null, set ); + + write( ")" ); + } + } + + protected void writeQuantifiedRestriction(OWLQuantifiedRestriction<?, ?, ?> theRestriction, + Keyword theKeyword) { + writeRestriction( theRestriction.getProperty(), theKeyword, theRestriction.getFiller() ); + } + + protected void writeRestriction(OWLPropertyExpression<?, ?> theProperty, Keyword theKeyword, + Object... theArgs) { + write( "(" ); + + write( theProperty ); + writeSpace(); + write( theKeyword ); + for( Object aObject : theArgs ) { + writeSpace(); + if( aObject instanceof OWLObject ) { + write( (OWLObject) aObject ); + } + else { + write( aObject.toString() ); + } + } + + write( ")" ); + + } + + protected void writeUnaryPropertyAxiom(OWLUnaryPropertyAxiom<?> theAxiom, Keyword keyword) { + writeKeywordPrefix( keyword, theAxiom.getProperty() ); + } + + protected void writeKeywordPrefix(Keyword keyword, OWLObject arg) { + write( keyword ); + writeSpace(); +// write( "(" ); + write( arg ); +// write( ")" ); + } + + protected void writeKeywordPrefix(Keyword keyword, OWLObject arg1, OWLObject arg2) { + write( keyword ); + writeSpace(); + write( "(" ); + write( arg1 ); + writeSpace(); + write( arg2 ); + write( ")" ); + } + + protected void writeKeywordInfix(Keyword keyword, OWLObject arg1, OWLObject arg2) { + write( arg1 ); + writeSpace(); + write( keyword ); + writeSpace(); + write( arg2 ); + } + + protected void writeEnumeration(Set<? extends OWLObject> objects) { + write( Keyword.OPEN_BRACE ); + writeCollection( objects, ",", true ); + write( Keyword.CLOSE_BRACE ); + } + + protected void writeCollection(Collection<? extends OWLObject> objects, String separator, boolean sort) { + if( sort ) + objects = DescriptionSorter.toSortedSet( objects ); + boolean first = true; + for( OWLObject ind : objects ) { + if( first ) { + first = false; + } + else { + write( separator ); + writeSpace(); + } + write( ind ); + } + } + + protected void write(OWLObject object) { + object.accept( this ); + } + + protected void write(Keyword keyword) { + write( keyword.getLabel().toUpperCase() ); + } + + protected void write(String s) { + writer.print( s ); + } + + protected void write(IRI iri) { + write( shortForm( iri ) ); + } + + protected void writeNewLine() { + writer.println(); + } + + protected void writeSpace() { + write( " " ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLHasKeyAxiom theAxiom) { + write( theAxiom.getClassExpression() ); + writeSpace(); + write( Keyword.HAS_KEY ); + if( !theAxiom.getObjectPropertyExpressions().isEmpty() ) { + writeCollection( theAxiom.getObjectPropertyExpressions(), "", true ); + writeSpace(); + } + writeCollection( theAxiom.getDataPropertyExpressions(), "", true ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLDatatypeDefinitionAxiom theAxiom) { + writeKeywordInfix( Keyword.EQUIVALENT_TO, theAxiom.getDatatype(), theAxiom.getDataRange() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationAssertionAxiom theAxiom) { + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getValue() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLSubAnnotationPropertyOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_PROPERTY_OF, theAxiom.getSubProperty(), theAxiom.getSuperProperty() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationPropertyDomainAxiom theAxiom) { + writeKeywordInfix( Keyword.DOMAIN, theAxiom.getProperty(), theAxiom.getDomain() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationPropertyRangeAxiom theAxiom) { + writeKeywordInfix( Keyword.RANGE, theAxiom.getProperty(), theAxiom.getRange() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLDataIntersectionOf node) { + writeNaryKeyword( Keyword.AND, node.getOperands() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLDataUnionOf node) { + writeNaryKeyword( Keyword.OR, node.getOperands() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationProperty property) { + write( property.getIRI() ); + } + + /** + * {@inheritDoc} + */ + public void visit(IRI iri) { + write( iri ); + } +} Added: trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,43 @@ +package org.dllearner.scripts; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLOntology; + +public class OntologyCleaner { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + List<String> namespaces = Arrays.asList(new String[]{"http://schema.org/"}); + OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument( + OntologyCleaner.class.getClassLoader().getResourceAsStream("dbpedia_0.75.owl")); + + //get all entities starting with one of the declared namespaces + Set<OWLAxiom> axioms2Remove = new HashSet<OWLAxiom>(); + for(OWLAxiom axiom : ontology.getLogicalAxioms()){ + for(OWLEntity entity : axiom.getSignature()){ + for(String namespace : namespaces){ + if(entity.toStringID().startsWith(namespace)){ + axioms2Remove.add(axiom); + } + } + + } + } + OWLManager.createOWLOntologyManager().removeAxioms(ontology, axioms2Remove); + OWLManager.createOWLOntologyManager().saveOntology(ontology, new RDFXMLOntologyFormat(), new FileOutputStream(new File("src/main/resources/dbpedia_0.75_cleaned.owl"))); + + } + +} Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -1,9 +1,12 @@ package org.dllearner.scripts; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; import java.net.URL; import java.util.Map; +import java.util.Map.Entry; import java.util.TreeMap; -import java.util.Map.Entry; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -18,16 +21,19 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; public class SPARQLEndpointMetrics { //parameters for thread pool //Parallel running Threads(Executor) on System - private static int corePoolSize = 1; + private static int corePoolSize = 5; //Maximum Threads allowed in Pool private static int maximumPoolSize = 20; //Keep alive time for waiting threads for jobs(Runnable) private static long keepAliveTime = 10; + + private static int queryTimeout = 30; /** * @param args @@ -84,9 +90,13 @@ ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(endpoints.size()); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue); + final BufferedWriter output = new BufferedWriter(new FileWriter("log/endpointMetrics.html", true)); + final StringBuffer sb = new StringBuffer(); - sb.append("<table border=\"1\">"); - sb.append("<tr><th>#classes</th><th>#op</th><th>#dp</th><th>#individuals</th></tr>"); + sb.append("<table border=\"1\">\n"); + sb.append("<tr><th>endpoint</th><th>#classes</th><th>#op</th><th>#dp</th><th>URL</th><th>ERROR</th></tr>\n"); + output.append(sb.toString()); + output.flush(); // perform enrichment on endpoints for(final Entry<String,SparqlEndpoint> endpoint : endpoints.entrySet()) { @@ -96,30 +106,70 @@ @Override public void run() { SparqlEndpoint se = endpoint.getValue(); + String name = endpoint.getKey(); // System.out.println(se); String filter = "FILTER()"; try { //count classes - String query = "SELECT (COUNT(DISTINCT ?type) AS ?cnt) WHERE {?s a ?type.}"; - int classCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); +// String query = "SELECT (COUNT(DISTINCT ?type) AS ?cnt) WHERE {?s a ?type.}"; +// int classCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); +// +// //count object properties +// query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; +// int opCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); +// +// //count data properties +// query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; +// int dpCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); +// +// //count individuals +// query = "SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.}"; +// int indCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); + String query = "SELECT DISTINCT ?type WHERE {?s a ?type. ?type a <http://www.w3.org/2002/07/owl#Class>}"; + int classCnt = countEntities(query, se); + //count object properties - query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; - int opCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); + query = "SELECT DISTINCT ?p WHERE {?s ?p ?o. ?p a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; + int opCnt = countEntities(query, se); //count data properties - query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; - int dpCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); + query = "SELECT DISTINCT ?p WHERE {?s ?p ?o. ?p a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + int dpCnt = countEntities(query, se); //count individuals - query = "SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.}"; - int indCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); +// query = "SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.}"; +// int indCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); - sb.append("<tr><td>" + classCnt + "</td><td>" + opCnt + "</td>" + "</td><td>" + dpCnt + "</td><td>" + indCnt + "</td></tr>\n"); + String line = "<tr><td>" + name + "</td><td>" + + classCnt + "</td><td>" + + opCnt + "</td><td>" + + dpCnt + "</td><td>" + + se.getURL() + "</td><td>" + + "" + "</td></tr>\n"; + + sb.append(line); + output.append(line); + output.flush(); + System.out.println(sb); } catch (Exception e) { - sb.append(""); + Throwable t = e.getCause(); + String errorCode; + if(t == null){ + errorCode = e.getClass().getSimpleName(); + } else { + errorCode = t.getMessage(); + } + String line = "<tr><td>" + name + "</td><td>-1</td><td>-1</td><td>-1</td><td>" + se.getURL() + "</td><td>" + errorCode + "</tr>\n"; + sb.append(line); + try { + output.append(line); + output.flush(); + } catch (IOException e1) { + e1.printStackTrace(); + } } } @@ -127,7 +177,39 @@ } threadPool.shutdown(); System.out.println(sb); - + } + + private static int countEntities(String baseQuery, SparqlEndpoint endpoint) throws Exception{ + int cnt = 0; + int limit = 1000; + int offset = 0; + ResultSet rs; + int tmp = 0; + do{ + String query = baseQuery + " LIMIT " + limit + " OFFSET " + offset;System.out.println(endpoint.getURL() + ": " + query); + rs = executeQuery(query, endpoint); + tmp = 0; + while(rs.hasNext()){ + rs.next(); + tmp++; + } + cnt += tmp; + offset += limit; + } while (tmp >= limit); + + return cnt; + } + + private static ResultSet executeQuery(String queryString, SparqlEndpoint endpoint) throws Exception{ + try { + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), queryString); + qe.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + qe.setTimeout(queryTimeout * 1000); + return qe.execSelect(); + } catch (Exception e) { + throw e; + } + } } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -19,6 +19,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -26,6 +27,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.Random; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -78,7 +80,6 @@ import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import com.clarkparsia.owlapi.explanation.PelletExplanation; -import com.clarkparsia.owlapi.explanation.io.manchester.ManchesterSyntaxExplanationRenderer; import com.clarkparsia.pellet.owlapiv3.PelletReasoner; import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; import com.hp.hpl.jena.query.Query; @@ -121,6 +122,8 @@ private OWLReasoner dbpediaReasoner; private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + private Random randomGen = new Random(2222343); + static {PelletExplanation.setup();} public SPARQLSampleDebugging(SparqlEndpoint endpoint) { @@ -160,6 +163,23 @@ } } + private Set<OWLAxiom> getBlackList(){ + Set<OWLAxiom> blacklist = new HashSet<OWLAxiom>(); + OWLAxiom ax = factory.getOWLSubClassOfAxiom( + factory.getOWLObjectSomeValuesFrom(factory.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/leaderName")), factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Person"))), + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Settlement"))); + blacklist.add(ax); + ax = factory.getOWLSubClassOfAxiom( + factory.getOWLObjectSomeValuesFrom(factory.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/language")), factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Language"))), + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Work"))); + blacklist.add(ax); + ax = factory.getOWLSubClassOfAxiom( + factory.getOWLObjectSomeValuesFrom(factory.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/officialLanguage")), factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Language"))), + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Country"))); + blacklist.add(ax); + return blacklist; + } + private void writeToDB(String resource, int fragementSize, boolean consistent, Set<Set<OWLAxiom>> explanations) { try { ps.setString(1, resource); @@ -225,25 +245,19 @@ return resources; } - private Set<String> extractSampleResourcesSingle(int size){ - logger.info("Extracting " + sampleSize + " sample resources..."); + private String extractSampleResource(int maxOffset){ long startTime = System.currentTimeMillis(); - Set<String> resources = new HashSet<String>(); - String query = "SELECT COUNT(DISTINCT ?s) WHERE {?s a ?type}"; + int random = randomGen.nextInt(maxOffset); + logger.info("Extracting sample resource (" + random + ")..."); + + String query = String.format("SELECT DISTINCT ?s WHERE {?s a ?type} LIMIT 1 OFFSET %d", random); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - int max = rs.next().getLiteral(rs.getResultVars().get(0)).getInt(); + String resource = rs.next().getResource("s").getURI(); - for(int i = 0; i < size; i++){ - int random = (int)(Math.random() * max); - query = String.format("SELECT DISTINCT ?s WHERE {?s a ?type} LIMIT 1 OFFSET %d", random); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - resources.add(rs.next().getResource("s").getURI()); - } - logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); - return resources; + return resource; } private OWLOntology extractSampleModule(Set<String> resources){ @@ -280,17 +294,12 @@ return explanations; } - private Set<Set<OWLAxiom>> computeExplanations(PelletReasoner reasoner){ + private Set<Set<OWLAxiom>> computeExplanations(PelletReasoner reasoner) throws Exception{ logger.info("Computing explanations..."); long startTime = System.currentTimeMillis(); PelletExplanation expGen = new PelletExplanation(reasoner); Set<Set<OWLAxiom>> explanations = new HashSet<Set<OWLAxiom>>(maxNrOfExplanations); - try { - explanations = expGen.getInconsistencyExplanations(maxNrOfExplanations); - } catch (Exception e) { - e.printStackTrace(); - logger.error(e); - } + explanations = expGen.getInconsistencyExplanations(maxNrOfExplanations); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return explanations; } @@ -387,7 +396,7 @@ } }); OWLDataFactory f = OWLManager.createOWLOntologyManager().getOWLDataFactory(); - ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(dbpediaReasoner); PrintWriter out = new PrintWriter( System.out ); for(OWLObjectProperty p : reasoner.getRootOntology().getObjectPropertiesInSignature()){ boolean satisfiable = reasoner.isSatisfiable(f.getOWLObjectExactCardinality(1, p)); @@ -427,9 +436,12 @@ } - public void run(OWLOntology reference) throws OWLOntologyCreationException{ - Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); - ontologies.add(reference); + + public void computeSampleExplanations(OWLOntology reference, int nrOfExplanations) throws OWLOntologyCreationException, IOException{ + Set<Set<OWLAxiom>> sampleExplanations = new HashSet<Set<OWLAxiom>>(); + manager = reference.getOWLOntologyManager(); + manager.removeAxioms(reference, getBlackList()); + PelletReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(reference); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); Set<OWLClass> unsatisfiableClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); @@ -438,25 +450,70 @@ logger.info("Unsatisfiable object properties(" + unsatisfiableObjectProperties.size() + "): " + unsatisfiableObjectProperties); Set<OWLDataProperty> unsatisfiableDataProperties = getUnsatisfiableDataProperties(reasoner); logger.info("Unsatisfiable data properties(" + unsatisfiableDataProperties.size() + "): " + unsatisfiableDataProperties); - OWLOntology merged; OWLOntology module; + reasoner.isConsistent(); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + man.addOntologyChangeListener( reasoner ); + Model model; - Set<String> resources = extractSampleResourcesChunked(sampleSize); - for(String resource : resources){resource = "http://dbpedia.org/resource/Leipzig"; - logger.info("Resource " + resource); - module = extractSampleModule(Collections.singleton(resource)); - ontologies.add(module); - merged = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://merged.en"), ontologies); - reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(merged); + FileWriter out = new FileWriter( "log/alljustifications" + System.currentTimeMillis() + ".txt" ); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(dbpediaReasoner); + renderer.startRendering(out ); + + String query = "SELECT COUNT(DISTINCT ?s) WHERE {?s a ?type}"; + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int maxOffset = rs.next().getLiteral(rs.getResultVars().get(0)).getInt(); + + while(sampleExplanations.size() < nrOfExplanations){ + String resource = extractSampleResource(maxOffset);//resource = "http://dbpedia.org/resource/Pigeon_%28company%29"; + logger.info("###################################################################"); + logger.info("Resource " + resource);//resource = "http://dbpedia.org/resource/The_Man_Who_Wouldn%27t_Die"; + module = extractSampleModule(resource);module.getOWLOntologyManager().removeAxioms(module, module.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)); + manager.addAxioms(reference, module.getABoxAxioms(true)); + manager.removeAxioms(reference, reference.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)); boolean isConsistent = reasoner.isConsistent(); logger.info("Consistent: " + isConsistent); Set<Set<OWLAxiom>> explanations = null; if(!isConsistent){ - explanations = computeExplanations(reasoner); + explanations = new HashSet<Set<OWLAxiom>>(); + try { + explanations.addAll(computeExplanations(reasoner)); + } catch (Exception e1) { + continue; + } + model = convert(reference); + explanations.addAll(computeInconsistencyExplanationsByAsymmetryPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByIrreflexivityPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByFunctionalityPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByInverseFunctionalityPattern(reference, model)); logger.info("Found " + explanations.size() + " explanations."); + for(Set<OWLAxiom> exp : explanations){ + logger.info(exp + "\n"); + out.flush(); + try { + renderer.render( Collections.singleton(exp) ); + } catch (UnsupportedOperationException e) { + e.printStackTrace(); + } catch (OWLException e) { + e.printStackTrace(); + } + } + boolean addSample = true; + while(addSample){ + int rnd = 0; + if(explanations.size() > 1){ + rnd = new Random().nextInt(explanations.size()-1); + } + Set<OWLAxiom> sampleExplanation = new ArrayList<Set<OWLAxiom>>(explanations).get(rnd); + if(!containsUnsatisfiableObjectProperty(sampleExplanation)){ + sampleExplanations.add(sampleExplanation); + addSample = false; + } + + } + Map<AxiomType, Integer> axiomType2CountMap = new HashMap<AxiomType, Integer>(); for(Set<OWLAxiom> explanation : explanations){ - logger.info(explanation); for(OWLAxiom axiom : explanation){ Integer cnt = axiomType2CountMap.get(axiom.getAxiomType()); if(cnt == null){ @@ -466,19 +523,35 @@ axiomType2CountMap.put(axiom.getAxiomType(), cnt); } } + logger.info("Axiom type count:"); for(Entry<AxiomType, Integer> entry : axiomType2CountMap.entrySet()){ logger.info(entry.getKey() + "\t: " + entry.getValue()); } } - ontologies.remove(module); - reasoner.dispose(); + man.removeAxioms(reference, module.getABoxAxioms(true)); // writeToDB(resource, module.getLogicalAxiomCount(), isConsistent, explanations); - break; } + renderer.endRendering(); + FileWriter sampleOut = new FileWriter( "log/sample_justifications" + System.currentTimeMillis() + ".txt" ); + ManchesterSyntaxExplanationRenderer sampleRenderer = new ManchesterSynta... [truncated message content] |