File Coverage

blib/lib/Text/SenseClusters/LabelEvaluation/Wikipedia/GetWikiData.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             # Declaring the Package for the module.
4             package Text::SenseClusters::LabelEvaluation::Wikipedia::GetWikiData;
5              
6 2     2   37802 use strict;
  2         4  
  2         89  
7 2     2   1765 use encoding "utf-8";
  2         18821  
  2         16  
8              
9             # The following two lines will make this module inherit from the Exporter Class.
10             require Exporter;
11             our @ISA = qw(Exporter);
12              
13             # Using WWW::Wikipedia Module.
14             # Reference: http://search.cpan.org/dist/WWW-Wikipedia/lib/WWW/Wikipedia.pm
15 2     2   3249 use WWW::Wikipedia;
  2         312084  
  2         198  
16              
17             # Defining the Variable for using the Wikipedia Module.
18             # Reference: http://search.cpan.org/~bricas/WWW-Wikipedia-2.00/
19             my $wiki = WWW::Wikipedia->new();
20              
21             #######################################################################################################################
22              
23             =head1 Name
24              
25             Text::SenseClusters::LabelEvaluation::Wikipedia::GetWikiData - Module for getting the information about a topic from wikipedia.
26              
27             =head1 SYNOPSIS
28              
29             #The following code snippet will show how to use this module.
30              
31             # Including the LabelEvaluation Module.
32             use Text::SenseClusters::LabelEvaluation::Wikipedia::GetWikiData;
33              
34             # Defining the topic name for which we will create the file containing their detail
35             # data from the wikipedia.
36             my $topicName ="BillClinton";
37              
38              
39             # The following code will call the getWikiDataForTopic() function from the
40             # GetWikiData modules. It will create the file containing the wikipedia
41             # information about the topic.
42             my $fileName =
43             Text::SenseClusters::LabelEvaluation::Wikipedia::GetWikiData::getWikiDataForTopic(
44             $topicName);
45              
46             print "\nName of the File created for the topic \'$topicName\' is $fileName \n";
47              
48              
49             =head1 DESCRIPTION
50            
51             Given a topic, this module is responsible for getting the wikipedia
52             information about it and writing it to file with the file-name as,
53             '.txt'
54            
55             =cut
56              
57             ##########################################################################################
58             =head1 function: getWikiDataForTopic
59             ---------------------------------------------------
60              
61             This function will fetch data about a topics from the Wikipedia, then it
62             will write the fetched data into a new file 'topic_Name.txt'.
63              
64              
65             @argument1 : Name of the topic for which we need to fetch data from the
66             Wikipedia.
67              
68             @return : Name of the file in which this function has written the
69             data,'topic_Name.txt'.
70            
71             @description :
72             1). Reading the topic to read from the function arguments.
73             2). Use this topic name to create file name in which we will write
74             data about the topic.
75             3). Get the data from the Wikipedia module about the topic and write
76             it into the above mentioned topic.
77             4). Return the file name.
78              
79             =cut
80             ##########################################################################################
81             sub getWikiDataForTopic{
82            
83             # Read the Topic name from the argument of the function.
84 3     3 0 13 my $topicToLook = shift;
85            
86             # Removing the white space from the front and end of the word.
87 3         30 $topicToLook =~ s/^\s+|\s+$//g;
88              
89             # Removing the white space with underscore.
90 3         17 $topicToLook =~ s/\s+/_/g;
91              
92             # Creating the fileName from the topic name.
93 3         16 my $fileName = "temp_$topicToLook.txt";
94            
95             # Open the file handle in Write Mode.
96 3         316 open (MYFILE, ">$fileName");
97              
98             # Use Wikipedia Search to get the result about the topic.
99             # Reference: http://search.cpan.org/~bricas/WWW-Wikipedia-2.00/
100 3         26 my $result = $wiki->search($topicToLook);
101              
102             # If the entry has some text, write it out to file.
103 3 50       16205697 if ($result){
104             # Writing the content of the search result into the newly created file.
105 3         27 print MYFILE $result->text();
106            
107             # Also writing the list of any related items into the files.
108 3         212 print MYFILE join( "\n", $result->related() );
109             }
110              
111             # Close the file handle.
112 3         1487 close (MYFILE);
113              
114             # Returning the name of the file in which we write the Wikipedia data
115             # about the given topic.
116 3         250 return $fileName;
117             }
118              
119              
120              
121              
122             #######################################################################################################
123             =pod
124              
125              
126             =head1 SEE ALSO
127              
128             http://senseclusters.cvs.sourceforge.net/viewvc/senseclusters/LabelEvaluation/
129            
130             @Last modified by : Anand Jha
131             @Last_Modified_Date : 24th Dec. 2012
132             @Modified Version : 1.3
133              
134            
135             =head1 AUTHORS
136              
137             Ted Pedersen, University of Minnesota, Duluth
138             tpederse at d.umn.edu
139              
140             Anand Jha, University of Minnesota, Duluth
141             jhaxx030 at d.umn.edu
142              
143              
144              
145             =head1 COPYRIGHT AND LICENSE
146              
147             Copyright (C) 2012 Ted Pedersen, Anand Jha
148              
149             See http://dev.perl.org/licenses/ for more information.
150              
151             This program is free software; you can redistribute it and/or modify
152             it under the terms of the GNU General Public License as published by
153             the Free Software Foundation; either version 2 of the License, or
154             (at your option) any later version.
155              
156             This program is distributed in the hope that it will be useful,
157             but WITHOUT ANY WARRANTY; without even the implied warranty of
158             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159             GNU General Public License for more details.
160              
161             You should have received a copy of the GNU General Public License
162             along with this program; if not, write to:
163            
164            
165             The Free Software Foundation, Inc., 59 Temple Place, Suite 330,
166             Boston, MA 02111-1307 USA
167            
168            
169             =cut
170             #######################################################################################################
171              
172              
173             # Making the default return statement as 1;
174             # Reference : http://lists.netisland.net/archives/phlpm/phlpm-2001/msg00426.html
175             1;