Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > returning calculation results in perl scripts

Reply
Thread Tools

returning calculation results in perl scripts

 
 
spanish26@gmail.com
Guest
Posts: n/a
 
      01-21-2009
Hello,

I am running a program using perl scripts to calculate the proximity
between two search terms when they are entered in the form box, i can
successfully view the form boxes, but when i click on the calculate
button after entering the term, i do not get any result, the values do
not show any result

E.g lets say i enter two terms "egg" term 1 and "fish" term 2 and i
click on the calculate button, i am supposed to see the following
results:
NGD(x,y) = some value

Term1: +:"egg"
f(x) = some value
log f(x) = some value

Term 2: +"fish"
f(y) = some value
log f (y) = some value

Intersection: +"egg" + "fish"
f(x,y) = some value

i dont get any result when click the calculate.

The source code is below :

#!"C:\Program Files\xampp\perl\bin\perl.exe"
# ngd-calculator.cgi
#
# wjt
# http://history.uwo.ca/faculty/turkel/
#
# 5 aug 2006

use SOAP::Lite;
use CGI;
use POSIX qw(log10);
use List::Util qw(max min);

# Google API developer's key
my $google_key = '<Insert Key Here>';

# Google WSDL
my $google_wsdl = "http://api.google.com/GoogleSearch.wsdl";
# my $google_wsdl = "./GoogleSearch.wsdl";

# start, maxResults, filter, restrict, safeSearch, lr, ie, oe
my @params = (0, 10, 0, '', 0, '', 'utf-8', 'utf-8');

# Do Google search and return count
sub do_search {
unshift (@params, ($google_key, $_[0]));
my $result =
SOAP::Lite
-> service($google_wsdl)
-> doGoogleSearch(@params);
shift @params;
shift @params;
return $result->{estimatedTotalResultsCount};
}

# Create the search page
$query = new CGI;
print $query->header;
print $query->start_html('NGD Calculator');
print "<H1>Normalized Google Distance (NGD) Calculator</H1>";

print '<p>';
print 'For information about NGD see Rudi Cilibrasi and Paul Vitanyi,
"';
print '<a href="http://www.arxiv.org/PS_cache/cs/pdf/
0412/0412098.pdf">';
print 'Automatic Meaning Discovery Using Google</a>."';
print '</p>';

# Print the search box form
print $query->startform;
print '<strong>Enter term 1</strong> ',$query->textfield('term1');
print '<br />';
print '<strong>Enter term 2</strong> ',$query->textfield('term2');
print '<br />';
print $query->submit('form_1','Calculate');
print $query->endform;
print '<br />';

$x = ''; $y = ''; $xy = '';
$x = '+"' . $query->param('term1') . '"';
$y = '+"' . $query->param('term2') . '"';
$xy = $x . " " . $y;

$fx = 1; $fy = 1; $fxy = 1;
$logfx = 0; $logfy = 0; $logfxy = 0; $logm = 0;
$maxlogfxy = 0; $minlogfxy = 0;
$ngd = 0;

# Best guess as of Jan 2006
$m = 11828505634;

if ($x && $y) {

# Determine frequencies
$fx = do_search( $x );
$fy = do_search( $y );
$fxy = do_search( $xy );

# Determine logarithms
$logm = log10( $m );
$logfx = log10( $fx );
$logfy = log10( $fy );
$logfxy = log10( $fxy );

# Determine max and min
@fxy = ($logfx, $logfy);
$maxlogfxy = max @fxy;
$minlogfxy = min @fxy;

# Calculate NGD
$ngd = ($maxlogfxy - $logfxy) / ($logm - $minlogfxy);

print 'NGD(x,y) = ' . $ngd . '<br /><br />';

print 'Term 1: ' . $x . '<br />';
print 'f(x) = ' . $fx . '<br />';
print 'log f(x) = ' . $logfx . '<br /><br />';

print 'Term 2: ' . $y . '<br />';
print 'f(y) = ' . $fy . '<br />';
print 'log f(y) = ' . $logfy . '<br /><br />';

# print 'max(log f(x),log f(y)) = ' . $maxlogfxy . '<br />';
# print 'min(log f(x),log f(y)) = ' . $minlogfxy . '<br /><br />';

print 'Intersection: ' . $xy . '<br />';
print 'f(x,y) = ' . $fxy . '<br />';
print 'log f(x,y) = ' . $logfxy . '<br /><br />';

print 'M: ' . $m . '<br />';
print 'log M: ' . $logm . '<br />';
}

print qq{<P><A HREF="http://history.uwo.ca/faculty/turkel">Digital
History at Western</A>};
print $query->end_html;

Thank you
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-21-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:(E-Mail Removed):

> I am running a program using perl scripts to calculate the proximity
> between two search terms when they are entered in the form box, i can
> successfully view the form boxes, but when i click on the calculate
> button after entering the term, i do not get any result, the values do
> not show any result


