RDF::Generator::HTTP(3pm) | User Contributed Perl Documentation | RDF::Generator::HTTP(3pm) |
RDF::Generator::HTTP - Generate RDF from a HTTP message
use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $response = $ua->get('http://search.cpan.org/'); use RDF::Generator::HTTP; use RDF::Trine qw(iri); my $g = RDF::Generator::HTTP->new(message => $response, graph => iri('http://example.org/graphname'), blacklist => ['Last-Modified', 'Accept']); my $model = $g->generate; print $model->size; my $s = RDF::Trine::Serializer->new('turtle', namespaces => { httph => 'http://www.w3.org/2007/ont/httph#', http => 'http://www.w3.org/2007/ont/http#' } ); $s->serialize_model_to_file(\*STDOUT, $model);
This module simply takes a HTTP::Message object, and based on its content, especially the content the HTTP::Header object(s) it contains, creates a simple RDF representation of the contents. It is useful chiefly for recording data when crawling resources on the Web, but it may also have other uses.
These attributes may be passed to the constructor to set them, or called like methods to get them.
The above attributes all have read-accessors by the same name. "blacklist", "whitelist" and "graph" also has writers and predicates, which is used to test if the attribute has been set, by prefixing "has_" to the attribute name.
This class has two methods:
For an example of what the module can be used to create, consider the example in the "SYNOPSIS", which at the time of this writing outputs the following Turtle:
@prefix http: <http://www.w3.org/2007/ont/http#> . @prefix httph: <http://www.w3.org/2007/ont/httph#> . [] a http:RequestMessage ; http:hasResponse [ a http:ResponseMessage ; http:status "200" ; httph:client_date "Sun, 14 Dec 2014 21:28:21 GMT" ; httph:client_peer "207.171.7.59:80" ; httph:client_response_num "1" ; httph:connection "close" ; httph:content_length "3643" ; httph:content_type "text/html" ; httph:date "Sun, 14 Dec 2014 21:28:21 GMT" ; httph:link "<http://search.cpan.org/uploads.rdf>; rel=\"alternate\"; title=\"RSS 1.0\"; type=\"application/rss+xml\"", "<http://st.pimg.net/tucs/opensearch.xml>; rel=\"search\"; title=\"SearchCPAN\"; type=\"application/opensearchdescription+xml\"", "<http://st.pimg.net/tucs/print.css>; media=\"print\"; rel=\"stylesheet\"; type=\"text/css\"", "<http://st.pimg.net/tucs/style.css?3>; rel=\"stylesheet\"; type=\"text/css\"" ; httph:server "Plack/Starman (Perl)" ; httph:title "The CPAN Search Site - search.cpan.org" ; httph:x_proxy "proxy2" ] ; http:method "GET" ; http:requestURI <http://search.cpan.org/> ; httph:user_agent "libwww-perl/6.05" .
There have been many efforts to create HTTP vocabularies (or ontologies), where the most elaborate and complete is the HTTP Vocabulary in RDF 1.0 <http://www.w3.org/TR/HTTP-in-RDF/>. Nevertheless, I decided not to support this, but rather support an older and much less complete vocabulary that has been in the Tabulator <https://github.com/linkeddata/tabulator-firefox> project, with the namespace prefixes <http://www.w3.org/2007/ont/http#> and <http://www.w3.org/2007/ont/httph#>. The problem of modelling HTTP is that headers modify each other, so if you want to record the HTTP headers so that they can be used in an actual HTTP dialogue afterwards, they have to be in a container so that the order can be reconstructed. Moreover, there is a lot of microstructure in the values, and that also adds complexity if you want to translate all that to RDF. That's what the former vocabulary does. However, for now, all the author wants to do is to record them, and then neither of these concerns are important. Therefore, I opted to go for a much simpler vocabulary, where each field is a simple predicate. That is not to say that the former approach isn't valid, it is just not something I need now.
This is a very early release, but it works for the author.
Please report any bugs to <https://github.com/kjetilk/p5-rdf-generator-http/issues>.
Kjetil Kjernsmo <kjetilk@cpan.org>.
This software is copyright (c) 2014 by Kjetil Kjernsmo.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2022-06-17 | perl v5.34.0 |