001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.algorithms.properties; 020 021import java.net.URL; 022import java.util.Collections; 023 024import org.dllearner.core.ComponentAnn; 025import org.dllearner.kb.SparqlEndpointKS; 026import org.dllearner.kb.sparql.SparqlEndpoint; 027import org.semanticweb.owlapi.model.AxiomType; 028import org.semanticweb.owlapi.model.IRI; 029import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom; 030import org.semanticweb.owlapi.model.OWLDataFactory; 031import org.semanticweb.owlapi.model.OWLObjectProperty; 032 033import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; 034 035import org.apache.jena.query.ParameterizedSparqlString; 036 037@ComponentAnn(name = "asymmetric object property axiom learner", shortName = "oplasymm", version = 0.1, description="A learning algorithm for asymmetric object property axioms.") 038public class AsymmetricObjectPropertyAxiomLearner extends ObjectPropertyCharacteristicsAxiomLearner<OWLAsymmetricObjectPropertyAxiom> { 039 040 public AsymmetricObjectPropertyAxiomLearner(SparqlEndpointKS ks) { 041 super(ks); 042 043 super.posExamplesQueryTemplate = new ParameterizedSparqlString( 044 "SELECT ?s ?o WHERE {?s ?p ?o. FILTER NOT EXISTS{?o ?p ?s}}"); 045 super.negExamplesQueryTemplate = new ParameterizedSparqlString( 046 "SELECT ?s ?o WHERE {?s ?p ?o. ?o ?p ?s}"); 047 048 super.POS_FREQUENCY_QUERY = new ParameterizedSparqlString( 049 "SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p ?o. FILTER NOT EXISTS{?o ?p ?s}}"); 050 051 axiomType = AxiomType.ASYMMETRIC_OBJECT_PROPERTY; 052 } 053 054 /* (non-Javadoc) 055 * @see org.dllearner.algorithms.properties.ObjectPropertyCharacteristicsAxiomLearner#getAxiom(org.semanticweb.owlapi.model.OWLObjectProperty) 056 */ 057 @Override 058 protected OWLAsymmetricObjectPropertyAxiom getAxiom(OWLObjectProperty property) { 059 return df.getOWLAsymmetricObjectPropertyAxiom(property); 060 } 061 062 public static void main(String[] args) throws Exception { 063 OWLDataFactory df = new OWLDataFactoryImpl(); 064 AsymmetricObjectPropertyAxiomLearner l = new AsymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS( 065 new SparqlEndpoint(new URL("http://live.dbpedia.org/sparql"), 066 Collections.singletonList("http://dbpedia.org"), Collections.<String> emptyList())));// .getEndpointDBpediaLiveAKSW())); 067 l.setEntityToDescribe(df.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/spouse"))); 068 l.setMaxExecutionTimeInSeconds(10); 069 l.init(); 070 l.start(); 071 System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); 072 } 073}