[Pellet-users] Problems with SWRLFactory: <coping Rules between 2 OWLModels>

Dimitar Hodzhev dimitar.hodzhev at insa-lyon.fr
Thu Dec 6 16:41:05 UTC 2007


Hi all,

I try to copy the Rules from one OWLModel to another.
I do everything like explained, but I get following exception:

" java.lang.ClassCastException:  
edu.stanford.smi.protegex.owl.model.impl.DefaultRDFList
	at  
edu.stanford.smi.protegex.owl.swrl.model.impl.DefaultSWRLImp.getBody(Unknown  
Source)
	at  
edu.stanford.smi.protegex.owl.swrl.model.impl.DefaultSWRLImp.getBrowserText(Unknown  
Source)
	at  
edu.stanford.smi.protegex.owl.swrl.model.SWRLFactory.copyImps(Unknown  
Source) "

Here is my test code:

"
#####################################
import java.util.Collection;
import java.util.Iterator;

import org.mindswap.pellet.jena.PelletReasonerFactory;

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 edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLFactory;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLImp;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLAtomList;

import edu.stanford.smi.protegex.owl.jena.protege2jena.Protege2Jena;

class Test {

	public static void  main (String[] args)
	{
		// -- OntologyA --
		String uriA = "http://dionisbg.di.funpic.de/familyA.owl";
		OWLModel modelA=null;
		SWRLFactory factoryA=null;

		try {
				modelA=ProtegeOWL.createJenaOWLModelFromURI(uriA);
				System.out.println("ModelA loaded ...");
			}
			catch (java.lang.Exception e) {
				e.printStackTrace();
			}
		factoryA = new SWRLFactory(modelA);
		System.out.println("SWRL FactoryA created ...");



		// -- OntologyB --
		String uriB = "http://dionisbg.di.funpic.de/familyB.owl";
		OWLModel modelB=null;
		SWRLFactory factoryB=null;

		try {
			modelB=ProtegeOWL.createJenaOWLModelFromURI(uriB);
			System.out.println("ModelB loaded ...");
		}
		catch (java.lang.Exception e) {
			e.printStackTrace();
		}
		factoryB = new SWRLFactory(modelB);
		System.out.println("SWRL FactoryB created ...");



		// -- Coping the Rules from A to B --
		try {
			factoryB.copyImps(modelA);
		}
		catch (java.lang.Exception e){
			e.printStackTrace();
		}

############################################################"

I get the same exception when I try to copy a single Rule like this :

"
try {

				SWRLImp grandpaRule_A = factoryA.getImp("family:GrandfatherRule");
				SWRLAtomList bodyA= grandpaRule_A.getBody();
				SWRLAtomList headB= grandpaRule_A.getHead();

				factoryB.createImpWithGivenName("family:GrandfatherRule");
				SWRLImp grandpaRule_B = factoryB.getImp("family:GrandfatherRule");
				grandpaRule_B.setBody(bodyA);
				grandpaRule_B.setHead(headB);

			}
			catch (java.lang.Exception e) {
				   e.printStackTrace();
			}
"

Did anybody have problems like this or do anyone have idea what I do wrong ?

Thanks a lot,
Dimitar Hodzhev



More information about the Pellet-users mailing list