You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Riccardo Tammaro <ri...@gmail.com> on 2012/05/29 15:25:50 UTC
"My code doesn't work" :-(
Hi all. I'm trying to create a OWL file through a java application.
The file must be like this:
<mns:TematicContext rdf:ID="_5">
<mns:contextName>My name</contextName>
<mns:contextDescription>My desciption</contextDescription>
<mns:geom>
<gml:Point>
<gml:coordinates>100,200</gml:coordinates>
</gml:Point>
</mns:geom>
</mns:TematicContext>
where TematicContext is my resource, contextName, contextDescription,
ect.. are property and My name, MyDescription, ect... are value. I
don't know if Jena can create nested properties, in this example:
<mns:geom>
<gml:Point>
<gml:coordinates>100,200</gml:coordinates>
</gml:Point>
</mns:geom>
This is the implemented code:
Resource contesto =
ResourceFactory.createResource(nso+"TematicContext");
Resource res = modelForContext.createResource(BASE+"_"+Integer.toString(cs.getIdContesto())),
contesto);
res.addProperty(modelForContext.createProperty(nso+"contextDescription"),cs.getDescrizioneContesto());
res.addProperty(modelForContext.createProperty(nso+"contextName"),cs.getNomeContesto());
res.addProperty(modelForContext.createProperty(nso+"geom"),
............................................................................and
now?
Can anyone help me?
Thanks to all,
Riccardo.
Re: "My code doesn't work" :-(
Posted by Ian Dickinson <ia...@epimorphics.com>.
Hi Riccardo,
On 29/05/12 14:25, Riccardo Tammaro wrote:
> <mns:TematicContext rdf:ID="_5">
> <mns:contextName>My name</contextName>
> <mns:contextDescription>My desciption</contextDescription>
> <mns:geom>
> <gml:Point>
> <gml:coordinates>100,200</gml:coordinates>
> </gml:Point>
> </mns:geom>
> </mns:TematicContext>
>
>
> where TematicContext is my resource, contextName, contextDescription,
> ect.. are property and My name, MyDescription, ect... are value. I
> don't know if Jena can create nested properties, in this example:
>
> <mns:geom>
> <gml:Point>
> <gml:coordinates>100,200</gml:coordinates>
> </gml:Point>
> </mns:geom>
>
>
> This is the implemented code:
> Resource contesto =
> ResourceFactory.createResource(nso+"TematicContext");
> Resource res = modelForContext.createResource(BASE+"_"+Integer.toString(cs.getIdContesto())),
> contesto);
> res.addProperty(modelForContext.createProperty(nso+"contextDescription"),cs.getDescrizioneContesto());
> res.addProperty(modelForContext.createProperty(nso+"contextName"),cs.getNomeContesto());
> res.addProperty(modelForContext.createProperty(nso+"geom"),
Please don't send fragmentary examples like this. It makes us have to
guess the missing pieces, like namespaces and the value of the 'cs'
variable, when trying to frame an answer. In the code below, I had to
guess a bunch of stuff, and I left some of your objects out.
Basically, in your fragment, you have a blank node (bNode) of type
geom:Point connected to the parent resource by a mns:geom property. So,
that's what you create. I've attached an example; the output I get when
I run the *non-fragementary example* (get the point? :) is:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:mns="http://fake.domain/mns#"
xmlns:gml="http://fake.domain/gml#">
<rdf:Description rdf:about="http://fake.domain/">
<mns:geom>
<gml:Point>
<gml:coordinates>100,200</gml:coordinates>
</gml:Point>
</mns:geom>
<mns:contextName>my name</mns:contextName>
<mns:contextDescription>my description</mns:contextDescription>
</rdf:Description>
</rdf:RDF>
Ian
--
____________________________________________________________
Ian Dickinson Epimorphics Ltd, Bristol, UK
mailto:ian@epimorphics.com http://www.epimorphics.com
cell: +44-7786-850536 landline: +44-1275-399069
------------------------------------------------------------
Epimorphics Ltd. is a limited company registered in England
(no. 7016688). Registered address: Court Lodge, 105 High St,
Portishead, Bristol BS20 6PT, UK
Re: "My code doesn't work" :-(
Posted by Chris Dollin <ch...@epimorphics.com>.
On Tuesday, May 29, 2012 03:25:50 PM Riccardo Tammaro wrote:
> Hi all. I'm trying to create a OWL file through a java application.
> The file must be like this:
>
> <mns:TematicContext rdf:ID="_5">
> <mns:contextName>My name</contextName>
> <mns:contextDescription>My desciption</contextDescription>
> <mns:geom>
> <gml:Point>
> <gml:coordinates>100,200</gml:coordinates>
> </gml:Point>
> </mns:geom>
> </mns:TematicContext>
Jena will write correct RDF/XML files and gives you some control over
layout. You cannot, however, control RDF-irrelevant details like the
order the properties come out in or the values of RDF:IDs.
> where TematicContext is my resource, contextName, contextDescription,
> ect.. are property and My name, MyDescription, ect... are value. I
> don't know if Jena can create nested properties, in this example:
Yes, it can.
> <mns:geom>
> <gml:Point>
> <gml:coordinates>100,200</gml:coordinates>
> </gml:Point>
> </mns:geom>
This means (he said, having used jena.rdfcat to turn the XML, after patching
it, into Turtle) that mns:TematicContext has a property mns:geom whose
value is an anonymous instance of Point which has the specified string
as its gml:coordinates value.
In Jena's RDF world, that "anonymous instance of Point" is a blank node
with property rdf:type having the value gml:Point (with prefix expanded).
You create a blank node using model.createResource() and then treat it
like any other Resource.
> This is the implemented code:
> Resource contesto =
> ResourceFactory.createResource(nso+"TematicContext");
> Resource res = modelForContext.createResource(BASE+"_"+Integer.toString(cs.getIdContesto())),
> contesto);
> res.addProperty(modelForContext.createProperty(nso+"contextDescription"),cs.getDescrizioneContesto());
> res.addProperty(modelForContext.createProperty(nso+"contextName"),cs.getNomeContesto());
> res.addProperty(modelForContext.createProperty(nso+"geom"),
> ............................................................................and
> now?
You'd be better of making contextDescription, contextName, etc, constant
Property variables (for which you may find ResourceFactory useful).
Chris
--
"It is seldom good news." ~Crystal Ball~, /The Tough Guide to Fantasyland/
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)