Discussion:
Problem in saving class instances to file
kumar rohit
2016-12-01 20:30:48 UTC
Permalink
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.

OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);

In the file when I enter name of a student, i-e Bob, it saves to the file
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved to
file.

I want record of all students so need all student instances. I used for
file writing.

try (FileOutputStream write = new FileOutputStream("D://students.owl")) {
model.write(write, "RDF/XML");
Lorenz B.
2016-12-02 08:18:03 UTC
Permalink
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the file
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved to
file.
I want record of all students so need all student instances. I used for
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://students.owl")) {
model.write(write, "RDF/XML");
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Claude Warren
2016-12-02 09:23:22 UTC
Permalink
It sounds to me like Kumar is thinking that he needs to store each student
in an individual file and load that. Kumar, if that is the case then I
think you misunderstand how the graph storage works. Or you have an
unusual use case. In most cases you would simply write the entire graph to
disk (Ususally using TDB as the storage engine as it will handle all the
persistence for you). If you really want to write each user to a separate
file then I would suggest creating a model using the Construct select to
pull all the data about the user and then write that graph to disk using
the standard graph.write() functionality.

Claude

On Fri, Dec 2, 2016 at 8:18 AM, Lorenz B. <
Post by Lorenz B.
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the file
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved to
file.
I want record of all students so need all student instances. I used for
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://students.owl"))
{
Post by kumar rohit
model.write(write, "RDF/XML");
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
kumar rohit
2016-12-02 10:57:21 UTC
Permalink
If you really want to write each user to a separate file

I dont want each user to a separate file, rather I want to save all the
individuals/students in one file. Some times ago, it worked for me but I
have made some changes to my code and now when I enter an individual, it
replaces the existing one and hence saves only one at a time.

I have checked the model before saving it to a file, and the model contains
only one individual (replaces existing one), so I think the problem is not
in the file saving itself.
Post by Claude Warren
It sounds to me like Kumar is thinking that he needs to store each student
in an individual file and load that. Kumar, if that is the case then I
think you misunderstand how the graph storage works. Or you have an
unusual use case. In most cases you would simply write the entire graph to
disk (Ususally using TDB as the storage engine as it will handle all the
persistence for you). If you really want to write each user to a separate
file then I would suggest creating a model using the Construct select to
pull all the data about the user and then write that graph to disk using
the standard graph.write() functionality.
Claude
On Fri, Dec 2, 2016 at 8:18 AM, Lorenz B. <
Post by Lorenz B.
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the
file
Post by Lorenz B.
Post by kumar rohit
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved
to
Post by Lorenz B.
Post by kumar rohit
file.
I want record of all students so need all student instances. I used for
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://
students.owl"))
Post by Lorenz B.
{
Post by kumar rohit
model.write(write, "RDF/XML");
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
Lorenz B.
2016-12-02 11:00:52 UTC
Permalink
Post by kumar rohit
If you really want to write each user to a separate file
I dont want each user to a separate file, rather I want to save all the
individuals/students in one file. Some times ago, it worked for me but I
have made some changes to my code and now when I enter an individual, it
replaces the existing one and hence saves only one at a time.
I have checked the model before saving it to a file, and the model contains
only one individual (replaces existing one), so I think the problem is not
in the file saving itself.
As I said, you have to load the existing model from the existing file.
Then work on this model. Then save this model to disk to the same file.
Post by kumar rohit
Post by Claude Warren
It sounds to me like Kumar is thinking that he needs to store each student
in an individual file and load that. Kumar, if that is the case then I
think you misunderstand how the graph storage works. Or you have an
unusual use case. In most cases you would simply write the entire graph to
disk (Ususally using TDB as the storage engine as it will handle all the
persistence for you). If you really want to write each user to a separate
file then I would suggest creating a model using the Construct select to
pull all the data about the user and then write that graph to disk using
the standard graph.write() functionality.
Claude
On Fri, Dec 2, 2016 at 8:18 AM, Lorenz B. <
Post by Lorenz B.
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the
file
Post by Lorenz B.
Post by kumar rohit
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved
to
Post by Lorenz B.
Post by kumar rohit
file.
I want record of all students so need all student instances. I used for
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://
students.owl"))
Post by Lorenz B.
{
Post by kumar rohit
model.write(write, "RDF/XML");
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
kumar rohit
2016-12-02 13:23:10 UTC
Permalink
Hello Lorenz, I tried to load the model from one owl file and then stored
it to another file (though both files have same data, but different names).
When I try to load model from owl file and store also into same file, it
then works fine and data is not overwritten.



On Fri, Dec 2, 2016 at 2:00 PM, Lorenz B. <
Post by kumar rohit
Post by kumar rohit
If you really want to write each user to a separate file
I dont want each user to a separate file, rather I want to save all the
individuals/students in one file. Some times ago, it worked for me but I
have made some changes to my code and now when I enter an individual, it
replaces the existing one and hence saves only one at a time.
I have checked the model before saving it to a file, and the model
contains
Post by kumar rohit
only one individual (replaces existing one), so I think the problem is
not
Post by kumar rohit
in the file saving itself.
As I said, you have to load the existing model from the existing file.
Then work on this model. Then save this model to disk to the same file.
Post by kumar rohit
Post by Claude Warren
It sounds to me like Kumar is thinking that he needs to store each
student
Post by kumar rohit
Post by Claude Warren
in an individual file and load that. Kumar, if that is the case then I
think you misunderstand how the graph storage works. Or you have an
unusual use case. In most cases you would simply write the entire
graph to
Post by kumar rohit
Post by Claude Warren
disk (Ususally using TDB as the storage engine as it will handle all the
persistence for you). If you really want to write each user to a
separate
Post by kumar rohit
Post by Claude Warren
file then I would suggest creating a model using the Construct select to
pull all the data about the user and then write that graph to disk using
the standard graph.write() functionality.
Claude
On Fri, Dec 2, 2016 at 8:18 AM, Lorenz B. <
Post by Lorenz B.
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the
file
Post by Lorenz B.
Post by kumar rohit
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved
to
Post by Lorenz B.
Post by kumar rohit
file.
I want record of all students so need all student instances. I used
for
Post by kumar rohit
Post by Claude Warren
Post by Lorenz B.
Post by kumar rohit
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://
students.owl"))
Post by Lorenz B.
{
Post by kumar rohit
model.write(write, "RDF/XML");
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
--
Lorenz BÃŒhmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Martynas Jusevičius
2016-12-02 13:58:35 UTC
Permalink
Where is the code??
Post by kumar rohit
Hello Lorenz, I tried to load the model from one owl file and then stored
it to another file (though both files have same data, but different names).
When I try to load model from owl file and store also into same file, it
then works fine and data is not overwritten.
On Fri, Dec 2, 2016 at 2:00 PM, Lorenz B. <
Post by kumar rohit
Post by kumar rohit
If you really want to write each user to a separate file
I dont want each user to a separate file, rather I want to save all the
individuals/students in one file. Some times ago, it worked for me but I
have made some changes to my code and now when I enter an individual, it
replaces the existing one and hence saves only one at a time.
I have checked the model before saving it to a file, and the model
contains
Post by kumar rohit
only one individual (replaces existing one), so I think the problem is
not
Post by kumar rohit
in the file saving itself.
As I said, you have to load the existing model from the existing file.
Then work on this model. Then save this model to disk to the same file.
Post by kumar rohit
Post by Claude Warren
It sounds to me like Kumar is thinking that he needs to store each
student
Post by kumar rohit
Post by Claude Warren
in an individual file and load that. Kumar, if that is the case then I
think you misunderstand how the graph storage works. Or you have an
unusual use case. In most cases you would simply write the entire
graph to
Post by kumar rohit
Post by Claude Warren
disk (Ususally using TDB as the storage engine as it will handle all the
persistence for you). If you really want to write each user to a
separate
Post by kumar rohit
Post by Claude Warren
file then I would suggest creating a model using the Construct select to
pull all the data about the user and then write that graph to disk using
the standard graph.write() functionality.
Claude
On Fri, Dec 2, 2016 at 8:18 AM, Lorenz B. <
Post by Lorenz B.
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the
file
Post by Lorenz B.
Post by kumar rohit
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved
to
Post by Lorenz B.
Post by kumar rohit
file.
I want record of all students so need all student instances. I used
for
Post by kumar rohit
Post by Claude Warren
Post by Lorenz B.
Post by kumar rohit
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://
students.owl"))
Post by Lorenz B.
{
Post by kumar rohit
model.write(write, "RDF/XML");
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Lorenz B.
2016-12-03 13:57:11 UTC
Permalink
Post by kumar rohit
Hello Lorenz, I tried to load the model from one owl file and then stored
it to another file (though both files have same data, but different names).
When I try to load model from owl file and store also into same file, it
then works fine and data is not overwritten.
I don't understand. Does it work now?
As far as I know, data will be always be overwritten if you write to a
file as most RDF formats do not allow for something like appending data.
Post by kumar rohit
On Fri, Dec 2, 2016 at 2:00 PM, Lorenz B. <
Post by kumar rohit
Post by kumar rohit
If you really want to write each user to a separate file
I dont want each user to a separate file, rather I want to save all the
individuals/students in one file. Some times ago, it worked for me but I
have made some changes to my code and now when I enter an individual, it
replaces the existing one and hence saves only one at a time.
I have checked the model before saving it to a file, and the model
contains
Post by kumar rohit
only one individual (replaces existing one), so I think the problem is
not
Post by kumar rohit
in the file saving itself.
As I said, you have to load the existing model from the existing file.
Then work on this model. Then save this model to disk to the same file.
Post by kumar rohit
Post by Claude Warren
It sounds to me like Kumar is thinking that he needs to store each
student
Post by kumar rohit
Post by Claude Warren
in an individual file and load that. Kumar, if that is the case then I
think you misunderstand how the graph storage works. Or you have an
unusual use case. In most cases you would simply write the entire
graph to
Post by kumar rohit
Post by Claude Warren
disk (Ususally using TDB as the storage engine as it will handle all the
persistence for you). If you really want to write each user to a
separate
Post by kumar rohit
Post by Claude Warren
file then I would suggest creating a model using the Construct select to
pull all the data about the user and then write that graph to disk using
the standard graph.write() functionality.
Claude
On Fri, Dec 2, 2016 at 8:18 AM, Lorenz B. <
Post by Lorenz B.
Post by kumar rohit
Hi
I want to create student instances of my Student class and enter his
details. Then at the end I writes model to the file.
OntClass std = model.getOntClass(ns + "Student");
Individual mystd = std.createIndividual(ns + stdname);
In the file when I enter name of a student, i-e Bob, it saves to the
file
Post by Lorenz B.
Post by kumar rohit
along other information like department, address etc.
Next time, when I enter another student name, i-e Alice, it replaces
previous instances of students and currently only one student is saved
to
Post by Lorenz B.
Post by kumar rohit
file.
I want record of all students so need all student instances. I used
for
Post by kumar rohit
Post by Claude Warren
Post by Lorenz B.
Post by kumar rohit
file writing.
I don't understand the problem. You have to load the existing model and
add new individuals to it. If you don't open the existing model, indeed
only what's added to your new model will be saved to the file.
Post by kumar rohit
try (FileOutputStream write = new FileOutputStream("D://
students.owl"))
Post by Lorenz B.
{
Post by kumar rohit
model.write(write, "RDF/XML");
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Continue reading on narkive:
Loading...