[Pellet-users] SWRL is supported din the OWLAPI right?

Crapo, Andrew (GE, Research) crapo at ge.com
Thu Mar 6 16:12:40 UTC 2008


Example 3 is very helpful!! Unfortunately, it doesn't include a built-in
with a constant and there I stumble. Below is code to add a rule to an
existing ontology. The modified ontology saves and looks ok as long as I
don't add the second builtin with the constant to the antecedent
(commented out in code below). If I do add it, the save fails with the
stack trace below the code. What am I doing wrong?

Andy

*********** code ****************
		OWLOntologyManager manager =
OWLManager.createOWLOntologyManager();
		SimpleURIMapper mapper = new
SimpleURIMapper(URI.create(modelUri), URI.create(altUrl));
		manager.addURIMapper(mapper);
		
		OWLDataFactory factory = manager.getOWLDataFactory();
		
		OWLOntology shapes = manager.loadOntology( URI.create(
altUrl ) );
		OWLClass oa_circle =
factory.getOWLClass(URI.create(modelNs + "Circle"));
		OWLDataProperty oa_radius =
factory.getOWLDataProperty(URI.create(modelNs + "radius"));
		OWLDataProperty oa_area =
factory.getOWLDataProperty(URI.create(modelNs + "area"));

		SWRLAtomIVariable var_x =
factory.getSWRLAtomIVariable(URI.create(modelNs + "x"));
		SWRLAtomDVariable var_r =
factory.getSWRLAtomDVariable(URI.create(modelNs + "r"));
		SWRLAtomDVariable var_r2 =
factory.getSWRLAtomDVariable(URI.create(modelNs + "r2"));
		SWRLAtomDVariable var_a =
factory.getSWRLAtomDVariable(URI.create(modelNs + "a"));
		OWLDataType floatDataType =
factory.getOWLDataType(XSDVocabulary.FLOAT.getURI());
		SWRLAtomConstantObject pi =
factory.getSWRLAtomConstantObject(factory.getOWLTypedConstant("3.14",
floatDataType));
		
		Set<SWRLAtom> antecedent = new HashSet<SWRLAtom>();
		SWRLClassAtom circleClassAtom =
factory.getSWRLClassAtom(oa_circle, var_x);
		antecedent.add(circleClassAtom);
		SWRLDataValuedPropertyAtom radiusAtom =
factory.getSWRLDataValuedPropertyAtom(oa_radius, var_x, var_r);
		antecedent.add(radiusAtom);
		List<SWRLAtomDObject> args1 = new
ArrayList<SWRLAtomDObject>();
		args1.add(var_r);
		args1.add(var_r);
		args1.add(var_r2);
		SWRLBuiltInAtom bi1 =
factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.MULTIPLY, args1);
		antecedent.add(bi1);
		List<SWRLAtomDObject> args2 = new
ArrayList<SWRLAtomDObject>();
		args2.add(var_r2);
		args2.add(pi);
		args2.add(var_a);
		SWRLBuiltInAtom bi2 =
factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.MULTIPLY, args2);
//		antecedent.add(bi2);
		
		SWRLDataValuedPropertyAtom areaAtom =
factory.getSWRLDataValuedPropertyAtom(oa_area, var_x, var_a);

		SWRLRule arearule = factory.getSWRLRule(antecedent,
Collections.singleton(areaAtom));
		manager.applyChange(new AddAxiom(shapes, arearule));

		manager.saveOntology(shapes);
*********** end code ************

*********** stack trace of error ***********
java.lang.IllegalStateException: Node is null!
	at
org.coode.owl.rdf.model.AbstractTranslator.getNode(AbstractTranslator.ja
va:867)
	at
org.coode.owl.rdf.model.AbstractTranslator.translateList(AbstractTransla
tor.java:880)
	at
org.coode.owl.rdf.model.AbstractTranslator.translateList(AbstractTransla
tor.java:881)
	at
org.coode.owl.rdf.model.AbstractTranslator.visit(AbstractTranslator.java
:691)
	at
uk.ac.manchester.cs.owl.SWRLBuiltInAtomImpl.accept(SWRLBuiltInAtomImpl.j
ava:63)
	at
org.coode.owl.rdf.model.AbstractTranslator.getNode(AbstractTranslator.ja
va:864)
	at
org.coode.owl.rdf.model.AbstractTranslator.translateList(AbstractTransla
tor.java:880)
	at
org.coode.owl.rdf.model.AbstractTranslator.translateList(AbstractTransla
tor.java:881)
	at
org.coode.owl.rdf.model.AbstractTranslator.addTriple(AbstractTranslator.
java:902)
	at
org.coode.owl.rdf.model.AbstractTranslator.visit(AbstractTranslator.java
:634)
	at
uk.ac.manchester.cs.owl.SWRLRuleImpl.accept(SWRLRuleImpl.java:67)
	at
org.coode.owl.rdf.rdfxml.RDFXMLRenderer.createGraph(RDFXMLRenderer.java:
273)
	at
org.coode.owl.rdf.rdfxml.RDFXMLRenderer.render(RDFXMLRenderer.java:219)
	at
org.coode.owl.rdf.rdfxml.RDFXMLOntologyStorer.storeOntology(RDFXMLOntolo
gyStorer.java:56)
	at
uk.ac.manchester.cs.owl.OWLOntologyManagerImpl.saveOntology(OWLOntologyM
anagerImpl.java:350)
	at
uk.ac.manchester.cs.owl.OWLOntologyManagerImpl.saveOntology(OWLOntologyM
anagerImpl.java:334)
	at
uk.ac.manchester.cs.owl.OWLOntologyManagerImpl.saveOntology(OWLOntologyM
anagerImpl.java:327)
	at
com.ge.research.eal.pellet.examples.BuildShapesExampleWithOWLApi.testBui
ldShapesOntologyUsingCombo(BuildShapesExampleWithOWLApi.java:312)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.jav
a:76)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Tes
tReference.java:38)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja
va:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)

*********** end stack trace ****************

> -----Original Message-----
> From: Michael Smith [mailto:msmith at clarkparsia.com] 
> Sent: Thursday, March 06, 2008 9:21 AM
> To: Crapo, Andrew (GE, Research)
> Cc: pellet-users at lists.owldl.com
> Subject: Re: [Pellet-users] SWRL is supported din the OWLAPI right?
> 
> On Thu, 2008-03-06 at 08:10 -0500, Crapo, Andrew (GE, Research) wrote:
> 
> 
> > Is there a code example of this somewhere? The file 
> MiscRuleTests.java has examples of adding rules to a 
> KnowledgeBase instance, but I can't see any way to save the 
> results. I'm assuming that the support through the OWLAPI is 
> using OWLOntology, not KnowledgeBase, so I can open an OWL 
> file, add rules, and save. I just haven't been able to find 
> either a coded example or documentation that explains how I 
> would do that using the OWLAPI.
> 
> Example 3 in the OWLAPI documentation [1] shows how to create 
> a rule, add it to an OWLOntology, and save that ontology.
> --
> Mike Smith
> 
> Clark & Parsia
> 
> [1] http://owlapi.sourceforge.net/documentation.html
> 
> 


More information about the Pellet-users mailing list