尝试使用 ARC2 从 HTML 字符串中提取 RDFa 时出错


Getting error when trying to extract RDFa from an HTML string using ARC2

我正在尝试使用 ARC2 从 HTML 字符串中提取 RDFa,但我遇到以下错误:

Undefined offset: 0 in /Applications/MAMP/htdocs/p-dpa/wp/addons/arc2/extractors/ARC2_PoshRdfExtractor.php on line 75

这是我使用的代码:

$aString = '
<span vocab="http://schema.org/" typeof="Document">
<a property="url" href="http://www.w3.org/TR/rdfa-primer/">
<span property="title">RDFa 1.1 Primer</span></a>.
</span>';
// Extracting RDFa from HTML
$config = array('auto_extract' => 0);
$parser = ARC2::getSemHTMLParser();
$parser->parse($aString);
$parser->extractRDF('rdfa');
$triples = $parser->getTriples();
$rdfxml = $parser->toRDFXML($triples);
print_r($rdfxml);

知道我做错了什么吗?

好的,看起来我使用了错误的解析方式。

$aString = '
<span vocab="http://schema.org/" typeof="Document">
<a property="url" href="http://www.w3.org/TR/rdfa-primer/">
<span property="title">RDFa 1.1 Primer</span></a>.
</span>';
// Extracting RDFa from HTML
$config = array('auto_extract' => 0);
$parser = ARC2::getSemHTMLParser();
$base = 'http://example.com';
$parser->parse($base, $aString);
$parser->extractRDF('rdfa');

$triples = $parser->getTriples();
$rdfxml = $parser->toRDFXML($triples);
print_r($rdfxml);

我不建议ARC2来解析RDFa,请使用EasyRDF 0.8(测试版)。即使EasyRdf仍处于测试阶段,它的RDFa解析器也比ARC2更可靠,并通过了超过95%的RDFa测试套件。

在 https://github.com/njh/easyrdf 查看主分支,并在 http://easyrdf-converter.aelius.com/试用