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

StackOverflow https://stackoverflow.com/questions/19815901

  •  04-07-2022
  •  | 
  •  

문제

I'm trying to extract RDFa from an HTML string using ARC2, but I'm having the following error:

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

Here's the code I use:

$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);

Any idea of what am I doing wrong?

도움이 되었습니까?

해결책

Ok,looks like I was using the wrong way to parse.

$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);

다른 팁

I would not recommend ARC2 to parse RDFa, please use EasyRDF 0.8 (in beta) instead. Even if EasyRdf is still in beta, its RDFa parser is more reliable than ARC2 and passes more than 95% of the RDFa test suite.

Check out the master branch at https://github.com/njh/easyrdf and try it out at http://easyrdf-converter.aelius.com/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top