punkish has asked for the wisdom of the Perl Monks concerning the following question:
my $uri = ''; my $xhtml = '<a rel="license" href="http://creativecommons.org/license +s/by/3.0/us/"><img alt="Creative Commons License" style="border-width +:0" src="http://i.creativecommons.org/l/by/3.0/us/88x31.png" /></a><b +r /><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://pu +rl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">My licenso +r</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="www.ex +ample.com/My-Licensor" property="cc:attributionName" rel="cc:attribut +ionURL">Puneet Kishor</a> is licensed under a <a rel="license" href=" +http://creativecommons.org/licenses/by/3.0/us/">Creative Commons Attr +ibution 3.0 United States License</a>.<br />Based on a work at <a xml +ns:dc="http://purl.org/dc/elements/1.1/" href="www.example.com/Source +-Work" rel="dc:source">www.example/Source-Work</a>.<br />Permissions +beyond the scope of this license may be available at <a xmlns:cc="htt +p://creativecommons.org/ns#" href="www.example/More-Permissions" rel= +"cc:morePermissions">www.example.com/More-Permissions</a>.'; my $parser = RDF::RDFa::Parser->new($xhtml, $uri); $parser->consume; print Dumper $parser;
Needless to say, the above code croaks because the xhtml doesn't have a root node. So, I wrap it in a node like so <lic>$xhtml</lic> and now the code doesn't croak, but I really get nothing. Here is my result from a dumper
$VAR1 = bless( { 'named_graphs' => 0, 'bnodes' => 0, 'DOM' => bless( do{\(my $o = 4444944)}, 'XML::LibXML: +:Document' ), 'baseuri' => '', 'tdb' => 0, 'RDF' => {}, 'xhtml' => '<lic>blah blah blah...</lic>', 'Graphs' => {} }, 'RDF::RDFa::Parser' );
Truth be told, I am not sure what I should expect. I was expecting the RDF key and/or the Graph key to be populated with RDF triples. If I put my $xhtml fragment (without my fake root node) into the license validator at http://validator.creativecommons.org/, it parses it just fine and gives back a result that makes sense, so, I guess that is what I am after.
Any suggestions anyone?
Note: There seems to be a dearth of Perl code for this. On CC site, we have Python, PHP and Ruby, but no Perl. http://buzzword.org.uk/swignition/ is a new project by the creator of RDFa. Perhaps, I should try that at some point, but step by step here.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing CC licenses
by Your Mother (Archbishop) on Apr 12, 2009 at 17:46 UTC | |
by tobyink (Canon) on Apr 12, 2009 at 21:57 UTC | |
by punkish (Priest) on Apr 12, 2009 at 23:21 UTC | |
by punkish (Priest) on Apr 12, 2009 at 18:34 UTC |