def top_set(self): if (self.nextToken == '@attrset'): self.fetch_token() self.fetch_token() n = self.currentToken.upper() if (n[:14] == "1.2.840.10003."): return asn1.OidVal(map(int, n.split('.'))) return oids.oids['Z3950']['ATTRS'][n]['oid'] else: return None
def attrset_to_oid (attrset): l = attrset.lower () if _attrdict.has_key (l): return _attrdict [l] split_l = l.split ('.') if split_l[0] == '': split_l = oids.Z3950_ATTRS + split_l[1:] try: intlist = map (string.atoi, split_l) except(ValueError): raise ParseError ('Bad OID: ' + l) return asn1.OidVal (intlist)
def attr_spec(self): # @attr is CT self.fetch_token() if (self.currentToken.find('=') == -1): # attrset set = self.currentToken if (set[:14] == "1.2.840.10003."): set = asn1.OidVal(map(int, set.split('.'))) else: set = oids.oids['Z3950']['ATTRS'][set.upper()]['oid'] self.fetch_token() else: set = None # May raise (atype, val) = self.currentToken.split('=') if (not atype.isdigit()): raise ValueError atype = int(atype) if (val.isdigit()): val = int(val) return (set, atype, val)
def toRPN(self, top): self.resolvePrefix() pf = self.prefix if (not pf and self.prefixURI): # We have a default for k in zConfig.contextSets: if zConfig.contextSets[k] == self.prefixURI: pf = k break # Default BIB1 set = oids.oids['Z3950']['ATTRS']['BIB1']['oid'] if (hasattr(top, 'config') and top.config): config = top.config # Check SRW Configuration cql = config.contextSetNamespaces['cql'] index = self.value if self.prefixURI == cql and self.value == "serverchoice": # Have to resolve our prefixes etc, so create an index object to do it index = config.defaultIndex cidx = CIndex(index) cidx.config = config cidx.parent = config cidx.resolvePrefix() pf = cidx.prefix index = cidx.value if config.indexHash.has_key(pf): if config.indexHash[pf].has_key(index): idx = config.indexHash[pf][index] # Need to map from this list to RPN list attrs = {} for i in idx: set = asn1.OidVal(map(int, i[0].split('.'))) type = int(i[1]) if (i[2].isdigit()): val = int(i[2]) else: val = i[2] attrs[(set, type)] = val return attrs else: diag = Diagnostic16() diag.details = index diag.message = "Unknown index" raise diag else: diag = Diagnostic15() diag.details = pf diag.message = "Unknown context set" raise diag elif (hasattr(zConfig, pf)): mp = getattr(zConfig, pf) if (mp.has_key(self.value)): val = mp[self.value] else: val = self.value elif (oids.oids['Z3950']['ATTRS'].has_key(pf.upper())): set = oids.oids['Z3950']['ATTRS'][pf.upper()]['oid'] if (self.value.isdigit()): # bib1.1018 val = int(self.value) else: # complex attribute for bib1 val = self.value else: print "Can't resolve %s" % pf raise (ValueError) return {(set, 1): val}
number = flds[1] if (len(flds) > 2): aliasList = flds[2:] else: aliasList = [] if (number[0] == "."): # add to previous splitname = name.split("_") cur = oids for n in splitname[:-1]: cur = cur[n] val = cur['val'] + [int(number[1:])] oid = asn1.OidVal(val) cur[splitname[-1]] = {'oid': oid, 'val': val} vars[name] = val tree = "oids['%s']" % "']['".join(splitname) outh.write(tree + " = " + "{'oid': asn1.OidVal(" + str(val) + "), 'val': " + str(val) + "}\n") else: # base splitnums = number.split('.') numlist = map(int, splitnums) oids[name] = {} oids[name]['oid'] = asn1.OidVal(numlist)
def attrsToCql(self, attrs): # Pull defaults off of self bib1 = z3950.Z3950_ATTRS_BIB1_ov #bib1str = '.'.join(map(str, bib1.lst)) bib1str = '.'.join([str(x) for x in bib1.lst]) xd1 = z3950.Z3950_ATTRS_XD1_ov # xd1str = '.'.join(map(str, xd1.lst)) xd1 = '.'.join([str(x) for x in xd1.lst]) attrHash = {} for c in attrs: if (not c[0]): # c[0] = asn1.OidVal(map(int, self.defaultAttributeSet.split('.'))) c[0] = asn1.OidVal( [int(x) for x in self.defaultAttributeSet.split('.')]) attrHash[(c[0], c[1])] = c[2] # First check bib1 defaultAttribs = self.defaultAttributeHash use = attrHash.get((bib1, 1)) rel = attrHash.get((bib1, 2), 3) posn = attrHash.get((bib1, 3), None) struct = attrHash.get((bib1, 4), None) trunc = attrHash.get((bib1, 5), None) comp = attrHash.get((bib1, 6), None) defaultPosn = self.defaultAttributeHash.get((bib1str, 3), None) defaultStruct = self.defaultAttributeHash.get((bib1str, 4), None) defaultTrunc = self.defaultAttributeHash.get((bib1str, 5), None) defaultComp = self.defaultAttributeHash.get((bib1str, 6), None) if use: if not isinstance(use, int) and use[:3] == "c3.": # Override, just grab index, if exists idx = self.parent.get_object(None, use[3:]) if not idx: raise ValueError(use) indexStr = use else: try: use = use.lower() except: pass info = self.indexHash.get(((bib1str, 1, use), ), None) if info: # list of possible indexes. possibleIndexes = [] for idx in info: if posn and (not (bib1str, 3, posn) in idx[0]): continue if not posn and defaultPosn and ( not (bib1str, 3, defaultPosn) in idx[0]): continue if struct and (not (bib1str, 4, struct) in idx[0]): continue if not struct and defaultStruct and ( not (bib1str, 4, defaultStruct) in idx[0]): continue if trunc and (not (bib1str, 5, trunc) in idx[0]): continue if not trunc and defaultTrunc and ( not (bib1str, 5, defaultTrunc) in idx[0]): continue if comp and (not (bib1str, 6, comp) in idx[0]): continue if not comp and defaultComp and ( not (bib1str, 6, defaultComp) in idx[0]): continue possibleIndexes.append([idx[1], idx[0][:4]]) if not possibleIndexes: # No match raise ValueError("No matching index") else: # If >1 take first indexInfo = possibleIndexes[0] index = indexInfo[0] # Assgn to struct etc. if not posn: posn = indexInfo[1][0][2] if not struct: struct = indexInfo[1][1][2] if not trunc: trunc = indexInfo[1][2][2] if not comp: comp = indexInfo[1][3][2] indexStr = "c3.%s" % index.id else: raise ValueError("No matching index??") index = indexType(indexStr) relations = ['', '<', '<=', '=', '>=', '>', '<>'] if (comp == 3): relation = relationType("exact") elif (rel > 6): if struct in [2, 6]: relation = relationType('any') elif (rel in [500, 501, 510, 530, 540]): relation = relationType('all') else: relation = relationType('=') else: relation = relationType(relations[rel]) if (rel == 100): relation.modifiers.append(modifierClauseType('phonetic')) elif (rel == 101): relation.modifiers.append(modifierClauseType('stem')) elif (rel == 102): relation.modifiers.append(modifierClauseType('relevant')) elif (rel == 500): relation.modifiers.append( modifierClauseType('rel.algorithm', '=', 'okapi')) elif (rel == 501): relation.modifiers.append( modifierClauseType('rel.algorithm', '=', 'cori')) elif (rel == 510): relation.modifiers.append( modifierClauseType('rel.algorithm', '=', 'trec2')) elif (rel == 530): relation.modifiers.append( modifierClauseType('rel.algorithm', '=', 'tfidf')) elif (rel == 540): relation.modifiers.append( modifierClauseType('rel.algorithm', '=', 'tfidflucene')) if (struct in [2, 6]): relation.modifiers.append(modifierClauseType('word')) elif (struct in [4, 5, 100]): relation.modifiers.append(modifierClauseType('date')) elif (struct == 109): relation.modifiers.append(modifierClauseType('number')) elif (struct in [1, 108]): relation.modifiers.append(modifierClauseType('string')) elif (struct == 104): relation.modifiers.append(modifierClauseType('uri')) return (index, relation)
from PyZ3950 import asn1 oids = {} oids['Z3950'] = { 'oid': asn1.OidVal([1, 2, 840, 10003]), 'val': [1, 2, 840, 10003] } oids['Z3950']['ATTRS'] = { 'oid': asn1.OidVal([1, 2, 840, 10003, 3]), 'val': [1, 2, 840, 10003, 3] } oids['Z3950']['DIAG'] = { 'oid': asn1.OidVal([1, 2, 840, 10003, 4]), 'val': [1, 2, 840, 10003, 4] } oids['Z3950']['RECSYN'] = { 'oid': asn1.OidVal([1, 2, 840, 10003, 5]), 'val': [1, 2, 840, 10003, 5] } oids['Z3950']['TRANSFER'] = { 'oid': asn1.OidVal([1, 2, 840, 10003, 6]), 'val': [1, 2, 840, 10003, 6] } oids['Z3950']['RRF'] = { 'oid': asn1.OidVal([1, 2, 840, 10003, 7]), 'val': [1, 2, 840, 10003, 7] } oids['Z3950']['ACCESS'] = { 'oid': asn1.OidVal([1, 2, 840, 10003, 8]), 'val': [1, 2, 840, 10003, 8] } oids['Z3950']['ES'] = {