lib/NNexus/Index/Mathhub.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 81 CC 4 SCAR 16.4
CC
4
Cov
0%
candidate_links
12.0
index_page
6.0
domain_root
2.0
CRAP 5.2
1 # /=====================================================================\ #
2 # | NNexus Autolinker | #
3 # | Indexing Plug-in, MathHub.info domain | #
4 # |=====================================================================| #
5 # | Part of the Planetary project: http://trac.mathweb.org/planetary | #
6 # | Research software, produced as part of work done by: | #
7 # | the KWARC group at Jacobs University | #
8 # | Copyright (c) 2012 | #
9 # | Released under the MIT License (MIT) | #
10 # |---------------------------------------------------------------------| #
11 # | Adapted from the original NNexus code by | #
12 # | James Gardner and Aaron Krowne | #
13 # |---------------------------------------------------------------------| #
14 # | Deyan Ginev <d.ginev@jacobs-university.de> #_# | #
15 # | http://kwarc.info/people/dginev (o o) | #
16 # \=========================================================ooo==U==ooo=/ #
17 package NNexus::Index::Mathhub;
18 use warnings;
19 use strict;
20 use base qw(NNexus::Index::Template);
21 use List::MoreUtils qw(uniq);
22 use URI::Escape;
23  
24 # 1. We want to start from the All Pages entry point, containing the list of all categories
25 sub domain_root { "http://mathhub.info/mh/archives"; }
26 our $mathhub_base = 'http://mathhub.info';
27  
28 sub candidate_links {
29 my ($self)=@_;
30 my $url = $self->current_url;
31 my $dom = $self->current_dom;
32 if ($url =~ /\/source$/) {
33 # List page, collect all leaf pages:
34 my @anchors = grep {$_->{'jobad:href'}} $dom->find('li.dref > span')->each;
35 my @category_pages = map {s/\/([^\/]+)$/\/source\/$1/; $_;} map {uri_unescape($_)} uniq(sort(grep {defined} map {$_->{'jobad:href'}} @anchors));
36 @category_pages = grep {/\.en\.omdoc$/} @category_pages; # Only English pages
37 return \@category_pages; }
38 elsif ($url =~ /archives$/) { # top page
39 my @anchors = $dom->find('div.field-item.even > ul > li > a')->each;
40 print STDERR "\nAnchors found: ",scalar(@anchors),"\n";
41 my @content_pages = map {$mathhub_base . $_ . '/source'} map {uri_unescape($_)} uniq(sort(grep {defined} map {$_->{'href'}} @anchors));
42 return \@content_pages; }
43 else {return [];} # skip leaves
44 }
45  
46 # Index a concept page, ignore category pages
47 sub index_page {
48 my ($self) = @_;
49 my $url = uri_unescape($self->current_url);
50 # Nothing to do in top page, or non-English pages
51 return [] if (($url =~ /smglom\/source$/) || ($url !~ /\.en\.omdoc$/));
52 my $dom = $self->current_dom;
53 my @spans = grep {$_->{'jobad:href'}} $dom->find('span.definiendum')->each;
54 my %mmt_url = map {$_->text => $_->{'jobad:href'}} @spans;
55 my @concepts = map {
56 {
57 url => $mmt_url{$_},
58 concept => $_,
59 scheme => 'MSC',
60 categories => ['XX-XX'], # No categorization available for now
61 }} uniq(grep {length($_)} map {$_->text} @spans);
62  
63 return \@concepts; }
64  
65 1;
66  
67 sub request_interval { 1; }
68  
69 __END__