On the way
[irspy-moved-to-github.git] / zebra / ezeerex2pqfproperties.pl
1 #! /usr/bin/perl -w
2
3 # $Id: ezeerex2pqfproperties.pl,v 1.3 2006-06-19 08:15:37 mike Exp $
4
5 use strict;
6 use warnings;
7 use XML::LibXML;
8 use XML::LibXML::XPathContext;
9
10 my $text = join('', <>);
11 my $parser = new XML::LibXML();
12 my $doc = $parser->parse_string($text);
13 my $root = $doc->getDocumentElement();
14 my $xc = XML::LibXML::XPathContext->new($root);
15 $xc->registerNs(zeerex => 'http://explain.z3950.org/dtd/2.0/');
16
17 print_sets($xc);
18 print_default_set($xc);
19 print_indexes($xc);
20 #print_relations($xc);
21 #print_relation_modifiers($xc);
22 #print_positions($xc);
23 #print_structures($xc);
24 #print_truncations($xc);
25
26 # We could limit the sets output to those that are actually used by an
27 # SRU index: that way we could avoid defining
28 #       set.bib1 = 1.2.840.10003.3.1
29 # which is a Z39.50 attribute set that we don't need for CQL.  But
30 # doing that would be a marginal gain.
31 #
32 sub print_sets {
33     my($xc) = @_;
34
35     my(@nodes) = $xc->findnodes('zeerex:indexInfo/zeerex:set');
36     print "found ", scalar(@nodes), " values\n";
37     foreach my $node (@nodes) {
38         my $name = $node->findvalue('@name');
39         my $identifier = $node->findvalue('@identifier');
40         print "set.$name = $identifier\n";
41     }
42 }
43
44 sub print_default_set {
45     my($xc) = @_;
46
47     my (@nodes) = $xc->findnodes('zeerex:configInfo/' .
48                                  'zeerex:default[@type="contextSet"]');
49     foreach my $node (@nodes) {
50         print "set = ", $node->findvalue('.'), "\n";
51     }
52 }
53
54 sub print_indexes {
55     my($xc) = @_;
56
57     foreach my $node ($xc->findnodes('zeerex:indexInfo/' .
58                                      'zeerex:index[@search="true"]')) {
59         print "node=$node = ", $node->toString(), "\n";
60         foreach my $map ($node->findnodes("zeerex:map")) {
61             print "map=$map = ", $map->toString(), "\n";
62             print("index.", $map->findvalue('@set'),
63                   " = ",  $map->findvalue('.'));
64         }
65     }
66 }