Skip to content

Instantly share code, notes, and snippets.

@danbri
Created June 7, 2011 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbri/1012713 to your computer and use it in GitHub Desktop.
Save danbri/1012713 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use RDF::Trine;
use RDF::Query;
use HTML::HTML5::Microdata::Parser;
my $html;
my $baseURI='http://schema.org/';
open(IN, "full_md.html") || die "no file"; # beware, the html is escaped; save the markup first.
while(<IN>) { $html .= $_ ; }
my $parser = HTML::HTML5::Microdata::Parser->new($html, $baseURI);
my $model = $parser->graph; # RDF::Trine::Model
my $sparql = <<EOQ;
PREFIX so: <http://schema.org/>
PREFIX soo: <http://www.w3.org/1999/xhtml/microdata#http%3A%2F%2Fschema.org%2FType%23%3A>
SELECT ?t ?st where {
?t a so:Type .
OPTIONAL { ?t soo:subClassOf ?st }
}
EOQ
my $query = RDF::Query->new( $sparql );
my $iterator = $query->execute( $model );
while (my $row = $iterator->next) {
print $row->{ 't' }->as_string , "\t";
if ($row->{'st'}) {
print $row->{ 'st' }->as_string;
}
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment