jenaprefixn-triplesiri

N-triples IRI prefix jena


I want to use prefix to represent this nt file:

<www.test.com/a/yan-dang-shan> <www.test.com/a/zhongwenming> <www.test.com/a/yan-dang-shan> .
<www.test.com/a/yan-dang-shan> <http://www.w3.org/2000/01/rdf-schema#label> "a" .
<www.test.com/a/zhongwenming> <http://www.w3.org/2000/01/rdf-schema#label> "b" .
<www.test.com/a/yan-dang-shan> <http://www.w3.org/2000/01/rdf-schema#label> "c" .

What I write into a new nt file is:

@prefix sp: <www.test.com/a/> .
<sp:yan-dang-shan> <sp:zhongwenming> <sp:yan-dang-shan> .
<sp:yan-dang-shan> <http://www.w3.org/2000/01/rdf-schema#label> "a" .
<sp:zhongwenming> <http://www.w3.org/2000/01/rdf-schema#label> "b" .
<sp:yan-dang-shan> <http://www.w3.org/2000/01/rdf-schema#label> "c" .

But when I use this to sparql in cmd:

SELECT ?x ?y ?z
WHERE
{ ?x ?y ?z . }  

There is an error showed in cmd:

D:\>sparql --data=ceshi.nt --query=ceshi.rq
11:01:42 ERROR riot                 :: [line: 1, col: 1 ] Expected BNode or IRI:
 Got: [DIRECTIVE:prefix]
Failed to load data

I also tried this:

@prefix sp: <www.test.com/a/> .
sp:yan-dang-shan sp:zhongwenming sp:yan-dang-shan .
sp:yan-dang-shan <http://www.w3.org/2000/01/rdf-schema#label> "a" .
sp:zhongwenming <http://www.w3.org/2000/01/rdf-schema#label> "b" .
sp:yan-dang-shan <http://www.w3.org/2000/01/rdf-schema#label> "c" .

But it report the same error which I don't know how to fix it.

How should I revise to make it ok?

Any help will be appreciated. Thanks!


Solution

  • N-triples does not have prefixes.

    Turtle has prefixes. Try putting your data in a file with extension ".ttl".

    You can test your data with the command line tool riot.