Re: dereferencing an array - Pt 2

2006-02-11 Thread Brad Baxter
Short answer: $profit{ $facet }{ $term }{ $resource } = $url;

Example:

#!perl
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Terse++;
$Data::Dumper::Indent--;

my %profit;
while(  ) {
chomp;
my( $resource, $url, $term, $facet ) = split /,/;
$profit{ $facet }{ $term }{ $resource } = $url;
}

print Dumper \%profit;

__DATA__
asto magazine,http://oxford.edu,astronomy,subjects
stars r us,http://websters.com,astronomy,subjects
telescope world,http://telescope.com,astronomy,subjects
2 + 2 = 4,http://catalog.nd.edu,mathematics,subjects
math library,http://worldcat.com,mathematics,subjects
und,http://catalog.nd.edu,catalogs,tools
worldcat,http://worldcat.com,catalogs,tools
websters,http://websters.com,dictionaries,tools
oxford,http://oxford.edu,dictionaries,tools


On 2/10/06, Eric Lease Morgan <[EMAIL PROTECTED]> wrote:
>
>
> On Feb 10, 2006, at 5:41 PM, Bruce Van Allen wrote:
>
> > foreach my $facet_key (keys %facets) {
> >   print "$facet_key\n";
> >   my %sub_hash= %{ $facets{$facet_key} };
> >   foreach my $sub_key (keys %sub_hash) {
> > print "\t$sub_key\n";
> > my %inner_hash= %{ $sub_hash{$sub_key} };
> > foreach my $inner_key (keys %inner_hash) {
> >   print "\t\t$inner_key - $inner_hash{$inner_key}\n";
> > }
> >   }
> > }
>
>
> This has been VERY helpful, and I appreciate the assistance. Now I
> need to programatically build the hash.
>
> I have this sample data structure:
>
>my %profile = (
>  'subjects' => {
>'astronomy' => {
>  'telescope world' => 'http://telescope.com',
>  'stars r us' => 'http://websters.com',
>  'asto magazine' => 'http://oxford.edu'
>},
>'mathematics' => {
>  '2 + 2 = 4' => 'http://catalog.nd.edu',
>  'math library' => 'http://worldcat.com'
>}
>  },
>  'tools' => {
>'dictionaries' => {
>  'websters' => 'http://websters.com',
>  'oxford' => 'http://oxford.edu'
>},
>'catalogs' => {
>  'und' => 'http://catalog.nd.edu',
>  'worldcat' => 'http://worldcat.com'
>}
>  }
>);
>
>
> I use the followign code, based on the good work of Bruce, to
> traverse %profile and output a set of nested HTML lists. It works for
> any size of %profile. Fun!
>
>print "";
>foreach my $facet (sort(keys(%profile))) {
>  print "$facet";
>  my %facets = %{$profile{$facet}};
>  print "";
>  foreach my $term (sort(keys(%{$profile{$facet}}))) {
>print "$term";
>my %terms = %{$facets{$term}};
>print "";
>foreach my $resource (sort(keys(%terms))) {
>  print "$resource a>";
>}
>print "";
>print "";
>  }
>  print "";
>  print "";
>}
>print "";
>
>
> I now need to build %profile programatically. As I loop through a set
> of information resources I can determine the following values:
>
>1. resource name (ex: telescope world)
>2. URL (ex: http://telescope.com)
>3. term (ex: astronomy)
>4. facet (ex: subjects)
>
> Given these values, how can I build %profile?
>
> --
> Eric "Perl Data Structures !R My Forte" Morgan
>
>
>
>
>


Re: dereferencing an array - Pt 2

2006-02-11 Thread Eric Lease Morgan


On Feb 11, 2006, at 8:16 AM, Brad Baxter wrote:


I have this sample data structure:

   my %profile = (
 'subjects' => {
   'astronomy' => {
 'telescope world' => 'http://telescope.com',
 'stars r us' => 'http://websters.com',
 'asto magazine' => 'http://oxford.edu'
   },
   'mathematics' => {
 '2 + 2 = 4' => 'http://catalog.nd.edu',
 'math library' => 'http://worldcat.com'
   }
 },
 'tools' => {
   'dictionaries' => {
 'websters' => 'http://websters.com',
 'oxford' => 'http://oxford.edu'
   },
   'catalogs' => {
 'und' => 'http://catalog.nd.edu',
 'worldcat' => 'http://worldcat.com'
   }
 }
   );

I now need to build %profile programatically. As I loop through a set
of information resources I can determine the following values:

   1. resource name (ex: telescope world)
   2. URL (ex: http://telescope.com)
   3. term (ex: astronomy)
   4. facet (ex: subjects)

Given these values, how can I build %profile?



Short answer: $profile{ $facet }{ $term }{ $resource } = $url;



Wow! Perfect!!

I have been able to take what Jonathan Gorman, Bruce Van Allen, and  
Brad Baxter have given me and incorporate it into a the beginnings of  
a patron-specific interface of MyLibrary. In MyLibrary patrons can be  
created and "cataloged" with facet/term combinations -- a controlled  
vocabulary. These same facet/term combinations are used to "catalog"  
information resources. Thus, through the controlled vocabulary I am  
able to create relationships between resources and patrons.


The results is the display of a set of information resources designed  
for individuals with particular characteristics. For example, try the  
following URLs. Each points to a different patron with different  
characteristics, and each page provides the ability to display the  
information resources in an alphabetical or grouped view:


  * Andrew Carnegie
http://dewey.library.nd.edu/morgan/portal/?cmd=patron&id=194

  * Leonardo D'Vinci
http://dewey.library.nd.edu/morgan/portal/?cmd=patron&id=191

  * Galileo Galilei
http://dewey.library.nd.edu/morgan/portal/?cmd=patron&id=193


Thanks guys. I have added your names to my code.

--
Eric Morgan