Re: [greenstone-devel] AZCompactList sorting

From Don Gourley
DateSun, 7 Sep 2003 15:46:00 -0400 (EDT)
Subject Re: [greenstone-devel] AZCompactList sorting
In-Reply-To (34951-66-215-217-28-1062936416-squirrel-library-ucr-edu)
Gordon Paynter said:
> Hi all,
>
> Does anyone know exactly how AZCompactList classifiers sort the documents
> inside each category? The global sortmeta in import doesn't work, and
> there's no classifier-specific option. The code is not easy to read (gsdl
> 2.39).

Gordon, take a look at this patch that Stephen DeGabrielle posted
a couple of months ago. It appears that AZCompactList is sorting
by date (ascending) and we successfully changed that one line to
get ours to sort by Title. I'm not sure about descending sorts,
but perhaps the sorttools package can help?

-Don

------------------------------ Original Message ------------------------------
Subject: [greenstone-devel] sorting leaves in AZCompactList classifier (and
patch?) From: Stephen.DeGabrielle@ntu.edu.au
Date: Wed, July 9, 2003 10:37 pm
To: greenstone-devel@list.scms.waikato.ac.nz
------------------------------------------------------------------------------

Hi, we are using AZCompactList to create a two level listing with our ereserve
items sorted by unitcode and lecturer. We discovered that the leaves of the
AZCompactList in this case were unsorted -
In our case it is desirable to have leaves sorted by title for easy retrival
by students, so after hunting around the classifiers code we have a small
modification of our own (Though probably not for everybody)
push @args, ("-sort", "Title");

this allows us to sort on the title field in the leaves.
In most cases this works fine but one group of documents is behaving strangely
they have extra metadata 'AltTitle' in addition to title. (Not DC standard)
The 'AltTitle' metadata is used to supply an english translation of a foreign
language 'Title' metadata. The other documents don't have
'AltTitle' and are sorting fine, but the 'AltTitle' ones end up being put
first in the sorted list, followed by the items without and 'AltTitle'
(Example follows)

Has anyone encountered this problem? Know how to resolve it?
(copies of output,code,and metadata follow)

Regards,

Stephen

PS How do the maintainers feel about me changing AZCompactList to pass a '
-sortleaves <metadataname>' instead of just this little patch?

s.


-greenstone browser output showing problem
copied from screen-my comments in brackets-

THTFTG03B (branch)
(leaves follow..)
Kakadu National Park: ihr ferlenpianer
Lecturer: Hutton, Ian
Parc National de Kakadu: plans de vacances
Lecturer: Hutton, Ian
Parque Nacional de Kakadu: planificador de vacaciones
Lecturer: Hutton, Ian
Piano per le vacanze nel parco nazionale Kakadu
Lecturer: Hutton, Ian (end of 'AltTitle leaves/start of others)
Kakadu: a guide for all seasons
Lecturer: Hutton, Ian
Kakadu National Park entry fees leaflet
Lecturer: Hutton, Ian
Kakadu National Park: holiday planner
Lecturer: Hutton, Ian
Kakadu National Park: holiday planner
Lecturer: Hutton, Ian
Park notes: Bowali visitor centre
Lecturer: Hutton, Ian
Welcome to the Aboriginal lands of Kakadu National Park: visitor guide and
maps
Lecturer: Hutton, Ian
(...end of leaves)

---


-
-sub reinit from AZCompactList.pm-
sub reinit
{
my ($self,$classlist_ref) = @_;
my $outhandle = $self->{'outhandle'};

my %mtfreq = ();
my @single_classlist = ();
my @multiple_classlist = ();

# find out how often each metavalue occurs
map
{
my $mv;
foreach $mv (@{$self->{'listmetavalue'}->{$_}} )
{
$mtfreq{$mv}++;
}
} @$classlist_ref;

# use this information to split the list: single metavalue/repeated
value
map
{
my $i = 1;
my $metavalue;
foreach $metavalue (@{$self->{'listmetavalue'}->{$_}})
{
if ($mtfreq{$metavalue} >= $self->{'mingroup'})
{
push(@multiple_classlist,[$_,$i,$metavalue]);
}
else
{
push(@single_classlist,[$_,$metavalue]);
$metavalue =~ tr/[A-Z]/[a-z]/;
$self->{'reclassifylist'}->{"Metavalue_$i.$_"} = $metavalue;
}
$i++;
}
} @$classlist_ref;


# Setup sub-classifiers for multiple list

$self->{'classifiers'} = {};

my $pm;
foreach $pm ("List", "SectionList")
{
my $listname
= &util::filename_cat($ENV
{'GSDLHOME'},"perllib/classify/$pm.pm");
if (-e $listname) { require $listname; }
else
{
print $outhandle "AZCompactList ERROR - couldn't find classifier
"$listname" ";
die " ";
}
}

# Create classifiers objects for each entry >= mingroup
my $metavalue;
foreach $metavalue (keys %mtfreq)
{
if ($mtfreq{$metavalue} >= $self->{'mingroup'})
{
my $listclassobj;
my $doclevel = $self->{'doclevel'};
my $metaname = $self->{'metaname'};
my @metaname_list = split('/',$metaname);
$metaname = shift(@metaname_list);
if (@metaname_list==0)
{
my @args;
push @args, ("-metadata", "$metaname");
# buttonname is also used for the node's title
push @args, ("-buttonname", "$metavalue");
push @args, ("-sort", "Date");
###############################################################################
## SORT LEAVES (s.degabrielle/I.Rohoza 2003)
push @args, ("-sort", "Title");
################################################################
if ($doclevel =~ m/^top(level)?/i)
{
eval ("$listclassobj = new List(@args)"); warn $@ if $@;
}
else
{
eval ("$listclassobj = new SectionList(@args)");
}
}
else
{
$metaname = join('/',@metaname_list);

my @args;
push @args, ("-metadata", "$metaname");
# buttonname is also used for the node's title
push @args, ("-buttonname", "$metavalue");
push @args, ("-doclevel", "$doclevel");
push @args, "-recopt";


eval ("$listclassobj = new AZCompactList(@args)");
}
if ($@) {
print $outhandle "$@";
die " ";
}

$listclassobj->init();

if (defined $metavalue && $metavalue =~ /w/)
{
my $formatted_node = $metavalue;

if ($self->{'removeprefix'}) {
$formatted_node =~ s/^$self->{'removeprefix'}//;
}

if ($self->{'metaname'} =~ m/^Creator(:.*)?$/)
{
&sorttools::format_string_name_english($formatted_node);
}
else
{
&sorttools::format_string_english($formatted_node);
}

# In case our formatted string is empty...
if (! defined($formatted_node)) {
print $outhandle "Warning: AZCompactList: metavalue is ";
print $outhandle "empty ";
$formatted_node="";
}

$self->{'classifiers'}->{$metavalue}
= { 'classifyobj' => $listclassobj,
'formattednode' => $formatted_node };
}
}
}


return (@single_classlist,@multiple_classlist);
}