You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by neha gupta <ne...@gmail.com> on 2016/09/06 07:12:57 UTC

Creating individuals if not already exists

I have created Students individuals in Jena and stored them in a file.
Every time students login, updates their information like GPA and updates
stored in the file.
Student.createIndividual(ns, stdName);

With this statement, suppose a student Neha is created with her information
in the file. Next time, she login, again a new instance will be created
when the application executes
*Student.createIndividual(ns, stdName);?*

*Is there any condition which states if the individual not already exists,
create it otherwise skip createIndividual statement?*

Re: Creating individuals if not already exists

Posted by "John A. Fereira" <ja...@cornell.edu>.
It would be difficult to do as the criteria for “an individual exists” could vary.  For example, you can’t simply check if the rdfs:label for a Student already exist as it’s possible that there are two students with the same name.  You might need to check for a unique studentID, or a combination of first name, last name, and email address, or any other set of properties which will unique identify a Student.

If you’re storing Students in a file, why not just check if the student is in the file?





On 9/6/16, 9:45 AM, "neha gupta" <ne...@gmail.com> wrote:

>So it means there is no method which check if an individual exists or not?
>
>On Tue, Sep 6, 2016 at 4:55 AM, John A. Fereira <ja...@cornell.edu> wrote:
>
>> You could run a query to get a resource with specific criteria (e.g. it
>> has an rdfs:label which has the users name).  If you get a result, replace
>> the triple which has their GPS, otherwise create a new Student.
>>
>> -----Original Message-----
>> From: neha gupta [mailto:neha.banglor@gmail.com]
>> Sent: Tuesday, September 6, 2016 3:13 AM
>> To: users@jena.apache.org
>> Subject: Creating individuals if not already exists
>>
>> I have created Students individuals in Jena and stored them in a file.
>> Every time students login, updates their information like GPA and updates
>> stored in the file.
>> Student.createIndividual(ns, stdName);
>>
>> With this statement, suppose a student Neha is created with her
>> information in the file. Next time, she login, again a new instance will be
>> created when the application executes *Student.createIndividual(ns,
>> stdName);?*
>>
>> *Is there any condition which states if the individual not already exists,
>> create it otherwise skip createIndividual statement?*
>>

Re: Creating individuals if not already exists

Posted by Chris Dollin <ch...@epimorphics.com>.
On 06/09/16 14:45, neha gupta wrote:
> So it means there is no method which check if an individual exists or not?

No, it does not mean that.

An Individual with URI u "exists" if a Resource with that URI has
a property rdf:type of some (Ont)Class. So if you really wanted
to know, you can use createResource to get a suitable Resource and
look for a type property.

>> With this statement, suppose a student Neha is created with her
>> information in the file. Next time, she login, again a new instance will be
>> created when the application executes *Student.createIndividual(ns,
>> stdName);?*

That depends what you mean by a "new instance". If you cann
createIndividual(URI) twice, there will still only be one individual
in the OntModel even if you have two different Java objects representing
it. So I don't think you need to worry about whether the individual
"already exists" or not.

Also: (A) createIndividual's has one [1] argument which is the URI for
this individual, doesn't it? Not two as you've shown? Unless Student
isn't an OntClass. Is it?

(B) You might want to consider using a database/triple store like
     TDB rather than repeatedly loading and saving a file.

Chris

[1] Or none, in which case it's going to make a blank node and there
     /will/ be multiple "different" individuals.

-- 
"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)

Re: Creating individuals if not already exists

Posted by neha gupta <ne...@gmail.com>.
So it means there is no method which check if an individual exists or not?

On Tue, Sep 6, 2016 at 4:55 AM, John A. Fereira <ja...@cornell.edu> wrote:

> You could run a query to get a resource with specific criteria (e.g. it
> has an rdfs:label which has the users name).  If you get a result, replace
> the triple which has their GPS, otherwise create a new Student.
>
> -----Original Message-----
> From: neha gupta [mailto:neha.banglor@gmail.com]
> Sent: Tuesday, September 6, 2016 3:13 AM
> To: users@jena.apache.org
> Subject: Creating individuals if not already exists
>
> I have created Students individuals in Jena and stored them in a file.
> Every time students login, updates their information like GPA and updates
> stored in the file.
> Student.createIndividual(ns, stdName);
>
> With this statement, suppose a student Neha is created with her
> information in the file. Next time, she login, again a new instance will be
> created when the application executes *Student.createIndividual(ns,
> stdName);?*
>
> *Is there any condition which states if the individual not already exists,
> create it otherwise skip createIndividual statement?*
>

RE: Creating individuals if not already exists

Posted by "John A. Fereira" <ja...@cornell.edu>.
You could run a query to get a resource with specific criteria (e.g. it has an rdfs:label which has the users name).  If you get a result, replace the triple which has their GPS, otherwise create a new Student.

-----Original Message-----
From: neha gupta [mailto:neha.banglor@gmail.com] 
Sent: Tuesday, September 6, 2016 3:13 AM
To: users@jena.apache.org
Subject: Creating individuals if not already exists

I have created Students individuals in Jena and stored them in a file.
Every time students login, updates their information like GPA and updates stored in the file.
Student.createIndividual(ns, stdName);

With this statement, suppose a student Neha is created with her information in the file. Next time, she login, again a new instance will be created when the application executes *Student.createIndividual(ns, stdName);?*

*Is there any condition which states if the individual not already exists, create it otherwise skip createIndividual statement?*