/*
 * Created on: 27 May 2008
 * Modified on: 27 May 2008
 */
package owl.test;

import java.net.URI;
import java.net.URL;
import java.util.Set;

import junit.framework.TestCase;

import org.mindswap.pellet.owlapi.Reasoner;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLDataFactory;
import org.semanticweb.owl.model.OWLIndividual;
import org.semanticweb.owl.model.OWLObjectProperty;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyManager;


/**
 * @author id812030
 */
public class OwlTest extends TestCase {

    public void testOwl() throws Exception {
        // charge l'ontology depuis un fichier
        URL ontologyUrl = Thread.currentThread().getContextClassLoader().getResource("owl/owl-test.owl");
        URI ontologyURI = URI.create(ontologyUrl.toExternalForm());

        // initialise un manager et un reasonner (on utilise Pellet pour ça)
        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
        OWLReasoner reasoner = new Reasoner(manager);

        // utilise le manager pour charger ontologie
        OWLOntology ontology = manager.loadOntologyFromPhysicalURI(ontologyURI);

        // charge l'ontologie dans le reasonner, vérifie la consistence et classifie
        // l'ontologie pour pouvoir raisonner dessus.
        reasoner.loadOntologies(manager.getImportsClosure(ontology));
        boolean isConsistent = reasoner.isConsistent(ontology);
        reasoner.classify();

        // instantie une data factorie
        OWLDataFactory dataFactory = manager.getOWLDataFactory();

        // récupère un Individu
        OWLIndividual individual = dataFactory.getOWLIndividual(URI.create("http://www.domain.com/owltest#W800i"));

        // récupère tout les individus d'une classes
        OWLClass clazz = dataFactory.getOWLClass(URI.create("http://www.domain.com/owltest#Offer"));
        Set<OWLIndividual> individuals = reasoner.getIndividuals(clazz, true);

        // récupère les individus lié à un individu donné celon une dataProperty
        OWLObjectProperty property = dataFactory.getOWLObjectProperty(URI.create("http://www.domain.com/owltest#hasPriceCategory"));
        reasoner.getRelatedIndividuals(individual, property);
    }

}
