473,396 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GSYN,depth bound transitive relations

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env perl
  2. ################################################################
  3. ### gsyn2
  4. ### Plamena Dragieva
  5. ### Oct 30, 2008
  6. ################################################################
  7.  
  8.  
  9.  
  10. use strict;
  11. use warnings;
  12. use Carp;
  13. use English '-no_match_vars';
  14. use utf8;
  15. binmode(STDOUT, ":utf8");
  16.  
  17. use LWP;
  18. use WWW::Mechanize 0.48;
  19. use Encode;
  20.  
  21. my $word = decode_utf8($ARGV[0]);
  22. my $url = "http://www.google.com/search?hl=en&q=%7E$word&btnG=Search";
  23. my $mech = WWW::Mechanize->new(autocheck => 1);
  24. $mech->get($url);
  25. my $page = $mech->content;
  26.  
  27. # Look for some bit of text occuring just before the real results.
  28. # Throw away all text before this.
  29. $page =~ s/.*?Save time//;
  30.  
  31. my %found;
  32.  
  33.  
  34. # This matches anything in bold. Uses non-greedy matching.
  35. while ($page =~ m/<b>(.*?)<\/b>/g) {
  36.     $found{$1}++;
  37. }
  38.  
  39. # Get one more page from Google.
  40. $page = $mech->follow_link( text => "Next", n => 1 )->content;
  41. $page =~ s/.*?Results//;
  42. while ($page =~ m/<b>(.*?)<\/b>/g) {
  43.     $found{$1}++;
  44. }
  45.  
  46. foreach (keys %found) {
  47.     my $key = $_;
  48.     if ($key !~ m/\.\./ && $key !~ m/~$word/) {
  49.         print "$_\n";
  50.     }
  51. }
  52.  
How can I modify this code so that I get a second command line argument?
Here is the task.
Try running the gsyn program (located in /afs/sfs/lehre/dg/perl):

prompt> gsyn beer
11
budweiser
Beer
Ale
ale
20
beer
0.22
beers
724,000,000

You see that this program returns a number of words that are
related or synonymous with 'beer' (or whatever word you choose).
Try some other possibilities. Then try 'gsyn ale' and you get the
word "brewery". Similarly 'gsyn brewery' returns the word
"restaurant." So by transitivity, the word "beer" is related to the
word "restaurant." Modify the gsyn program so that it returns these
transitive relations (to some depth bound).
Oct 30 '08 #1
2 1874
numberwhun
3,509 Expert Mod 2GB
If you provide a second command line option, then you can reference it with $ARGV[1], the next element in the array you referenced in your code.

Regards,

Jeff
Oct 30 '08 #2
KevinADC
4,059 Expert 2GB
Whatever, I just love that descriptive bit of gobbeldy-guk:

depth bound transitive relations

I'm going to try and use that in a sentence one of these days
Oct 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mikito Harakiri | last post by:
Transitive closure (TC) of a graph is with TransClosedEdges (tail, head) as ( select tail, head from Edges union all select e.tail, ee.head from Edges e, TransClosedEdges ee where e.head =...
7
by: David | last post by:
Hi there, I'm having some trouble identifying transitive dependencies in the student table below StudId Name CourseCode CourseDesc Lecturer Grade Office 'S1234', 'Jack', ...
1
by: Jef De Rycke | last post by:
Hi access group, I have written code to create relations between tables according to a corresponding relations information table. At first I thought my code was not working properly because...
3
by: Christopher Jedlicka | last post by:
Hi, I am trying to use a datagrid control to display hierarchical data in a flat format essentially in a master-detail relationship. i.e. <Data> <Customer CustomerName="Customer1"> <Order...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
0
by: Dave | last post by:
I'm having trouble trying to get some bound datagrids to work. I even tried to use some examples that were given to me, but I can't get those to work, either. I have customers, who have orders,...
3
by: Bill | last post by:
I have what I think should be a simple question regarding a bound combo box. My first table is Dealers: DealerID - primary key DealerName BillToLocation My second table is Locations:...
4
by: N. Graves | last post by:
Thanks for reading my request for help! I have a Bound Object Frame that I have stored a Word Document. When I double click to view the document it is very small and unreadable. If I try to...
1
by: =?Utf-8?B?QWRl?= | last post by:
Hi, I have three datagridview controls bound to three tables in a dataset. Two relations exist to join the three tables. Ie Master to Child1 and then Child 1 to Child 2. The Master and Child 1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.