summaryrefslogtreecommitdiff
path: root/foaf/any2rdf.pl
blob: 9474aa60898c690410877f85b547c9b633999959 (plain)
  1. #!/usr/bin/perl -w
  2. use RDF::Trine;
  3. use HTML::Data::Parser;
  4. use RDF::TrineShortcuts;
  5. use File::Slurp;
  6. my $markup = read_file( $ARGV[0] );
  7. my $base_uri = $ARGV[1];
  8. # hint: locate common abbreviations at http://prefix.cc/
  9. #
  10. my $NAMESPACES= {
  11. rdfs => 'http://www.w3.org/2000/01/rdf-schema#',
  12. dc => 'http://purl.org/dc/terms/',
  13. foaf => 'http://xmlns.com/foaf/0.1/',
  14. xhtml => 'http://www.w3.org/1999/xhtml/vocab#',
  15. vcard => 'http://www.w3.org/2006/vcard/ns#',
  16. vcardx => 'http://buzzword.org.uk/rdf/vcardx#',
  17. hcterms => 'http://purl.org/uF/hCard/terms/',
  18. ical => 'http://www.w3.org/2002/12/cal/icaltzd#',
  19. cv => 'http://purl.org/captsolo/resume-rdf/0.2/cv#',
  20. hresume => 'http://ontologi.es/hresume#',
  21. };
  22. my $parser = HTML::Data::Parser->new;
  23. my $model = RDF::Trine::Model->temporary_model;
  24. my $writer = RDF::Trine::Serializer->new('RDFXML');
  25. $parser->parse_into_model($base_uri, $markup, $model);
  26. my $output = rdf_string($model,'RDFXML',
  27. namespaces => { %$NAMESPACES },
  28. );
  29. # TODO: somehow make RDF::Trine generate stable IDs
  30. $output =~ s/(?<=rdf:nodeID="B)[a-f0-9]{32}(?=0[0-9]{3}")//g;
  31. print $output;