【发布时间】:2012-09-23 01:15:26
【问题描述】:
我编写了以下代码,用于从内容类型为 application/rdf-xml 的网页中提取 URI,用于关联数据应用程序。
public static void test(String url) {
try {
Model read = ModelFactory.createDefaultModel().read(url);
System.out.println("to go");
StmtIterator si;
si = read.listStatements();
System.out.println("to go");
while(si.hasNext()) {
Statement s=si.nextStatement();
Resource r=s.getSubject();
Property p=s.getPredicate();
RDFNode o=s.getObject();
System.out.println(r.getURI());
System.out.println(p.getURI());
System.out.println(o.asResource().getURI());
}
}
catch(JenaException | NoSuchElementException c) {}
}
但是对于输入
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:ex="http://example.org/stuff/1.0/">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
dc:title="RDF/XML Syntax Specification (Revised)">
<ex:editor>
<rdf:Description ex:fullName="Dave Beckett">
<ex:homePage rdf:resource="http://purl.org/net/dajobe/" />
</rdf:Description>
</ex:editor>
</rdf:Description>
</rdf:RDF>
输出是:
Subject URI is http://www.w3.org/TR/rdf-syntax-grammar
Predicate URI is http://example.org/stuff/1.0/editor
Object URI is null
Subject URI is http://www.w3.org/TR/rdf-syntax-grammar
Predicate URI is http://purl.org/dc/elements/1.1/title
Website is read
我需要在输出中包含该页面上存在的所有 URI,以便为 RDF 页面构建网络爬虫。 我需要输出中的所有以下链接:
http://www.w3.org/TR/rdf-syntax-grammar
http://example.org/stuff/1.0/editor
http://purl.org/net/dajobe
http://example.org/stuff/1.0/fullName
http://www.w3.org/TR/rdf-syntax-grammar
http://purl.org/dc/elements/1.1/title
【问题讨论】:
-
把 XML 放到网上并给我们 URL
-
另外,您不应该手动遍历所有三元组。请参阅 this old answer 以简要介绍您应该在 Jena 中使用的查询语言,以从序列化模型中提取信息
-
删除这两个无用的 cmets,并编辑您的问题以提供所需的输出,因为我无法完全理解您的问题
-
好的。我已经完成了。并在问题本身中进行了编辑
-
更好,但我仍然不明白您要从 哪个页面 提取 URL。我希望您知道 RDF 中的 URL 不是用于定位,而是用于识别...
标签: java xml-parsing web-crawler rdf jena