change rules for cluster accessible dirs.
[cxgn-corelibs.git] / lib / CXGN / Glossary.pm
blobac10a18682f16aae2da332169e1951cabfdfc642
1 package CXGN::Glossary;
2 use CXGN::DB::Connection;
4 =head1 NAME
6 CXGN::Glossary -- Helper functions for querying the glossary database.
8 =head1 SYNOPSIS
10 Allows a list of definitions for a term to be searched and for the first of
11 those definitions to be put into a toolip.
13 =head1 FUNTIONS
15 All functions are EXPORT_OK.
17 =over 4
19 =cut
21 BEGIN {
22 our @ISA = qw/Exporter/;
23 use Exporter;
24 our $VERSION = sprintf "%d.%03d", q$Revision: 1.1 $ =~ /(\d+)/g;
25 our @EXPORT_OK = qw/ get_definitions get_glossary_tooltip create_tooltips_from_text/;
27 our @ISA;
28 our @EXPORT_OK;
30 sub get_definitions{
31 my $dbh=CXGN::DB::Connection->new();
32 my $term = $_[0];
33 $term = lc($term);
34 $term =~ s/\s+/ /g;
35 $term =~ s/^\s+//;
36 $term =~ s/\s+$//;
37 my $terms = $dbh->selectall_arrayref("select definition from glossary where ? ilike term", undef, $term);
38 my @definitions;
39 for(my $i = 0; $i < @{$terms}[$i]; $i++){
40 $definitions[$i] = $terms->[$i][0];
42 return @definitions;
45 sub get_glossary_tooltip{
46 my $term = $_[0];
47 my @defs = get_definitions($term);
48 if(@defs == 1){
49 return tooltipped_text($term, $defs[0]);
51 elsif(@defs > 1){
52 return tooltipped_text("<a href = \"glossarysearch.pl?getTerm=$term\">$term</a>",$defs[0]."<br />See link for more definitions.");
54 else{
55 return $term;
58 #Doesn't work, should take a paragraph of text and make a tooltip for
59 #every word that is in the database.
60 sub create_tooltips_from_text{
61 my @words = split(" ", $_[0]);
62 my $text;
63 for $word(@words){
64 $text .= " " . get_glossary_tooltip($word);
66 return $text;