下载了sesame 3alpha1,先写个小程序体验一下RDF的几种格式
输出如下:
static String NS = "http://www.steeven.org/rdf#";
public static void main(String[] args) throws RDFHandlerException {
for (RDFFormat format : RDFFormat.values())
writeRDF(format);
}
private static void writeRDF(RDFFormat format) throws RDFHandlerException {
System.out.println("=======format: "+format+"========");
RDFWriter w = Rio.createWriter(format, System.out);
w.handleNamespace("myns", NS);
w.handleNamespace("w3", RDFS.NAMESPACE);
w.startRDF();
w.handleComment("my first rdf file");
BNode res = MemValueFactory.getInstance().createBNode(
"steeven@gmail.com");
w.handleStatement(MemValueFactory.getInstance().createStatement(res,
RDFS.LABEL,
MemValueFactory.getInstance().createLiteral("steeven")));
w.handleStatement(MemValueFactory.getInstance().createStatement(res,
MemValueFactory.getInstance().createURI(NS, "desc"),
MemValueFactory.getInstance().createLiteral("good blogger")));
w.endRDF();
System.out.println("\n");
}
输出如下:
=======format: RDF/XML (mimeTypes=application/rdf+xml, application/xml; ext=rdf, rdfs, owl, xml)========
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:myns="http://www.steeven.org/rdf#"
xmlns:w3="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!-- my first rdf file -->
<rdf:Description rdf:nodeID="steeven@gmail.com">
<w3:label>steeven</w3:label>
<myns:desc>good blogger</myns:desc>
</rdf:Description>
</rdf:RDF>
=======format: N-Triples (mimeTypes=text/plain; ext=nt)========
# my first rdf file
_:steeven@gmail.com <http://www.w3.org/2000/01/rdf-schema#label> "steeven" .
_:steeven@gmail.com <http://www.steeven.org/rdf#desc> "good blogger" .
=======format: Turtle (mimeTypes=application/x-turtle; ext=ttl)========
@prefix myns: <http://www.steeven.org/rdf#> .
@prefix w3: <http://www.w3.org/2000/01/rdf-schema#> .
# my first rdf file
_:steeven@gmail.com w3:label "steeven" ;
myns:desc "good blogger" .
=======format: N3 (mimeTypes=text/rdf+n3; ext=n3)========
@prefix myns: <http://www.steeven.org/rdf#> .
@prefix w3: <http://www.w3.org/2000/01/rdf-schema#> .
# my first rdf file
_:steeven@gmail.com w3:label "steeven" ;
myns:desc "good blogger" .
=======format: TriX (mimeTypes=application/trix; ext=xml, trix)========
<?xml version='1.0' encoding='UTF-8'?>
<TriX xmlns='http://www.w3.org/2004/03/trix/trix-1/'>
<!-- my first rdf file -->
<graph>
<triple>
<id>steeven@gmail.com</id>
<uri>http://www.w3.org/2000/01/rdf-schema#label</uri>
<plainLiteral>steeven</plainLiteral>
</triple>
<triple>
<id>steeven@gmail.com</id>
<uri>http://www.steeven.org/rdf#desc</uri>
<plainLiteral>good blogger</plainLiteral>
</triple>
</graph>
</TriX>
=======format: TriG (mimeTypes=application/x-trig; ext=trig)========
@prefix myns: <http://www.steeven.org/rdf#> .
@prefix w3: <http://www.w3.org/2000/01/rdf-schema#> .
# my first rdf file
{
_:steeven@gmail.com w3:label "steeven" ;
myns:desc "good blogger" .
}
=======format: RDFa (mimeTypes=application/xhtml+xml; ext=xhtml)========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:myns="http://www.steeven.org/rdf#"
xmlns:w3="http://www.w3.org/2000/01/rdf-schema#">
<head>
<!-- my first rdf file -->
</head>
<body>
<div about="[_:steeven@gmail.com]">
<span property="w3:label">steeven</span>
<span property="myns:desc">good blogger</span>
</div>
</body>
</html>