You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Don S <do...@gmail.com> on 2012/05/29 06:00:55 UTC
Updating Tuples in the graph
HI,
I am developing a semantic application. As a first step to understand the
concept I made a simple ontology using protege and used Jena for query the
data under eclipse platforms. Its working fine. But when I tried to update
the triples in the graph it is not updating the graph rather it is adding
in memory. I will thankful if some one can give an idea or related articles
for updating the graph.
The update query is
Model model =ModelFactory.createOntologyModel();
~~~~Some lines of code
String queryString ="PREFIX owl: <http://localhost:3030/personal.owl#>\r\n"
+
"INSERT DATA" +
"{" +
"<http://localhost:3030/personal.owl#Age3>\n" +
"owl:hasAge 98." +
"}";
GraphStore gs=GraphStoreFactory.create();
gs.setDefaultGraph(model.getGraph());
UpdateRequest ur = UpdateFactory.create(queryString);
Update update = ur.getOperations().get(0);
UpdateAction.execute(ur,gs);
System.out.println(update);
Print result for "update" variable
INSERT DATA {
<http://localhost:3030/personal.owl#Age3> <
http://localhost:3030/personal.owl#hasAge> 98 .
}
After applying the SELECT query the results come like this
-----------------------------------------------------------
| Age | hasAge |
===========================================================
| owl:Age3 | 98 |
| owl:Age2 | "40"^^<http://www.w3.org/2001/XMLSchema#int> |
| owl:Age1 | "20"^^<http://www.w3.org/2001/XMLSchema#int> |
-----------------------------------------------------------
With Regards
Re: Updating Tuples in the graph
Posted by Andy Seaborne <an...@apache.org>.
On 30/05/12 08:25, Don S wrote:
> HI,
>
>
> My server if Fuseki. and the server configuration is *java -Xmx1200M -jar
> fuseki-server.jar --update --mem /ds/data *
You seem to be using Fuseki as a plain HTTP server by dropping files in
the /pages area.
You are not using the dataset are /ds.
> *
> *
> When I gave * FileOutputStream fileour =new FileOutputStream("
> http://localhost:3030/per1.owl");*
> * model.write(fileour,"RDF/XML-ABBREV");* Shows an error
>
> Exception in thread "main" java.io.FileNotFoundException:
> http:\localhost:3030\per2.owl (The filename, directory name, or volume
> label syntax is incorrect)
That's not a file name - that's a URL. As you can see, / has become \
because you are on windows.
You can't update the /pages area.
> I will be thankful to you if you can give me an idea.
Take a step back - if you want to update remote data you need to
understand how that is going to happen.
1/ You'll need to use an RDF database - TDB comes Fuseki.
2/ Do update via a remote SPARQL Update
UpdateExecutionFactory.createRemote
Start by trying the simple UI that comes with Fuseki to interact with
your data.
3/ See also the graph store protocol and do an HTTP PUT to send back to
data into a dataset.
Andy
Re: Re: Updating Tuples in the graph
Posted by Don S <do...@gmail.com>.
HI,
My server if Fuseki. and the server configuration is *java -Xmx1200M -jar
fuseki-server.jar --update --mem /ds/data *
*
*
When I gave * FileOutputStream fileour =new FileOutputStream("
http://localhost:3030/per1.owl");*
* model.write(fileour,"RDF/XML-ABBREV");* Shows an error
Exception in thread "main" java.io.FileNotFoundException:
http:\localhost:3030\per2.owl (The filename, directory name, or volume
label syntax is incorrect)
I will be thankful to you if you can give me an idea.
My code
* * static final String inputFileName = "http://localhost:3030/";
public static void main(String[] args) throws IOException{
Model model =ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException( "File: " + inputFileName +
" not found");
}
// read the RDF/XML file
model.read(inputFileName+"per.owl");
in.close();
String queryString ="PREFIX xmlns:
<http://localhost:3030/per1.owl#>\r\n"
+
"PREFIX base: <
http://localhost:3030/per1.owl>\r"+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#
>\r"+
"INSERT DATA" +
"{"+
"<http://localhost:3030/per1.owl#Person_7>\n"
+
" xmlns:hasFirstname
\"harapa\" ^^ xsd:string." +
"}";
String queryString1 =
"PREFIX owl: <http://localhost:3030/per1.owl#>" +
"SELECT * "+
"FROM <http://localhost:3030/per1.owl>"+
"WHERE"+
"{"+
"?Name owl:hasFirstname ?hasFirstname." +
"}";
//ontology part
GraphStore gs=GraphStoreFactory.create(model);
gs.setDefaultGraph(model.getGraph());
UpdateRequest ur = UpdateFactory.create(queryString);
Update update = ur.getOperations().get(0);
UpdateAction.execute(ur,gs);
System.out.println(update);
// search part
Query query = QueryFactory.create(queryString1);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
model.write(System.out);
qe.close();
}
Regards
On Tue, May 29, 2012 at 7:19 AM, Chris Dollin
<ch...@epimorphics.com>wrote:
> On Tuesday, May 29, 2012 06:44:23 PM don wrote:
> > But I need to save the file back to
> > the server. May I know the procedure for doing that.
>
> It will depend on your server.
>
> What's your server?
>
> Chris
>
> --
> "It does not need to take events in their correct order."
> /Hexwood/
>
> 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: Re: Updating Tuples in the graph
Posted by Chris Dollin <ch...@epimorphics.com>.
On Tuesday, May 29, 2012 06:44:23 PM don wrote:
> But I need to save the file back to
> the server. May I know the procedure for doing that.
It will depend on your server.
What's your server?
Chris
--
"It does not need to take events in their correct order." /Hexwood/
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: Updating Tuples in the graph
Posted by Andy Seaborne <an...@apache.org>.
On 30/05/12 02:44, don wrote:
> Dear Andy,
>
> Really thankful to you for your reply. It is working fine and I am able
> see the result in console
> window when I gave the command "
> model.write(System.out,"RDF/XML-ABBREV");. But I need to save the file
> back to
> the server. May I know the procedure for doing that.
>
> Regards
> Don
This question is on answers.semanticweb.com:
http://answers.semanticweb.com/questions/16603/writing-ontology-back-to-server
which has answers.
Andy
>
>
>
>
>
>
> On 5/29/2012 12:58 AM, Andy Seaborne wrote:
>> On 29/05/12 05:00, Don S wrote:
>>> HI,
>>>
>>> I am developing a semantic application. As a first step to understand
>>> the
>>> concept I made a simple ontology using protege and used Jena for
>>> query the
>>> data under eclipse platforms. Its working fine. But when I tried to
>>> update
>>> the triples in the graph it is not updating the graph rather it is
>>> adding
>>> in memory. I will thankful if some one can give an idea or related
>>> articles
>>> for updating the graph.
>>>
>>> The update query is
>>>
>>> Model model =ModelFactory.createOntologyModel();
>>
>> This is an in-memory model.
>>
>> Do you then call model.read() or otherwise load data? That wil be
>> in-memory.
>>
>>> ~~~~Some lines of code
>>>
>>> String queryString ="PREFIX
>>> owl:<http://localhost:3030/personal.owl#>\r\n"
>>> +
>>> "INSERT DATA" +
>>> "{" +
>>> "<http://localhost:3030/personal.owl#Age3>\n" +
>>> "owl:hasAge 98." +
>>> "}";
>>> GraphStore gs=GraphStoreFactory.create();
>> > gs.setDefaultGraph(model.getGraph());
>>
>> Simpler?
>>
>> GraphStore gs=GraphStoreFactory.create(model);
>>
>>> UpdateRequest ur = UpdateFactory.create(queryString);
>>> Update update = ur.getOperations().get(0);
>>> UpdateAction.execute(ur,gs);
>>> System.out.println(update);
>>>
>>> Print result for "update" variable
>>> INSERT DATA {
>>> <http://localhost:3030/personal.owl#Age3> <
>>> http://localhost:3030/personal.owl#hasAge> 98 .
>>> }
>>
>> Do you call model.write() to put back the changes into the file you
>> read it from?
>>
>> Andy
>>
>>>
>>>
>>>
>>> After applying the SELECT query the results come like this
>>> -----------------------------------------------------------
>>> | Age | hasAge |
>>> ===========================================================
>>> | owl:Age3 | 98 |
>>> | owl:Age2 | "40"^^<http://www.w3.org/2001/XMLSchema#int> |
>>> | owl:Age1 | "20"^^<http://www.w3.org/2001/XMLSchema#int> |
>>> -----------------------------------------------------------
>>>
>>> With Regards
>>>
>>
>>
>
Re: Updating Tuples in the graph
Posted by don <do...@gmail.com>.
Dear Andy,
Really thankful to you for your reply. It is working fine
and I am able see the result in console
window when I gave the command "
model.write(System.out,"RDF/XML-ABBREV");. But I need to save the file
back to
the server. May I know the procedure for doing that.
Regards
Don
On 5/29/2012 12:58 AM, Andy Seaborne wrote:
> On 29/05/12 05:00, Don S wrote:
>> HI,
>>
>> I am developing a semantic application. As a first step to understand
>> the
>> concept I made a simple ontology using protege and used Jena for
>> query the
>> data under eclipse platforms. Its working fine. But when I tried to
>> update
>> the triples in the graph it is not updating the graph rather it is
>> adding
>> in memory. I will thankful if some one can give an idea or related
>> articles
>> for updating the graph.
>>
>> The update query is
>>
>> Model model =ModelFactory.createOntologyModel();
>
> This is an in-memory model.
>
> Do you then call model.read() or otherwise load data? That wil be
> in-memory.
>
>> ~~~~Some lines of code
>>
>> String queryString ="PREFIX
>> owl:<http://localhost:3030/personal.owl#>\r\n"
>> +
>> "INSERT DATA" +
>> "{" +
>> "<http://localhost:3030/personal.owl#Age3>\n" +
>> "owl:hasAge 98." +
>> "}";
>> GraphStore gs=GraphStoreFactory.create();
> > gs.setDefaultGraph(model.getGraph());
>
> Simpler?
>
> GraphStore gs=GraphStoreFactory.create(model);
>
>> UpdateRequest ur = UpdateFactory.create(queryString);
>> Update update = ur.getOperations().get(0);
>> UpdateAction.execute(ur,gs);
>> System.out.println(update);
>>
>> Print result for "update" variable
>> INSERT DATA {
>> <http://localhost:3030/personal.owl#Age3> <
>> http://localhost:3030/personal.owl#hasAge> 98 .
>> }
>
> Do you call model.write() to put back the changes into the file you
> read it from?
>
> Andy
>
>>
>>
>>
>> After applying the SELECT query the results come like this
>> -----------------------------------------------------------
>> | Age | hasAge |
>> ===========================================================
>> | owl:Age3 | 98 |
>> | owl:Age2 | "40"^^<http://www.w3.org/2001/XMLSchema#int> |
>> | owl:Age1 | "20"^^<http://www.w3.org/2001/XMLSchema#int> |
>> -----------------------------------------------------------
>>
>> With Regards
>>
>
>
Re: Updating Tuples in the graph
Posted by Andy Seaborne <an...@apache.org>.
On 29/05/12 05:00, Don S wrote:
> HI,
>
> I am developing a semantic application. As a first step to understand the
> concept I made a simple ontology using protege and used Jena for query the
> data under eclipse platforms. Its working fine. But when I tried to update
> the triples in the graph it is not updating the graph rather it is adding
> in memory. I will thankful if some one can give an idea or related articles
> for updating the graph.
>
> The update query is
>
> Model model =ModelFactory.createOntologyModel();
This is an in-memory model.
Do you then call model.read() or otherwise load data? That wil be
in-memory.
> ~~~~Some lines of code
>
> String queryString ="PREFIX owl:<http://localhost:3030/personal.owl#>\r\n"
> +
> "INSERT DATA" +
> "{" +
> "<http://localhost:3030/personal.owl#Age3>\n" +
> "owl:hasAge 98." +
> "}";
> GraphStore gs=GraphStoreFactory.create();
> gs.setDefaultGraph(model.getGraph());
Simpler?
GraphStore gs=GraphStoreFactory.create(model);
> UpdateRequest ur = UpdateFactory.create(queryString);
> Update update = ur.getOperations().get(0);
> UpdateAction.execute(ur,gs);
> System.out.println(update);
>
> Print result for "update" variable
> INSERT DATA {
> <http://localhost:3030/personal.owl#Age3> <
> http://localhost:3030/personal.owl#hasAge> 98 .
> }
Do you call model.write() to put back the changes into the file you read
it from?
Andy
>
>
>
> After applying the SELECT query the results come like this
> -----------------------------------------------------------
> | Age | hasAge |
> ===========================================================
> | owl:Age3 | 98 |
> | owl:Age2 | "40"^^<http://www.w3.org/2001/XMLSchema#int> |
> | owl:Age1 | "20"^^<http://www.w3.org/2001/XMLSchema#int> |
> -----------------------------------------------------------
>
> With Regards
>