我使用 Jena API 创建了一个模型:
public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
Resource alice = ResourceFactory.createResource("http://example.org/alice");
Resource bob = ResourceFactory.createResource("http://example.org/bob");
Resource charlie = ResourceFactory.createResource("http://example.org/charlie");
model.add (alice, RDF.type, FOAF.Person);
model.add (alice, FOAF.name, "Alice");
model.add (alice, FOAF.mbox, ResourceFactory.createResource("mailto:alice@example.org"));
model.add (alice, FOAF.knows, bob);
model.add (alice, FOAF.knows, charlie);
model.write(System.out, "RDF/XML-ABBREV");
}
该程序的输出是:
<rdf:RDF xmlns:rdf="w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="xmlns.com/foaf/0.1/">
<j.0:Person rdf:about="example.org/alice">
<j.0:knows rdf:resource="example.org/charlie"/>
<j.0:knows rdf:resource="example.org/bob"/>
<j.0:mbox rdf:resource="mailto:alice@example.org"/>
<j.0:name>Alice</j.0:name>
</j.0:Person>
</rdf:RDF>
现在如何获取链接到某个资源的资源列表?
例如:Alice 认识 Bob 和 Charlie。Alice、Bob 和 Charlie 是资源,资源 Alice 知道其他两个资源。现在如何获得名字 [Bob, Charlie]?