[Pellet-users] how to fetch individuals with certain properties
Matthew Horridge
matthew.horridge at cs.man.ac.uk
Mon Jun 9 18:47:04 UTC 2008
Hi Alex,
I think you also might be able to get the individuals by asking for
instances of "hasTag some rdfs:Literal".... rdfs:Literal is the top
datatype. To do this in the OWL API you can create an
OWLDataSomeRestriction with the property hasTag and a filler of
rdfs:Literal which you can get from the data factory using
getTopDatatype. You can then ask Pellet (via the OWLReasoner
interface) for instances of this restriction.
Cheers,
Matthew
On 9 Jun 2008, at 19:05, Alexander Becker wrote:
> Hi!
>
> Thats right, I don't care exactely what is contained in the hasTag
> property, I just want to see if there is any hasTag property defined.
>
> But even if I name the OWLConstant to one of the individuals I have
> in the ontology (as seen in {hasTag=["NPM"^^string],
> hasTier=["pos"^^string]}m so I name it "NPM"), I don't get any
> results.
>
> Again, my code so far:
> [code]
> @Test
> /**
> * Fetch some individuals with certain properties.
> */
> public void proptest() {
> OWLDataFactory factory =
> OWLManager.createOWLOntologyManager().getOWLDataFactory();
> OWLDataProperty dataprop =
> factory.getOWLDataProperty(URI.create(url + "#hasTag"));
>
> OWLDataType stringDataType = factory.getOWLDataType(URI.create("http://www.w3.org/2001/XMLSchema#string
> "));
> OWLConstant constant = factory.getOWLTypedConstant("NPM",
> stringDataType);
>
> //OWLConstant constant = factory.getOWLUntypedConstant("NPN");
> OWLRestriction restriction =
> factory.getOWLDataValueRestriction(dataprop, constant);
>
> Set<OWLIndividual> rv = reasoner.getIndividuals(restriction, true);
>
> System.out.println(rv);
> }
> [/code]
>
>
> HTH, Alex
>
> PS: Thanks for the for loop thing. It reminds me of Perl, so I like
> it :)
>
> -------- Original-Nachricht --------
>> Datum: Mon, 9 Jun 2008 18:45:09 +0100
>> Von: "robert davey \\(JIC\\)" <robert.davey at bbsrc.ac.uk>
>> An: "Alexander Becker" <trennung at weinenvorglueck.de>
>> Betreff: RE: RE: [Pellet-users] how to fetch individuals with
>> certain properties
>
>> I'm guessing it's because you are looking for the hasTag property,
>> filled
>> with "test" as the typed constant datavalue. Unless a data property
>> is in
>> your ontology that has this value and is referenced to an
>> individual, you
>> won't get any results back. I presume you are looking for all
>> individuals
>> that have _any_ value in the hasTag property?
>>
>> As an aside, I see you're using java 1.5 (with generics), so you
>> can use
>> the nice for loop function instead of an iterator. As you have
>> typed the
>> all_ind set to OWLIndividual, so:
>>
>> Iterator ii = all_ind.iterator(); // ii = individual iterator
>> while( ii.hasNext() ) {
>> OWLIndividual ind = (OWLIndividual) ii.next();
>>
>> becomes:
>>
>> for (OWLIndividual i : all_ind)
>>
>> and you can do away with the casting as a result too.
>>
>> Hope this helps,
>>
>> Rob
>>
>> -----Original Message-----
>> From: Alexander Becker [mailto:trennung at weinenvorglueck.de]
>> Sent: Mon 6/9/2008 6:04 PM
>> To: robert davey (JIC)
>> Subject: Re: RE: [Pellet-users] how to fetch individuals with certain
>> properties
>>
>> Hi Rob,
>>
>> thanks for the exapmle and the link. I didn't found that one.
>> But now, after knowing how the way to use those things, I'm stuck
>> with
>> fetching the properties.
>>
>> I can get them from a known individual this way:
>> [code]
>> @Test // it's a junit test case that i abuse to test small
>> pieces of
>> code
>> /**
>> * Show the properties of an individual.
>> */
>> public void get_props() {
>> Set<OWLIndividual> all_ind = reasoner.getIndividuals();
>>
>> System.out.println("individual count: " + all_ind.size());
>>
>> Iterator ii = all_ind.iterator(); // ii = individual iterator
>> while( ii.hasNext() ) {
>> OWLIndividual ind = (OWLIndividual) ii.next();
>>
>> Map<OWLDataProperty,Set<OWLConstant>> props =
>> reasoner.getDataPropertyRelationships(ind);
>>
>> System.out.println(props.toString());
>> break;
>> }
>>
>> }
>> [/code]
>>
>> The output is:
>> [quote]
>> individual count: 417
>> {hasTag=["NPM"^^string], hasTier=["pos"^^string]}
>> [/quote]
>>
>> And now, I want to do it the other way, fetch some Individuals that
>> have a
>> property:
>> [code]
>> @Test
>> /**
>> * fetch some individuals with certain properties.
>> */
>> public void proptest() {
>> OWLDataFactory factory =
>> OWLManager.createOWLOntologyManager().getOWLDataFactory();
>> OWLDataProperty dataprop =
>> factory.getOWLDataProperty(URI.create(ontURI.toString() +
>> "#hasTag"));
>>
>> OWLDataType stringDataType =
>> factory.getOWLDataType(URI.create("http://www.w3.org/2001/XMLSchema#string
>> "));
>>
>> OWLConstant constant = factory.getOWLTypedConstant("test",
>> stringDataType);
>> OWLRestriction restriction =
>> factory.getOWLDataValueRestriction(dataprop, constant);
>>
>> Set<OWLIndividual> rv = reasoner.getIndividuals(restriction, true);
>>
>> System.out.println(rv);
>> }
>> [/code]
>>
>> But that doesn't work as I get an empty set as resut (output = "[]").
>>
>> So, where is my mistake?
>>
>> Cheers, Alex
>>
>> -------- Original-Nachricht --------
>>> Datum: Sun, 8 Jun 2008 17:14:51 +0100
>>> Von: "robert davey \\(JIC\\)" <robert.davey at bbsrc.ac.uk>
>>> An: trennung at weinenvorglueck.de, pellet-users at lists.owldl.com
>>> Betreff: RE: [Pellet-users] how to fetch individuals with certain
>> properties
>>
>>> Hi Alex,
>>>
>>> You can create OWLDescriptions from any implementing class, such as
>>> OWLRestriction:
>>>
>>> OWLDataFactory factory =
>>> OWLManager.createOWLOntologyManager().getOWLDataFactory();
>>> OWLDataProperty dataprop =
>>> factory.getOWLDataProperty("http://ontology/uri#hasTag");
>>> OWLConstant constant = factory.getOWLTypedConstant("test",
>>> "http://www.w3.org/2001/XMLSchema#string");
>>> OWLRestriction restriction =
>> factory.getOWLDataValueRestriction(dataprop,
>>> constant);
>>>
>>> I'm pretty sure there are some examples of how to do this in the
>>> OWLAPI
>>> examples...
>>>
>>>
>> http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/examples/src/main/java/org/coode/owlapi/examples/Example7.java
>>>
>>> Cheers
>>>
>>> Rob
>>>
>>> ---------------------------------------
>>> Dr. Rob Davey
>>> NCYC / Institute of Food Research
>>> Computational Biology / John Innes Centre
>>> Norwich Research Park
>>> Norwich, Norfolk, NR4 7HU
>>>
>>> Tel IFR : +44 (0)1603 251449 / x1449
>>> Tel JIC : +44 (0)1603 450833 / x2833
>>> Web : http://cbr.jic.ac.uk/dicks/
>>> ---------------------------------------
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: pellet-users-bounces at lists.owldl.com on behalf of
>>> trennung at weinenvorglueck.de
>>> Sent: Sat 6/7/2008 4:55 PM
>>> To: pellet-users at lists.owldl.com
>>> Subject: [Pellet-users] how to fetch individuals with certain
>>> properties
>>>
>>> Hello!
>>>
>>> I want to get all individuals, that have some properties.
>>> They must have one of these: hasTag, startswith or endswith.
>>> hasTag is
>> an
>>> OWLDataProperty, as I get (with some others) via:
>>> Set<OWLDataProperty>
>>> my_dprops = reasoner.getDataProperties();
>>>
>>> Is it possible, to create an OWLDescription and get all matching
>>> individuals
>>> like that:
>>> [code]
>>> OWLDescription clsC = new OWLDescription(); // OWLDescription is
>> abstract,
>>> doesn't work that way.
>>>
>>> // public Set<OWLIndividual> getIndividuals(OWLDescription
>>> clsC,
>>> boolean direct)
>>> Set<OWLIndividual> results = reasoner.getIndividuals(clsC,
>> false);
>>> [/code]
>>>
>>> If so, my primary question is: how do I create the OWLDescription?
>>>
>>> best regards, Alex
>>> --
>>> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
>>> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>>> _______________________________________________
>>> Pellet-users mailing list
>>> Pellet-users at lists.owldl.com
>>> http://lists.owldl.com/mailman/listinfo/pellet-users
>>> _______________________________________________
>>>
>>> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
>>
>> --
>> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
>> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
>
> --
> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> _______________________________________________
> Pellet-users mailing list
> Pellet-users at lists.owldl.com
> http://lists.owldl.com/mailman/listinfo/pellet-users
> _______________________________________________
>
> Sponsored by Clark & Parsia, LLC http://clarkparsia.com/
More information about the Pellet-users
mailing list