From 86ce645f54d6dc54037256daea84ae4e9d3579c5 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 14 Oct 2010 16:58:15 +0000 Subject: move all the keyword search related things into one subdir of tlpkg/dev git-svn-id: svn://tug.org/texlive/trunk@20097 c570f23f-e606-0410-a88d-b1316a301751 --- .../dev/keyword-search/parse-texcatalogue-keywords | 181 +++++++++++++++++++++ .../keyword-search/read-dump-and-pretty-print.pl | 52 ++++++ .../tlpkg/dev/keyword-search/tlmgr-interface.txt | 35 ++++ 3 files changed, 268 insertions(+) create mode 100755 Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords create mode 100644 Master/tlpkg/dev/keyword-search/read-dump-and-pretty-print.pl create mode 100644 Master/tlpkg/dev/keyword-search/tlmgr-interface.txt (limited to 'Master/tlpkg/dev/keyword-search') diff --git a/Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords b/Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords new file mode 100755 index 00000000000..281542022cc --- /dev/null +++ b/Master/tlpkg/dev/keyword-search/parse-texcatalogue-keywords @@ -0,0 +1,181 @@ +#!/usr/bin/env perl +# $Id$ +# parse a TeXCatalogue v2 .xml dump containing keywords and +# characterizations +# +# Copyright 2010 Norbert Preining +# This file is licensed under the GNU General Public License version 2 +# or any later version. + +$^W = 1; +use strict; + + +use XML::Parser; +use XML::XPath; +use XML::XPath::XMLParser; +use Text::Unidecode; +use Data::Dumper; + +my $tcfile; +if (@ARGV) { + $tcfile = shift @ARGV; +} else { + $tcfile = "texcatalogue.xml"; +} + +my %seikaku; +my %kw_pkg; +my %cz_pkg; + +parse_texcatalogue($tcfile); + +$Data::Dumper::Indent = 1; +print Data::Dumper->Dump([\%seikaku, \%kw_pkg, \%cz_pkg], + ["seikaku", "kw_pkg", "cz_pkg"]), $/; + + +# how to read in!!! +#my $seikaku; +#my $kw_pkg; +#my $cz_pkg; +#my $foo = `cat tc-dump`; +# the no strict "vars" is *ABSOLUT* necessary otherwise the file is not +# evaluated, no idea why! +#no strict "vars"; +#eval "$foo"; +#use strict "vars"; +# +#print_keywords($kw_pkg); +#print "\n===================\nprimary characterizations\n"; +#walk_cz_tree($cz_pkg->{'primary'}, "PRIM"); +#print "\n===================\nsecondary characterizations\n"; +#walk_cz_tree($cz_pkg->{'secondary'}, "SEC"); +#print "\n===================\nby-function characterizations\n"; +#walk_cz_tree($cz_pkg->{'by-function'}, "BFUNC"); + +##### only subs from here ########## + +sub parse_texcatalogue { + my $tcfile = shift; + my $_parser = XML::Parser->new( + ErrorContext => 2, + ParseParamEnt => 1, + NoLWP => 1 + ); + my $io; + open($io, "<", $tcfile) or die "Cannot open texcatalogue.xml: $!"; + my $parser = new XML::XPath->new(ioref => $io, parser => $_parser) || + die "Failed to parse texcatalogue.xml: $!"; + + # format of the data + # $seikaku{'keyword'}{$package} = [ $kwi, $kwii,...]; + # $seikaku{'primary'}{$package} = $primchar; + # $seikaku{'secondary'}{$package'} = $secchar; + # $seikaku{'by-function'}{$package} = [ $bfi, $bfii, ...]; + # + # post processing gives + # $kw_pkg{$keyword} = [ $pkg1, $pkg2, ...]; + # $cz_pkg{'primary'}{$level1}{$level2}...{'_packages_'} = [ $pkg1, $pkg2, ...]; + # $cz_pkg{'secondary'}{$level1}{$level2}...{'_packages_'} = [ $pkg1, $pkg2, ...]; + # $cz_pkg{'by-function'}{$level1}{$level2}...{'_packages_'} = [ $pkg1, $pkg2, ...]; + + + foreach my $e ($parser->find('/fullcat/catalogue/entry')->get_nodelist) { + my $pkg = $parser->findvalue('./name',$e)->value(); + #print "FOUND: $pkg\n"; + my $n = $parser->find('./keyword',$e); + for my $kw ($n->get_nodelist) { + my $kwval = $parser->find('./@keyword',$kw)->string_value(); + push @{$seikaku{'keyword'}{$pkg}}, $kwval; + #print "keyword = $kwval\n"; + } + $n = $parser->find('./characterization',$e); + for my $cz ($n->get_nodelist) { + my $czdimnl = $parser->find('./@dimension',$cz); + my $czdim = $czdimnl->string_value(); + my $czvalnl = $parser->findvalue('.',$cz); + my $czval = $czvalnl->value(); + if (($czdim eq "primary") || ($czdim eq "secondary")) { + # assume only one primary and one secondary function + $seikaku{$czdim}{$pkg} = $czval; + } else { + # assume that it is always "by-function" + push @{$seikaku{'by-function'}{$pkg}}, $czval; + } + #print "char dim = $czdim val=$czval\n"; + } + } + + + # + # do the keyword reshuffling + for my $pkg (keys %{$seikaku{'keyword'}}) { + for my $kw (@{$seikaku{'keyword'}{$pkg}}) { + push @{$kw_pkg{$kw}}, $pkg; + } + } + + parse_characterizations('primary'); + parse_characterizations('secondary'); + parse_characterizations('by-function'); +} + +sub parse_characterizations { + my $what = shift; + $cz_pkg{$what} = {}; + for my $pkg (keys %{$seikaku{$what}}) { + my $value = $seikaku{$what}{$pkg}; + my @charlist; + if (!ref($value)) { + @charlist = ($value); + } else { + @charlist = @$value; + } + for my $prim (@charlist) { + # split the primary into levels sep by > + my @levels = split(' > ', $prim); + my $currentpointer; + $currentpointer = $cz_pkg{$what}; + for my $l (@levels) { + if (!defined($currentpointer->{$l})) { + $currentpointer->{$l} = {}; + } + $currentpointer = $currentpointer->{$l} + } + push @{$currentpointer->{'_packages_'}}, $pkg; + } + } +} + + +sub print_keywords { + my $kw_pkg = shift; + for my $k (keys %$kw_pkg) { + my @pkgl = @{$kw_pkg->{$k}}; + if (defined(@pkgl)) { + print "keyword = $k\n package = @pkgl\n"; + } else { + print "keyword = $k\n package = NO PACKAGE FOUND!\n"; + } + } +} + + +sub walk_cz_tree { + my $cp = shift; + my $prestring = shift; + if (defined($cp->{'_packages_'})) { + my @pkgs = sort @{$cp->{'_packages_'}}; + print "$prestring\n"; + print "--> @pkgs\n"; + } + for my $cz (keys %$cp) { + if ($cz ne '_packages_') { + my $nextstring = "$prestring > $cz"; + my $np = $cp->{$cz}; + &walk_cz_tree($np,$nextstring); + } + } +} + diff --git a/Master/tlpkg/dev/keyword-search/read-dump-and-pretty-print.pl b/Master/tlpkg/dev/keyword-search/read-dump-and-pretty-print.pl new file mode 100644 index 00000000000..ca5a7ba7d76 --- /dev/null +++ b/Master/tlpkg/dev/keyword-search/read-dump-and-pretty-print.pl @@ -0,0 +1,52 @@ +$^W = 1; +use strict; +# how to read in!!! +my $seikaku; +my $kw_pkg; +my $cz_pkg; +my $foo = `cat tc-dump`; +# the no strict "vars" is *ABSOLUT* necessary otherwise the file is not +# evaluated, no idea why! +no strict "vars"; +eval "$foo"; +use strict "vars"; +# +print_keywords($kw_pkg); +print "\n===================\nprimary characterizations\n"; +walk_cz_tree($cz_pkg->{'primary'}, "PRIM"); +print "\n===================\nsecondary characterizations\n"; +walk_cz_tree($cz_pkg->{'secondary'}, "SEC"); +print "\n===================\nby-function characterizations\n"; +walk_cz_tree($cz_pkg->{'by-function'}, "BFUNC"); + + +sub print_keywords { + my $kw_pkg = shift; + for my $k (keys %$kw_pkg) { + my @pkgl = @{$kw_pkg->{$k}}; + if (defined(@pkgl)) { + print "keyword = $k\n package = @pkgl\n"; + } else { + print "keyword = $k\n package = NO PACKAGE FOUND!\n"; + } + } +} + + +sub walk_cz_tree { + my $cp = shift; + my $prestring = shift; + if (defined($cp->{'_packages_'})) { + my @pkgs = sort @{$cp->{'_packages_'}}; + print "$prestring\n"; + print "--> @pkgs\n"; + } + for my $cz (keys %$cp) { + if ($cz ne '_packages_') { + my $nextstring = "$prestring > $cz"; + my $np = $cp->{$cz}; + &walk_cz_tree($np,$nextstring); + } + } +} + diff --git a/Master/tlpkg/dev/keyword-search/tlmgr-interface.txt b/Master/tlpkg/dev/keyword-search/tlmgr-interface.txt new file mode 100644 index 00000000000..c6405c490d8 --- /dev/null +++ b/Master/tlpkg/dev/keyword-search/tlmgr-interface.txt @@ -0,0 +1,35 @@ +How to interface tlmgr search with keywords + +new search interface: + +tlmgr search + + ::= --global | --word | --list [keywords|functions|characterizations] + + ::= | + ::= AND | OR | LEFT | RIGHT + keyword= | function= | + characterization= | + package-name= | title= | + description= | file= + + ::= | " > " + ::= + + +defaults = package-names=ARG OR titles=ARG OR descriptions=ARG +AND -> conjunction +OR -> disjunction +LEFT|RIGHT -> parenthesis for grouping of and and or + + may contain wildcards and it is matched in a glob style (no re!!) + + +example + tlmgr search keyword=paragraph AND description=dropped +should give back the lettrine package + + tlmgr search characterization=bibliography +searches for all packages with characterization containing anywhere the string +"bibliography" (case insensitive). + -- cgit v1.2.3