Question

Here is how I know to create a class in N3:

:Person a rdfs:Class.

And here is how to specify that a specific ressource is an instance of that class:

:Pat a :Person.

Problem: I want to create a class with more than 20000 instances (programmatically generated). Writing the whole :Pat a :Person. for my 20000 instances makes the ontology file verbose.

Question: is there a work around to make the file smaller?

Was it helpful?

Solution

You can define a custom prefix for the full class URI, and then just use the prefix to refer to the class:

@prefix : <http://example.com/myOntology#>.
@prefix x: <http://example.com/myOntology#MyClass>.

:Alice a x: .
:Bob a x: .
:Charlie a x: .

That's not exactly readable, but as short as it's going to get.

I agree with Antoine that there's little point in this kind of trickery. Disk space is cheap, and this stuff compresses well for network transfer, and for processing in an application it will be expanded anyways.

OTHER TIPS

If you are really using N3 and not Turtle (which I doubt), you can use the @is ... @of keywords, like this:

:Person  a  rdfs:Class;
    @is a @of  :Pat, :Bob, :Chris, :Cindy, :Suzy .

There are hardly any Turtle toolkit that allow this.

There was also a long discussion thread on the public-rdf-comments@w3.org Mail Archives about adding this functionality to Turtle (which is currently published by the W3C as a Last Call Working Draft), starting with a comment by Tim Berners-Lee. Then went a comment by Dave Beckett asking for not including the feature, and a long thread again. Then went a good summary of the positions with a comment by Gavin Carothers, editor of the Turtle spec in the current RDF Working Group.

However, I doubt this will become a feature of Turtle when it's eventually standardised.

BTW, what's the problem of having 20,000 records when it's all generated (and I guess, parsed) programmatically? If you need to exchange so much data over the network, you can easily compress it a lot. Or, you could use a compact serialisation syntax like HDT, but there are few implementations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top