5

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?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user14750
  • 157
  • 4

2 Answers2

6

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.

Antoine Zimmermann
  • 5,314
  • 18
  • 36
3

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.

cygri
  • 9,412
  • 1
  • 25
  • 47
  • Many thanks for these answers. I like the prefix suggestion. Do I need to explicitly state ":Alice a x: ." if Alice is involved is some relations? More precisely, let say I have "x:Alice :hasSibling x:Bob". Does this imply that Alice and Bob are x? – user14750 Aug 29 '12 at 16:19
  • A comment about why I am asking that question. I really like the work around the semantic web and believe it has a huge potential but fails to deliver the simplicity that would enable large audience acceptance (maybe the way HTML got widely adopted in its time). So, I am investigating the notation shortcuts available. Now, obviously 20K instances are hard to describe in an "simple" manner. But my ontology is hopefully going to be read and used by many people and I want to write it in the most human readable manner. – user14750 Aug 29 '12 at 16:29
  • 1
    The short answer to your questions is: Yes you need to type things explicitly (unless you assume that every user of the data has a toolkit that supports inference, which typically isn't the case). And no, “`x:Alice :hasSibling x:Bob`” does not imply that Alice and Bob are `x:`. – cygri Aug 30 '12 at 06:35
  • Also, if you like an answer then you can show that by upvoting and/or accepting it. – cygri Aug 30 '12 at 06:37