I do not have a Google API key so I can't try out your code. AFAIK,
Google no longer hands out keys for that service:
http://google-code-updates.blogspot....earch-api.html

I will point out that you need to divide the problem into two separate
questions:

1) Are you getting back results?

2) Are those results being output properly?

As I said, I cannot look into (1) above. (2) is a stealth CGI question,
not a Perl question, but let's look at the code below.

> #!"C:\Program Files\xampp\perl\bin\perl.exe"
> # ngd-calculator.cgi
> #
> # wjt
> # http://history.uwo.ca/faculty/turkel/
> #
> # 5 aug 2006


Here, you are missing:

use strict;
use warnings;

Please see the posting guidelines for why you should include
those pragmas so that you can help yourself and help others help
you more effectively.

> use SOAP::Lite;
> use CGI;
> use POSIX qw(log10);
> use List::Util qw(max min);


<snip>

Code accessing Google Search service. You should test this part
separately from the command line.

</snip>

> # Create the search page
> $query = new CGI;


my $query = CGI->new;

Avoid indirect object notation.

> print $query->header;
> print $query->start_html('NGD Calculator');
> print "<H1>Normalized Google Distance (NGD) Calculator</H1>";


Here, you are mixing CGI.pm's output generation routines with plain HTML.
I would recommend using HTML::Template or some other similar solution
to separate presentation from logic.

Also, by default, CGI.pm outputs XHTML in which upper case tags
are not valid AFAIK.

In any case, you should try the script from the command line to see
what happens there. See
http://search.cpan.org/~lds/CGI.pm-3...I.pm#DEBUGGING

Please provide a small, self-contained example others can run from
the command line that still exhibits the problem.

Sinan
--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
Reply With Quote
 
 
 
 
spanish26@gmail.com
Guest
Posts: n/a
 
      01-21-2009

Thank you, i signed for the Google API developers key on Monday and i
was issued the key.
I ran the program on the command prompt, but got error. when
debugging.


On Jan 21, 9:11*pm, "A. Sinan Unur" <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote innews:(E-Mail Removed):
>
> > I am running a program using perl scripts to calculate the proximity
> > between two search terms when they are entered in the form box, i can
> > successfully view the form boxes, but when i click on the calculate
> > button after entering the term, i do not get any result, the values do
> > not show any result

>
> I do not have a Google API key so I can't try out your code. AFAIK,
> Google no longer hands out keys for that service:http://google-code-updates.blogspot....soap-search-ap...
>
> I will point out that you need to divide the problem into two separate
> questions:
>
> 1) Are you getting back results?
>
> 2) Are those results being output properly?
>
> As I said, I cannot look into (1) above. (2) is a stealth CGI question,
> not a Perl question, but let's look at the code below.
>
> > #!"C:\Program Files\xampp\perl\bin\perl.exe"
> > # ngd-calculator.cgi
> > #
> > # wjt
> > #http://history.uwo.ca/faculty/turkel/
> > #
> > # 5 aug 2006

>
> Here, you are missing:
>
> use strict;
> use warnings;
>
> Please see the posting guidelines for why you should include
> those pragmas so that you can help yourself and help others help
> you more effectively.
>
> > use SOAP::Lite;
> > use CGI;
> > use POSIX qw(log10);
> > use List::Util qw(max min);

>
> <snip>
>
> Code accessing Google Search service. You should test this part
> separately from the command line.
>
> </snip>
>
> > # Create the search page
> > $query = new CGI;

>
> my $query = CGI->new;
>
> Avoid indirect object notation.
>
> > print $query->header;
> > print $query->start_html('NGD Calculator');
> > print "<H1>Normalized Google Distance (NGD) Calculator</H1>";

>
> Here, you are mixing CGI.pm's output generation routines with plain HTML.
> I would recommend using HTML::Template or some other similar solution
> to separate presentation from logic.
>
> Also, by default, CGI.pm outputs XHTML in which upper case tags
> are not valid AFAIK.
>
> In any case, you should try the script from the command line to see
> what happens there. Seehttp://search.cpan.org/~lds/CGI.pm-3.42/CGI.pm#DEBUGGING
>
> Please provide a small, self-contained example others can run from
> the command line that still exhibits the problem.
>
> Sinan
> --
> A. Sinan Unur <(E-Mail Removed)>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Presenting calculation results Vedran Python 1 09-10-2008 05:18 PM
What is required for perl scripts to run correct when launched from rc scripts on HPUX 11? deanjones7@gmail.com Perl Misc 13 09-10-2007 11:58 AM
Problem with returning prime number in a simple calculation program QHorizon@gmail.com Python 2 03-04-2007 12:32 AM
Layout depending on simple results of a calculation Badass Scotsman ASP .Net 1 04-24-2006 05:56 PM
strange calculation results...? Jeremy Java 1 02-18-2004 06:12 AM



Advertisments