Hello Lorenz, this was the question I was expected to ask? I mean values of BestCategory are resources. Kindly if you can guide me how to get the value, I searched it on the web but could not found any related resources.
Kind regards On Wed, Jan 18, 2017 at 10:57 AM, Lorenz B. < [email protected]> wrote: > > > OntModel model2=ModelFactory.createOntologyModel( > OntModelSpec.OWL_DL_MEM); > > InputStream in =FileManager.get().open("F://20-8.owl"); > > if (in==null) { > > throw new IllegalArgumentException( "File: " + " not > > found"); > > } model2.read(in,""); > > > > String ns=" > > http://www.semanticweb.org/t/ontologies/2016/7/myOWL#"; > > > > OntProperty favcat=model2.getOntProperty(ns+ "BestCategory"); > > String name=jTextField1.getText(); > > Individual indiv = user1.createIndividual(ns + name); > > RDFNode phFav=indiv.getPropertyValue(favcat); > > if (phFav!=null){ > > Literal l1=phFav.asLiteral(); > If BestCategory is an object property, why do you cast the value as > literal?! > > > > s1=l1.toString(); } > > } > > if (s1=="CatPhysics"){ > > JOptionPane.showMessageDialog(null, "Physics"); > > } > > > > The rule itself is > > > > String rule ="[rule1: ( ?x http://www.semanticweb.org/ > > t/ontologies/2016/7/myOWL#Physics_Preferred_Category ?cat1 )" + > > "( ?x http://www.semanticweb.org/t/ontologies/2016/7/myOWL# > > Chem_Preferred_Category ?cat2 )" + > > "( ?x http://www.semanticweb.org/t/ontologies/2016/7/myOWL#Geo_ > > Preferred_Category ?cat3 )" + > > "greaterThan(?cat1,?cat2), greaterThan(?cat1,?cat3)" > > + " -> (?x http://www.semanticweb.org/t/ > > ontologies/2016/7/myOWL#BestCategory http://www.semanticweb.org/t/ > > ontologies/2016/7/myOWL#BestCategory#Physics )]"; > > > > > > The BestCategory is object property. > > > > Regards > > > > > > On Tue, Jan 17, 2017 at 8:16 PM, Andy Seaborne <[email protected]> wrote: > > > >> A Complete, Minimal Example please. > >> > >> > >> Partial code, no data is not complete. > >> It must compile and run to be complete. > >> > >> Minimal means only what is necessary to ask the question not the whole > >> data or whole application. > >> > >> Andy > >> > >> On 17/01/17 17:14, Sidra shah wrote: > >> > >>> I am surprise that when there is no value in BestCategory, it gives me > no > >>> error and when the rule executes and value comes in BestCategory, it > gives > >>> me now *"RequiredLiteralException*" > >>> > >>> The code I used here is > >>> > >>> OntProperty favcat=model2.getOntProperty(ns+ "BestCategory"); > >>> > >>> RDFNode phFav=indiv.getPropertyValue(favcat); > >>> if (phFav!=null){ > >>> Literal l1=phFav.asLiteral(); > >>> > >>> s1=l1.toString();} > >>> > >>> if (s1=="CatPhysics"){ > >>> JOptionPane.showMessageDialog(null, "Physics"); > >>> } > >>> > >>> Best regards > >>> > >>> On Tue, Jan 17, 2017 at 5:53 PM, Sidra shah <[email protected]> > >>> wrote: > >>> > >>> Hello Chris, thanks a lot for your suggestion. > >>>> Best regards. > >>>> > >>>> On Tue, Jan 17, 2017 at 5:37 PM, Chris Dollin < > >>>> [email protected]> wrote: > >>>> > >>>> > >>>>> On 17/01/17 13:30, Sidra shah wrote: > >>>>> > >>>>> Hi Lorenz, I am sorry but with much regards, you discussed here the > >>>>>> problem, not the solution :) :) > >>>>>> > >>>>>> I know this if there is no value, there must be Null exception, > >>>>>> > >>>>>> > >>>>> This is not true. > >>>>> > >>>>> but can you suggest me a way where we dodge the compiler > >>>>> > >>>>>> > >>>>> No "dodging" of the compiler is required. Instead, just write > >>>>> perfectly ordinary code that tests to see if the result of > >>>>> getPropertyValue is null, and take one action if it isn't and > >>>>> a different one if it is. > >>>>> > >>>>> There's nothing special about this. You don't need to use > >>>>> break (which is for escaping from loops); just an if > >>>>> with suitable then and else parts. > >>>>> > >>>>> I know this is more a Java problem, but any help I will appreciate. > >>>>> > >>>>>> > >>>>> Find someone /local/ doing the same or similar course and talk to > >>>>> them (and have them talk to you) about programming and this > >>>>> problem. I don't mean copy each other's work; I mean use each > >>>>> other to understand what the problem is about and how the code > >>>>> works. Each of you will know things that the other doesn't; share. > >>>>> > >>>>> Chris > >>>>> > >>>>> -- > >>>>> "He could not weigh up which was worse and so tried not to think > about > >>>>> either." > >>>>> /The Spellgrinder's > >>>>> Apprentice/ > >>>>> > >>>>> Epimorphics Ltd, http://www.epimorphics.com > >>>>> Registered address: Court Lodge, 105 High Street, Portishead, Bristol > >>>>> BS20 6PT > >>>>> Epimorphics Ltd. is a limited company registered in England (number > >>>>> 7016688) > >>>>> > >>>>> > >>>> > -- > Lorenz Bühmann > AKSW group, University of Leipzig > Group: http://aksw.org - semantic web research center > >
