| 1 |
NAME |
| 2 |
RDF::Generator::HTTP - Generate RDF from a HTTP message |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use LWP::UserAgent; |
| 6 |
my $ua = LWP::UserAgent->new; |
| 7 |
my $response = $ua->get('http://search.cpan.org/'); |
| 8 |
|
| 9 |
use RDF::Generator::HTTP; |
| 10 |
use RDF::Trine qw(iri); |
| 11 |
my $g = RDF::Generator::HTTP->new(message => $response, |
| 12 |
graph => iri('http://example.org/graphname'), |
| 13 |
blacklist => ['Last-Modified', 'Accept']); |
| 14 |
my $model = $g->generate; |
| 15 |
print $model->size; |
| 16 |
my $s = RDF::Trine::Serializer->new('turtle', namespaces => |
| 17 |
{ httph => 'http://www.w3.org/2007/ont/httph#', |
| 18 |
http => 'http://www.w3.org/2007/ont/http#' } ); |
| 19 |
$s->serialize_model_to_file(\*STDOUT, $model); |
| 20 |
|
| 21 |
DESCRIPTION |
| 22 |
This module simply takes a HTTP::Message object, and based on its content, |
| 23 |
especially the content the HTTP::Header object(s) it contains, creates a |
| 24 |
simple RDF representation of the contents. It is useful chiefly for |
| 25 |
recording data when crawling resources on the Web, but it may also have |
| 26 |
other uses. |
| 27 |
|
| 28 |
Constructor |
| 29 |
`new(%attributes)` |
| 30 |
Moose-style constructor function. |
| 31 |
|
| 32 |
Attributes |
| 33 |
These attributes may be passed to the constructor to set them, or called |
| 34 |
like methods to get them. |
| 35 |
|
| 36 |
`message` |
| 37 |
A HTTP::Message (or subclass thereof) object to generate RDF for. |
| 38 |
Required. |
| 39 |
|
| 40 |
`blacklist` |
| 41 |
An `ArrayRef` of header field names that you do not want to see in the |
| 42 |
output. |
| 43 |
|
| 44 |
`whitelist` |
| 45 |
An `ArrayRef` of the only header field names that you want to see in |
| 46 |
the output. The whitelist will be ignored if the blacklist is set. |
| 47 |
|
| 48 |
`graph` |
| 49 |
You may pass an optional graph name to be used for all triples in the |
| 50 |
output. This must be an object of RDF::Trine::Node::Resource. |
| 51 |
|
| 52 |
`ns` |
| 53 |
An URI::NamespaceMap object containing namespace prefixes used in the |
| 54 |
module. You should probably not override this even though you can. |
| 55 |
|
| 56 |
`request_subject` |
| 57 |
An RDF::Trine::Node object containing the subject of any statements |
| 58 |
describing requests. If unset, it will default to a blank node. |
| 59 |
|
| 60 |
`response_subject` |
| 61 |
An RDF::Trine::Node object containing the subject of any statements |
| 62 |
describing responses. If unset, it will default to a blank node. |
| 63 |
|
| 64 |
Methods |
| 65 |
The above attributes all have read-accessors by the same name. |
| 66 |
`blacklist`, `whitelist` and `graph` also has writers and predicates, |
| 67 |
which is used to test if the attribute has been set, by prefixing `has_` |
| 68 |
to the attribute name. |
| 69 |
|
| 70 |
This class has two methods: |
| 71 |
|
| 72 |
`generate ( [ $model ] )` |
| 73 |
This method will generate the RDF. It may optionally take an |
| 74 |
RDF::Trine::Model as parameter. If it exists, the RDF will be added to |
| 75 |
this model, if not, a new Memory model will be created and returned. |
| 76 |
|
| 77 |
`ok_to_add ( $field )` |
| 78 |
This method will look up in the blacklists and whitelists and return |
| 79 |
true if the given field and value may be added to the model. |
| 80 |
|
| 81 |
EXAMPLES |
| 82 |
For an example of what the module can be used to create, consider the |
| 83 |
example in the "SYNOPSIS", which at the time of this writing outputs the |
| 84 |
following Turtle: |
| 85 |
|
| 86 |
@prefix http: <http://www.w3.org/2007/ont/http#> . |
| 87 |
@prefix httph: <http://www.w3.org/2007/ont/httph#> . |
| 88 |
|
| 89 |
[] a http:RequestMessage ; |
| 90 |
http:hasResponse [ |
| 91 |
a http:ResponseMessage ; |
| 92 |
http:status "200" ; |
| 93 |
httph:client_date "Sun, 14 Dec 2014 21:28:21 GMT" ; |
| 94 |
httph:client_peer "207.171.7.59:80" ; |
| 95 |
httph:client_response_num "1" ; |
| 96 |
httph:connection "close" ; |
| 97 |
httph:content_length "3643" ; |
| 98 |
httph:content_type "text/html" ; |
| 99 |
httph:date "Sun, 14 Dec 2014 21:28:21 GMT" ; |
| 100 |
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\"" ; |
| 101 |
httph:server "Plack/Starman (Perl)" ; |
| 102 |
httph:title "The CPAN Search Site - search.cpan.org" ; |
| 103 |
httph:x_proxy "proxy2" |
| 104 |
] ; |
| 105 |
http:method "GET" ; |
| 106 |
http:requestURI <http://search.cpan.org/> ; |
| 107 |
httph:user_agent "libwww-perl/6.05" . |
| 108 |
|
| 109 |
NOTES |
| 110 |
HTTP Vocabularies |
| 111 |
There have been many efforts to create HTTP vocabularies (or ontologies), |
| 112 |
where the most elaborate and complete is the HTTP Vocabulary in RDF 1.0 |
| 113 |
<http://www.w3.org/TR/HTTP-in-RDF/>. Nevertheless, I decided not to |
| 114 |
support this, but rather support an older and much less complete |
| 115 |
vocabulary that has been in the Tabulator |
| 116 |
<https://github.com/linkeddata/tabulator-firefox> project, with the |
| 117 |
namespace prefixes <http://www.w3.org/2007/ont/http#> and |
| 118 |
<http://www.w3.org/2007/ont/httph#>. The problem of modelling HTTP is that |
| 119 |
headers modify each other, so if you want to record the HTTP headers so |
| 120 |
that they can be used in an actual HTTP dialogue afterwards, they have to |
| 121 |
be in a container so that the order can be reconstructed. Moreover, there |
| 122 |
is a lot of microstructure in the values, and that also adds complexity if |
| 123 |
you want to translate all that to RDF. That's what the former vocabulary |
| 124 |
does. However, for now, all the author wants to do is to record them, and |
| 125 |
then neither of these concerns are important. Therefore, I opted to go for |
| 126 |
a much simpler vocabulary, where each field is a simple predicate. That is |
| 127 |
not to say that the former approach isn't valid, it is just not something |
| 128 |
I need now. |
| 129 |
|
| 130 |
BUGS |
| 131 |
This is a very early release, but it works for the author. |
| 132 |
|
| 133 |
Please report any bugs to |
| 134 |
<https://github.com/kjetilk/p5-rdf-generator-http/issues>. |
| 135 |
|
| 136 |
AUTHOR |
| 137 |
Kjetil Kjernsmo <[email protected]>. |
| 138 |
|
| 139 |
COPYRIGHT AND LICENCE |
| 140 |
This software is copyright (c) 2014 by Kjetil Kjernsmo. |
| 141 |
|
| 142 |
This is free software; you can redistribute it and/or modify it under the |
| 143 |
same terms as the Perl 5 programming language system itself. |
| 144 |
|
| 145 |
DISCLAIMER OF WARRANTIES |
| 146 |
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
| 147 |
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 148 |
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 149 |
|