From: Adam Dickmeiss Date: Tue, 28 Jun 2011 15:15:52 +0000 (+0200) Subject: idzebra-abs2dom part of dist and packages X-Git-Tag: v2.0.48~4 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=df71705159b0acf7d390a28bbdd0e48d1361d15a;p=idzebra-moved-to-github.git idzebra-abs2dom part of dist and packages Solves bug #2685. --- diff --git a/debian/idzebra-2.0-utils.install b/debian/idzebra-2.0-utils.install index d839031..396e623 100644 --- a/debian/idzebra-2.0-utils.install +++ b/debian/idzebra-2.0-utils.install @@ -1,2 +1,3 @@ usr/bin/zebraidx-2.0 usr/bin/zebrasrv-2.0 +usr/bin/idzebra-abs2dom diff --git a/debian/idzebra-2.0-utils.manpages b/debian/idzebra-2.0-utils.manpages index 3d268eb..aee27c4 100644 --- a/debian/idzebra-2.0-utils.manpages +++ b/debian/idzebra-2.0-utils.manpages @@ -1,2 +1,3 @@ doc/zebrasrv-2.0.8 doc/zebraidx-2.0.1 +doc/idzebra-abs2dom.1 diff --git a/doc/Makefile.am b/doc/Makefile.am index 8d315ae..5473cae 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -2,13 +2,14 @@ SUBDIRS = common docdir=$(datadir)/doc/$(PACKAGE)$(PACKAGE_SUFFIX) -XMLMAN = zebraidx.xml zebrasrv.xml idzebra-config.xml +XMLMAN = zebraidx.xml zebrasrv.xml idzebra-config.xml idzebra-abs2dom.xml XMLFILES = \ administration.xml \ architecture.xml \ field-structure.xml \ gpl-2.0.xml \ + idzebra-abs2dom.xml \ indexdata.xml \ installation.xml \ introduction.xml \ @@ -57,6 +58,9 @@ idzebra-config$(PACKAGE_SUFFIX).1: idzebra-config.xml $(MAN_COMPILE) $(srcdir)/idzebra-config.xml mv idzebra-config.1 idzebra-config$(PACKAGE_SUFFIX).1 +idzebra-abs2dom.1: idzebra-abs2dom.xml + $(MAN_COMPILE) $(srcdir)/idzebra-abs2dom.xml + $(HTMLFILES): $(XMLFILES) $(PNGFILES) rm -f *.html $(HTML_COMPILE) $(srcdir)/idzebra.xml diff --git a/doc/idzebra-abs2dom.xml b/doc/idzebra-abs2dom.xml new file mode 100644 index 0000000..3a711ae --- /dev/null +++ b/doc/idzebra-abs2dom.xml @@ -0,0 +1,65 @@ + + %local; + + %entities; + + %idcommon; +]> + + + zebra + &version; + + + + idzebra-abs2dom + 1 + + + + idzebra-abs2dom + Converts .abs files to DOM XML configuration files + + + + + idzebra-abs2dom + file + + + + DESCRIPTION + + idzebra-abs2dom converts grs filter .abs files + to DOM XML filter index XSLT files. + The melm and xelm directives are converted to XSLT rules. Conversion + of elm directives are not supported. + + + SEE ALSO + + + zebraidx + 1 + + + + + + diff --git a/idzebra.spec b/idzebra.spec index 426c51f..a624c9e 100644 --- a/idzebra.spec +++ b/idzebra.spec @@ -72,9 +72,11 @@ rm -fr ${RPM_BUILD_ROOT} %config /usr/share/idzebra-2.0/tab %{_bindir}/zebrasrv-* %{_bindir}/zebraidx-* +%{_bindir}/idzebra-abs2dom* /usr/share/doc/idzebra-2.0 %{_mandir}/*/zebraidx-* %{_mandir}/*/zebrasrv-* +%{_mandir}/*/idzebra-abs2dom* /usr/share/idzebra-2.0-examples %files -n lib%{name} diff --git a/util/Makefile.am b/util/Makefile.am index 2a967b3..e7a1412 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -5,7 +5,7 @@ check_PROGRAMS = tstcharmap tstflock tstlockscope tstpass tstres test_strmap TESTS = $(check_PROGRAMS) -bin_SCRIPTS = idzebra-config-2.0 +bin_SCRIPTS = idzebra-config-2.0 idzebra-abs2dom EXTRA_DIST = zebrasrv.rh tstcharmap.chr emptycharmap.chr tstpass.txt tstres.cfg mk_version.tcl diff --git a/util/abs2dom b/util/abs2dom deleted file mode 100755 index bfb77d9..0000000 --- a/util/abs2dom +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/perl -w - -# ---------------------------------------------------------------------------- -# Generate a dom-filter indexing stylesheet based upon an .abs file -# Should be called either this way -# -# abs2dom something.abs > something.xsl -# -# or in a streaming way -# -# something | abs2dom > something.xsl -# -# The output xslt stylesheet generally needs a little bit of tweaking to be -# ready for indexing. In particular, watch out for the precedence rules of -# xslt templates which work differently from xelm declarations in an .abs file! -# -# Good luck! - -use strict; - -my $marc_prefix = 'marc'; -my $supported_rules = { - - # Supported indexing types: - 'melm' => \&melm_handler, - 'xelm' => sub { return $_[1] }, - - # Declarations to ignore: - 'attset' => 0, - 'encoding' => 0, - 'esetname' => 0, - 'marc' => 0, - 'name' => 0, - 'xpath' => 0 - -}; - -print < - - - - - - - - - - -END_OF_XSLT - - -while (<>) { - my $handler = undef; - - chomp; - s/^\s+//; - s/\s+$//; - next unless length; - next if /^#/; - - my ($rule) = (/^(\S+)/); - - if ( defined $supported_rules->{$rule} ) { - $handler = $supported_rules->{$rule}; - - if ( $handler == 0 ) { - next; - } - } else { - print STDERR "$0: Unsupported indexing rule: '", $rule, "\n\n"; - next; - } - - s/^\Q$rule\E\s+//; - - my ($index) = (/(\S+)$/); - - s/\s+\Q$index\E$//; - - my $match = $_; - my $xpath = $handler->($rule, $match); - my @indexes = split /,/, $index; - - # To avoid screwing up the instruction... - $xpath =~ s/"/'/g; - - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n\n"; -} - -print "\n"; - - -sub melm_handler { - my ($rule, $match) = @_; - my ($field, $subfield) = ($match =~ /([^\$]+)\$?(.*)/); - my $xpath = '/*/'; - - if ( $field =~ /^00/ ) { - $xpath .= $marc_prefix . ':controlfield[@tag=\'' . $field . '\']'; - } else { - $xpath .= $marc_prefix . ':datafield[@tag=\'' . $field . '\']/' . - $marc_prefix . ':subfield'; - - if ( $subfield ne '' ) { - $xpath .= '[@code=\'' . $subfield . '\']'; - } - } - - return $xpath; -} - - - diff --git a/util/idzebra-abs2dom b/util/idzebra-abs2dom new file mode 100755 index 0000000..464ca98 --- /dev/null +++ b/util/idzebra-abs2dom @@ -0,0 +1,124 @@ +#!/usr/bin/perl -w + +# ---------------------------------------------------------------------------- +# Generate a dom-filter indexing stylesheet based upon an .abs file +# Should be called either this way +# +# idzebra-abs2dom something.abs > something.xsl +# +# or in a streaming way +# +# something | idzebra-abs2dom > something.xsl +# +# The output xslt stylesheet generally needs a little bit of tweaking to be +# ready for indexing. In particular, watch out for the precedence rules of +# xslt templates which work differently from xelm declarations in an .abs file! +# +# Good luck! + +use strict; + +my $marc_prefix = 'marc'; +my $supported_rules = { + + # Supported indexing types: + 'melm' => \&melm_handler, + 'xelm' => sub { return $_[1] }, + + # Declarations to ignore: + 'attset' => 0, + 'encoding' => 0, + 'esetname' => 0, + 'marc' => 0, + 'name' => 0, + 'xpath' => 0 + +}; + +print < + + + + + + + + + + +END_OF_XSLT + + +while (<>) { + my $handler = undef; + + chomp; + s/^\s+//; + s/\s+$//; + next unless length; + next if /^#/; + + my ($rule) = (/^(\S+)/); + + if ( defined $supported_rules->{$rule} ) { + $handler = $supported_rules->{$rule}; + + if ( $handler == 0 ) { + next; + } + } else { + print STDERR "$0: Unsupported indexing rule: '", $rule, "\n\n"; + next; + } + + s/^\Q$rule\E\s+//; + + my ($index) = (/(\S+)$/); + + s/\s+\Q$index\E$//; + + my $match = $_; + my $xpath = $handler->($rule, $match); + my @indexes = split /,/, $index; + + # To avoid screwing up the instruction... + $xpath =~ s/"/'/g; + + print " \n"; + print " \n"; + print " \n"; + print " \n"; + print " \n\n"; +} + +print "\n"; + + +sub melm_handler { + my ($rule, $match) = @_; + my ($field, $subfield) = ($match =~ /([^\$]+)\$?(.*)/); + my $xpath = '/*/'; + + if ( $field =~ /^00/ ) { + $xpath .= $marc_prefix . ':controlfield[@tag=\'' . $field . '\']'; + } else { + $xpath .= $marc_prefix . ':datafield[@tag=\'' . $field . '\']/' . + $marc_prefix . ':subfield'; + + if ( $subfield ne '' ) { + $xpath .= '[@code=\'' . $subfield . '\']'; + } + } + + return $xpath; +} + + +