File: exampleC.pl

package info (click to toggle)
libhtml-microformats-perl 0.105-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,340 kB
  • sloc: perl: 14,121; makefile: 10; sh: 1
file content (34 lines) | stat: -rwxr-xr-x 867 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	use HTML::Microformats;
	use LWP::Simple qw[get];
	use RDF::Query;
	
	my $page  = 'http://twitter.com/t' || 'http://tantek.com/';
	my $graph = HTML::Microformats
	               ->new_document(get($page), $page)
	               ->assume_all_profiles
	               ->parse_microformats
	               ->model;
	
	my $query = RDF::Query->new(<<SPARQL);
	PREFIX foaf: <http://xmlns.com/foaf/0.1/>
	SELECT DISTINCT ?friendname ?friendpage
	WHERE {
		<$page> ?p ?friendpage .
		?person foaf:name ?friendname ;
			foaf:page ?friendpage .
		FILTER (
			isURI(?friendpage)
			&& isLiteral(?friendname) 
			&& regex(str(?p), "^http://vocab.sindice.com/xfn#(.+)-hyperlink")
		)
	}
SPARQL
	
	my $results = $query->execute($graph);
	while (my $result = $results->next)
	{
		printf("%s <%s>\n",
			$result->{friendname}->literal_value,
			$result->{friendpage}->uri,
			);
	}