Comment on what remains to be done
[irspy-moved-to-github.git] / zebra / ezeerex2pqfproperties.pl
1 #! /usr/bin/perl -w
2
3 # $Id: ezeerex2pqfproperties.pl,v 1.5 2006-06-19 16:45:18 mike Exp $
4 #
5 # Run like this:
6 #       ./ezeerex2pqfproperties.pl zeerex.xml
7
8 use strict;
9 use warnings;
10 use XML::LibXML;
11 use XML::LibXML::XPathContext;
12
13 my $text = join('', <>);
14 my $parser = new XML::LibXML();
15 my $doc = $parser->parse_string($text);
16 my $root = $doc->getDocumentElement();
17 my $xc = XML::LibXML::XPathContext->new($root);
18 $xc->registerNs(z => 'http://explain.z3950.org/dtd/2.0/');
19
20 print_sets($xc);
21 print_default_set($xc);
22 print_indexes($xc);
23 print_relations($xc);
24 print_relation_modifiers($xc);
25 print_positions($xc);
26 print_structures($xc);
27 print_truncations($xc);
28
29 # We could limit the sets output to those that are actually used by an
30 # SRU index: that way we could avoid defining
31 #       set.bib1 = 1.2.840.10003.3.1
32 # which is a Z39.50 attribute set that we don't need for CQL.  But
33 # doing that would be a marginal gain.
34 #
35 sub print_sets {
36     my($xc) = @_;
37
38     my(@nodes) = $xc->findnodes('z:indexInfo/z:set');
39     foreach my $node (@nodes) {
40         my $name = $node->findvalue('@name');
41         my $identifier = $node->findvalue('@identifier');
42         print "set.$name = $identifier\n";
43     }
44 }
45
46 sub print_default_set {
47     my($xc) = @_;
48
49     my (@nodes) = $xc->findnodes('z:configInfo/' .
50                                  'z:default[@type="contextSet"]');
51     foreach my $node (@nodes) {
52         ### Look this up and render as a URI
53         print "set = ", $node->findvalue('.'), "\n";
54     }
55 }
56
57 sub print_indexes {
58     my($xc) = @_;
59
60     foreach my $node ($xc->findnodes('z:indexInfo/' .
61                                      'z:index[@search="true"]')) {
62         my @pqf = $xc->findnodes("z:map/z:attr", $node);
63         die("no PQF mapping for index '" .
64             $xc->findvalue("z:title", $node) . "'")
65             if @pqf == 0;
66         my $ptype = $xc->findvalue('@type', $pqf[0]);
67         my $pval = $xc->findvalue(".", $pqf[0]);
68
69         foreach my $map ($xc->findnodes("z:map", $node)) {
70             my $setname = $xc->findvalue('z:name/@set', $map);
71             my $indexname = $xc->findvalue('z:name', $map);
72             ### We need a way for the ZeeRex record to specify other
73             #   attributes to be specified along with the access-point,
74             #   e.g. @attr 4=3 for whole-field indexes.
75             print "index.$setname.$indexname = $ptype=$pval\n"
76                 if $indexname ne "";
77         }
78     }
79 }
80
81 # I don't think these are affected by the ZeeRex record
82 sub print_relations {
83     my($xc) = @_;
84
85     print <<__EOT__;
86 relation.< = 2=1
87 relation.le = 2=2
88 relation.eq = 2=3
89 relation.exact = 2=3
90 relation.ge = 2=4
91 relation.> = 2=5
92 relation.<> = 2=6
93 relation.scr = 2=3
94 __EOT__
95 }
96
97 # I don't think these are affected by the ZeeRex record
98 sub print_relation_modifiers {
99     my($xc) = @_;
100
101     print <<__EOT__;
102 relationModifier.relevant = 2=102
103 relationModifier.fuzzy = 5=103
104 relationModifier.stem = 2=101
105 relationModifier.phonetic = 2=100
106 relationModifier.regexp = 5=102
107 __EOT__
108 }
109
110 # I don't think these are affected by the ZeeRex record
111 sub print_positions {
112     my($xc) = @_;
113
114     print <<__EOT__;
115 position.first = 3=1 6=1
116 position.any = 3=3 6=1
117 position.last = 3=4 6=1
118 position.firstAndLast = 3=3 6=3
119 __EOT__
120 }
121
122 # I don't think these are affected by the ZeeRex record
123 sub print_structures {
124     my($xc) = @_;
125
126     print <<__EOT__;
127 structure.exact = 4=108
128 structure.all = 4=2
129 structure.any = 4=2
130 structure.* = 4=1
131 __EOT__
132 }
133
134 # I don't think these are affected by the ZeeRex record
135 sub print_truncations {
136     my($xc) = @_;
137
138     print <<__EOT__;
139 truncation.right = 5=1
140 truncation.left = 5=2
141 truncation.both = 5=3
142 truncation.none = 5=100
143 truncation.regexp = 5=102
144 truncation.z3958 = 5=104
145 __EOT__
146 }