You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Tom Emerson <tr...@gmail.com> on 2013/09/06 16:49:35 UTC
vocab2jena - Create Jena Property and Resource constants from a vocabulary
Hello List,
I am working with SKOS in Jena and needed to create a utility class
containing the properties and resources defined in the vocabulary (just
like those in com.hp.hpl.jena.vocabulary). Instead of creating these
manually, I did the normal engineer thing and wrote a program to generate
them for me. It works for SKOS: I haven't tried it with other vocabularies.
The code is available if you want to try it out. Suggestions/improvements
are welcome.
https://github.com/TreeRex/vocab2jena
Peace,
-tree
--
Tom Emerson
tremerson@gmail.com
http://www.dreamersrealm.net/tree
Re: vocab2jena - Create Jena Property and Resource constants from a vocabulary
Posted by Tom Emerson <tr...@gmail.com>.
It would probably make more sense for me to go and tweak schemagen and
submit a patch than to continue with vocab2jena, which I wrote really for
the one purpose of generating the SKOS definitions and is undoubtedly
useless for anything else. But... the code is there for people to look at.
:-)
As far as the code generation goes, as simple as simple can be.
Thanks for the feedback Joshua, I appreciate it.
-tree
On Fri, Sep 6, 2013 at 12:39 PM, Joshua TAYLOR <jo...@gmail.com>wrote:
> On Fri, Sep 6, 2013 at 12:17 PM, Tom Emerson <tr...@gmail.com> wrote:
> > The output is very similar: you can see the output of vocab2jena here:
> > https://gist.github.com/TreeRex/6464149
> >
> > The main difference is that I use use the ResourceFactory methods
> instead of
> > creating the static Model. And I don't use the * wildcard on the imports.
> >
> > So... I guess it would have behoved me to look at schemagen before I
> spent a
> > couple of hours writing my utility: it would have saved me the bother. I
> saw
> > the name in the docs and didn't connect it to what I needed. I should
> have
> > figured you guys would have done this already. :-/
>
> Not "you guys", but "those guys"; I'm not a Jena developer. I've
> used a lot of schemagen with Jena though, and I'm always genuinely
> interested in code generation based on ontologies, so I was serious
> when I asked how the two compared.
>
> In my opinion, it's good that you used ResourceFactory, though.
> There's a StackOverflow question [1] about why some of the vocabulary
> classes use a model and some use a ResourceFactory. Ian Dickinson
> answered:
>
> "That both styles are used is just historical accident. I think these
> days, I'd probably suggest using theResourceFactory approach, simply
> because it avoids the (small) overhead of allocating a model, and the
> model gives you no real advantages. At some point, we'll probably go
> back and do some refactoring to just use a single approach in the Jena
> codebase."
>
> In the future, Jena's schemagen might produce results more like what
> your code produces.
>
> [1] http://stackoverflow.com/q/17701316/1281433
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>
--
Tom Emerson
tremerson@gmail.com
http://www.dreamersrealm.net/tree
Re: vocab2jena - Create Jena Property and Resource constants from a vocabulary
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Fri, Sep 6, 2013 at 12:17 PM, Tom Emerson <tr...@gmail.com> wrote:
> The output is very similar: you can see the output of vocab2jena here:
> https://gist.github.com/TreeRex/6464149
>
> The main difference is that I use use the ResourceFactory methods instead of
> creating the static Model. And I don't use the * wildcard on the imports.
>
> So... I guess it would have behoved me to look at schemagen before I spent a
> couple of hours writing my utility: it would have saved me the bother. I saw
> the name in the docs and didn't connect it to what I needed. I should have
> figured you guys would have done this already. :-/
Not "you guys", but "those guys"; I'm not a Jena developer. I've
used a lot of schemagen with Jena though, and I'm always genuinely
interested in code generation based on ontologies, so I was serious
when I asked how the two compared.
In my opinion, it's good that you used ResourceFactory, though.
There's a StackOverflow question [1] about why some of the vocabulary
classes use a model and some use a ResourceFactory. Ian Dickinson
answered:
"That both styles are used is just historical accident. I think these
days, I'd probably suggest using theResourceFactory approach, simply
because it avoids the (small) overhead of allocating a model, and the
model gives you no real advantages. At some point, we'll probably go
back and do some refactoring to just use a single approach in the Jena
codebase."
In the future, Jena's schemagen might produce results more like what
your code produces.
[1] http://stackoverflow.com/q/17701316/1281433
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: vocab2jena - Create Jena Property and Resource constants from a vocabulary
Posted by Tom Emerson <tr...@gmail.com>.
The output is very similar: you can see the output of vocab2jena here:
https://gist.github.com/TreeRex/6464149
The main difference is that I use use the ResourceFactory methods instead
of creating the static Model. And I don't use the * wildcard on the imports.
So... I guess it would have behoved me to look at schemagen before I spent
a couple of hours writing my utility: it would have saved me the bother. I
saw the name in the docs and didn't connect it to what I needed. I should
have figured you guys would have done this already. :-/
-tree
On Fri, Sep 6, 2013 at 11:49 AM, Joshua TAYLOR <jo...@gmail.com>wrote:
> On Fri, Sep 6, 2013 at 11:44 AM, Joshua TAYLOR <jo...@gmail.com>
> wrote:
> > On Fri, Sep 6, 2013 at 10:49 AM, Tom Emerson <tr...@gmail.com>
> wrote:
> >> I am working with SKOS in Jena and needed to create a utility class
> >> containing the properties and resources defined in the vocabulary (just
> >> like those in com.hp.hpl.jena.vocabulary). Instead of creating these
> >> manually, I did the normal engineer thing and wrote a program to
> generate
> >> them for me. It works for SKOS: I haven't tried it with other
> vocabularies.
> >>
> >> The code is available if you want to try it out.
> Suggestions/improvements
> >> are welcome.
> >>
> >> https://github.com/TreeRex/vocab2jena
> >
> > Code-generation is always interesting. Can you give a quick overview
> > of how it compares with Jena's schemagen [1]?
> >
> > [1] http://jena.apache.org/documentation/tools/schemagen.html
>
> For comparison purposes, here's what Jena's schemagen produces for SKOS:
>
> $ schemagen -i http://www.w3.org/TR/skos-reference/skos.rdf
>
> /* CVS $Id: $ */
>
> import com.hp.hpl.jena.rdf.model.*;
>
> /**
> * Vocabulary definitions from
> http://www.w3.org/TR/skos-reference/skos.rdf
> * @author Auto-generated by schemagen on 06 Sep 2013 11:47
> */
> public class Skos {
> /** <p>The RDF model that holds the vocabulary terms</p> */
> private static Model m_model = ModelFactory.createDefaultModel();
>
> /** <p>The namespace of the vocabulary as a string</p> */
> public static final String NS = "http://www.w3.org/2004/02/skos/core#
> ";
>
> /** <p>The namespace of the vocabulary as a string</p>
> * @see #NS */
> public static String getURI() {return NS;}
>
> /** <p>The namespace of the vocabulary as a resource</p> */
> public static final Resource NAMESPACE = m_model.createResource( NS );
>
> /** <p>The range of skos:altLabel is the class of RDF plain
> literals.skos:prefLabel,
> * skos:altLabel and skos:hiddenLabel are pairwise disjoint
> properties.</p>
> */
> public static final Property altLabel = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#altLabel" );
>
> public static final Property broadMatch = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#broadMatch" );
>
> /** <p>Broader concepts are typically rendered as parents in a
> concept hierarchy
> * (tree).</p>
> */
> public static final Property broader = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#broader" );
>
> public static final Property broaderTransitive =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#broaderTransitive" );
>
> public static final Property changeNote = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#changeNote" );
>
> public static final Property closeMatch = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#closeMatch" );
>
> public static final Property definition = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#definition" );
>
> public static final Property editorialNote =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#editorialNote" );
>
> /** <p>skos:exactMatch is disjoint with each of the properties
> skos:broadMatch and
> * skos:relatedMatch.</p>
> */
> public static final Property exactMatch = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#exactMatch" );
>
> public static final Property example = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#example" );
>
> public static final Property hasTopConcept =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#hasTopConcept" );
>
> /** <p>The range of skos:hiddenLabel is the class of RDF plain
> literals.skos:prefLabel,
> * skos:altLabel and skos:hiddenLabel are pairwise disjoint
> properties.</p>
> */
> public static final Property hiddenLabel = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#hiddenLabel" );
>
> public static final Property historyNote = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#historyNote" );
>
> public static final Property inScheme = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#inScheme" );
>
> /** <p>These concept mapping relations mirror semantic relations,
> and the data model
> * defined below is similar (with the exception of
> skos:exactMatch) to the data
> * model defined for semantic relations. A distinct vocabulary is
> provided for
> * concept mapping relations, to provide a convenient way to
> differentiate links
> * within a concept scheme from links between concept schemes.
> However, this
> * pattern of usage is not a formal requirement of the SKOS data
> model, and relies
> * on informal definitions of best practice.</p>
> */
> public static final Property mappingRelation =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#mappingRelation" );
>
> public static final Property member = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#member" );
>
> /** <p>For any resource, every item in the list given as the value
> of the skos:memberList
> * property is also a value of the skos:member property.</p>
> */
> public static final Property memberList = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#memberList" );
>
> public static final Property narrowMatch = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#narrowMatch" );
>
> /** <p>Narrower concepts are typically rendered as children in a
> concept hierarchy
> * (tree).</p>
> */
> public static final Property narrower = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#narrower" );
>
> public static final Property narrowerTransitive =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#narrowerTransitive" );
>
> public static final Property notation = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#notation" );
>
> public static final Property note = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#note" );
>
> /** <p>skos:prefLabel, skos:altLabel and skos:hiddenLabel are
> pairwise disjoint properties.A
> * resource has no more than one value of skos:prefLabel per
> language tag, and
> * no more than one value of skos:prefLabel without language
> tag.The range of
> * skos:prefLabel is the class of RDF plain literals.</p>
> */
> public static final Property prefLabel = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#prefLabel" );
>
> /** <p>skos:related is disjoint with skos:broaderTransitive</p> */
> public static final Property related = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#related" );
>
> public static final Property relatedMatch =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#relatedMatch" );
>
> public static final Property scopeNote = m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#scopeNote" );
>
> public static final Property semanticRelation =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#semanticRelation" );
>
> public static final Property topConceptOf =
> m_model.createProperty(
> "http://www.w3.org/2004/02/skos/core#topConceptOf" );
>
> public static final Resource Collection = m_model.createResource(
> "http://www.w3.org/2004/02/skos/core#Collection" );
>
> public static final Resource Concept = m_model.createResource(
> "http://www.w3.org/2004/02/skos/core#Concept" );
>
> public static final Resource ConceptScheme =
> m_model.createResource(
> "http://www.w3.org/2004/02/skos/core#ConceptScheme" );
>
> public static final Resource OrderedCollection =
> m_model.createResource(
> "http://www.w3.org/2004/02/skos/core#OrderedCollection" );
>
> }
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>
--
Tom Emerson
tremerson@gmail.com
http://www.dreamersrealm.net/tree
Re: vocab2jena - Create Jena Property and Resource constants from a vocabulary
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Fri, Sep 6, 2013 at 11:44 AM, Joshua TAYLOR <jo...@gmail.com> wrote:
> On Fri, Sep 6, 2013 at 10:49 AM, Tom Emerson <tr...@gmail.com> wrote:
>> I am working with SKOS in Jena and needed to create a utility class
>> containing the properties and resources defined in the vocabulary (just
>> like those in com.hp.hpl.jena.vocabulary). Instead of creating these
>> manually, I did the normal engineer thing and wrote a program to generate
>> them for me. It works for SKOS: I haven't tried it with other vocabularies.
>>
>> The code is available if you want to try it out. Suggestions/improvements
>> are welcome.
>>
>> https://github.com/TreeRex/vocab2jena
>
> Code-generation is always interesting. Can you give a quick overview
> of how it compares with Jena's schemagen [1]?
>
> [1] http://jena.apache.org/documentation/tools/schemagen.html
For comparison purposes, here's what Jena's schemagen produces for SKOS:
$ schemagen -i http://www.w3.org/TR/skos-reference/skos.rdf
/* CVS $Id: $ */
import com.hp.hpl.jena.rdf.model.*;
/**
* Vocabulary definitions from http://www.w3.org/TR/skos-reference/skos.rdf
* @author Auto-generated by schemagen on 06 Sep 2013 11:47
*/
public class Skos {
/** <p>The RDF model that holds the vocabulary terms</p> */
private static Model m_model = ModelFactory.createDefaultModel();
/** <p>The namespace of the vocabulary as a string</p> */
public static final String NS = "http://www.w3.org/2004/02/skos/core#";
/** <p>The namespace of the vocabulary as a string</p>
* @see #NS */
public static String getURI() {return NS;}
/** <p>The namespace of the vocabulary as a resource</p> */
public static final Resource NAMESPACE = m_model.createResource( NS );
/** <p>The range of skos:altLabel is the class of RDF plain
literals.skos:prefLabel,
* skos:altLabel and skos:hiddenLabel are pairwise disjoint properties.</p>
*/
public static final Property altLabel = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#altLabel" );
public static final Property broadMatch = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#broadMatch" );
/** <p>Broader concepts are typically rendered as parents in a
concept hierarchy
* (tree).</p>
*/
public static final Property broader = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#broader" );
public static final Property broaderTransitive =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#broaderTransitive" );
public static final Property changeNote = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#changeNote" );
public static final Property closeMatch = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#closeMatch" );
public static final Property definition = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#definition" );
public static final Property editorialNote =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#editorialNote" );
/** <p>skos:exactMatch is disjoint with each of the properties
skos:broadMatch and
* skos:relatedMatch.</p>
*/
public static final Property exactMatch = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#exactMatch" );
public static final Property example = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#example" );
public static final Property hasTopConcept =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#hasTopConcept" );
/** <p>The range of skos:hiddenLabel is the class of RDF plain
literals.skos:prefLabel,
* skos:altLabel and skos:hiddenLabel are pairwise disjoint properties.</p>
*/
public static final Property hiddenLabel = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#hiddenLabel" );
public static final Property historyNote = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#historyNote" );
public static final Property inScheme = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#inScheme" );
/** <p>These concept mapping relations mirror semantic relations,
and the data model
* defined below is similar (with the exception of
skos:exactMatch) to the data
* model defined for semantic relations. A distinct vocabulary is
provided for
* concept mapping relations, to provide a convenient way to
differentiate links
* within a concept scheme from links between concept schemes.
However, this
* pattern of usage is not a formal requirement of the SKOS data
model, and relies
* on informal definitions of best practice.</p>
*/
public static final Property mappingRelation =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#mappingRelation" );
public static final Property member = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#member" );
/** <p>For any resource, every item in the list given as the value
of the skos:memberList
* property is also a value of the skos:member property.</p>
*/
public static final Property memberList = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#memberList" );
public static final Property narrowMatch = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#narrowMatch" );
/** <p>Narrower concepts are typically rendered as children in a
concept hierarchy
* (tree).</p>
*/
public static final Property narrower = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#narrower" );
public static final Property narrowerTransitive =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#narrowerTransitive" );
public static final Property notation = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#notation" );
public static final Property note = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#note" );
/** <p>skos:prefLabel, skos:altLabel and skos:hiddenLabel are
pairwise disjoint properties.A
* resource has no more than one value of skos:prefLabel per
language tag, and
* no more than one value of skos:prefLabel without language
tag.The range of
* skos:prefLabel is the class of RDF plain literals.</p>
*/
public static final Property prefLabel = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#prefLabel" );
/** <p>skos:related is disjoint with skos:broaderTransitive</p> */
public static final Property related = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#related" );
public static final Property relatedMatch =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#relatedMatch" );
public static final Property scopeNote = m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#scopeNote" );
public static final Property semanticRelation =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#semanticRelation" );
public static final Property topConceptOf =
m_model.createProperty(
"http://www.w3.org/2004/02/skos/core#topConceptOf" );
public static final Resource Collection = m_model.createResource(
"http://www.w3.org/2004/02/skos/core#Collection" );
public static final Resource Concept = m_model.createResource(
"http://www.w3.org/2004/02/skos/core#Concept" );
public static final Resource ConceptScheme =
m_model.createResource(
"http://www.w3.org/2004/02/skos/core#ConceptScheme" );
public static final Resource OrderedCollection =
m_model.createResource(
"http://www.w3.org/2004/02/skos/core#OrderedCollection" );
}
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: vocab2jena - Create Jena Property and Resource constants from a vocabulary
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Fri, Sep 6, 2013 at 10:49 AM, Tom Emerson <tr...@gmail.com> wrote:
> I am working with SKOS in Jena and needed to create a utility class
> containing the properties and resources defined in the vocabulary (just
> like those in com.hp.hpl.jena.vocabulary). Instead of creating these
> manually, I did the normal engineer thing and wrote a program to generate
> them for me. It works for SKOS: I haven't tried it with other vocabularies.
>
> The code is available if you want to try it out. Suggestions/improvements
> are welcome.
>
> https://github.com/TreeRex/vocab2jena
Code-generation is always interesting. Can you give a quick overview
of how it compares with Jena's schemagen [1]?
[1] http://jena.apache.org/documentation/tools/schemagen.html
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/