1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// 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: licensing@clarkparsia.com
import org.mindswap.pellet.jena.PelletReasonerFactory;
import org.mindswap.pellet.PelletOptions;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.rdf.*;
import java.io.InputStream;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.ValidityReport;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.reasoner.*;
import java.util.Iterator;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import org.omg.CORBA.NameValuePair;
/**
* An example program that tests the DL-safe rules example from Table 3 in the
* paper: B. Motik, U. Sattler, R. Studer. Query Answering for OWL-DL with
* Rules. Proc. of the 3rd International Semantic Web Conference (ISWC 2004),
* Hiroshima, Japan, November, 2004, pp. 549-563
*
* @author Evren Sirin
*/
public class BB {
public static void main(String[] args) {
String ont = "http://www.owl-ontologies.com/MyPizza.owl";
OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC, null );
model.read( ont );
ObjectProperty hasPoids = model.getObjectProperty( ont + "#hasPoids" );
// les classes //
OntClass Pizza = model.getOntClass( ont + "#Pizza" );
OntClass GrosPizza = model.getOntClass( ont + "#GrosPizza" );
OntClass Poids = model.getOntClass( ont + "#Poids" );
// les individus //
Individual Pizza_1 = model.getIndividual( ont + "#Pizza_1" );
Individual Pizza_2 = model.getIndividual( ont + "#Pizza_2" );
Individual Poids_1 = model.getIndividual( ont + "#Poids_1" );
Individual Poids_2 = model.getIndividual( ont + "#Poids_2" );
model.prepare();
// pizza1 has poids poids 1
printPropertyValues( Pizza_1, hasPoids );
// Jamila est tante de marwa due to est_tante_de rule
//printPropertyValues( jamila, est_tante_de );
printInstances( Pizza );
printInstances( Poids );
printInstances( GrosPizza );// ici, normalement ça m'affiche Pizza_1 grâce à la règle SWRL
}
public static void printPropertyValues(Individual ind, Property prop) {
System.out.print( ind.getLocalName() + " has " + prop.getLocalName() + "(s): " );
printIterator( ind.listPropertyValues( prop ) );
}
public static void printInstances(OntClass cls) {
System.out.print( cls.getLocalName() + " instances: " );
printIterator( cls.listInstances() );
}
public static void printIterator(ExtendedIterator i) {
if( !i.hasNext() ) {
System.out.print( "none" );
}
else {
while( i.hasNext() ) {
Resource val = (Resource) i.next();
System.out.print( val.getLocalName() );
if( i.hasNext() )
System.out.print( ", " );
}
}
System.out.println();
}
} |
Partager