def _initializePOSTables():
global _POSNormalizationTable, _POStoDictionaryTable
_POSNormalizationTable = {}
_POStoDictionaryTable = {}
for pos, abbreviations in (
(NOUN, "noun n n."),
(VERB, "verb v v."),
(ADJECTIVE, "adjective adj adj. a s"),
(ADVERB, "adverb adv adv. r")):
tokens = string.split(abbreviations)
for token in tokens:
_POSNormalizationTable[token] = pos
_POSNormalizationTable[string.upper(token)] = pos
for dict in Dictionaries:
_POSNormalizationTable[dict] = dict.pos
_POStoDictionaryTable[dict.pos] = dict
python类upper()的实例源码
def enrich_nodes(node, function=string.upper,\
target_nodes="//Token", input_attribute="text", \
output_attribute="uppercase_text", overwrite=True, kwargs={}):
"""
Apply function to elements of utt that mathc xpath target_nodes. Input to
the function with be input_attribute, output will be put in output_attribute.
Using the defaults, this should make uppercase copies of tokens [TODO: test this].
"""
nodes = node.xpath(target_nodes)
assert len(nodes) > 0
for node in nodes:
assert node.has_attribute(input_attribute)
if not overwrite:
assert not node.has_attribute(output_attribute),"Cannot overwrite existing '%s' in node "%(output_attribute)
input_data = node.get(input_attribute)
transformed_data = function(input_data, **kwargs)
node.set(output_attribute, transformed_data)
def _initializePOSTables():
global _POSNormalizationTable, _POStoDictionaryTable
_POSNormalizationTable = {}
_POStoDictionaryTable = {}
for pos, abbreviations in (
(NOUN, "noun n n."),
(VERB, "verb v v."),
(ADJECTIVE, "adjective adj adj. a s"),
(ADVERB, "adverb adv adv. r")):
tokens = string.split(abbreviations)
for token in tokens:
_POSNormalizationTable[token] = pos
_POSNormalizationTable[string.upper(token)] = pos
for dict in Dictionaries:
_POSNormalizationTable[dict] = dict.pos
_POStoDictionaryTable[dict.pos] = dict
def _initializePOSTables():
global _POSNormalizationTable, _POStoDictionaryTable
_POSNormalizationTable = {}
_POStoDictionaryTable = {}
for pos, abbreviations in (
(NOUN, "noun n n."),
(VERB, "verb v v."),
(ADJECTIVE, "adjective adj adj. a s"),
(ADVERB, "adverb adv adv. r")):
tokens = string.split(abbreviations)
for token in tokens:
_POSNormalizationTable[token] = pos
_POSNormalizationTable[string.upper(token)] = pos
for dict in Dictionaries:
_POSNormalizationTable[dict] = dict.pos
_POStoDictionaryTable[dict.pos] = dict
def copy(self):
"Copy raster data"
self.load()
im = self.im.copy()
return self._new(im)
##
# Returns a rectangular region from this image. The box is a
# 4-tuple defining the left, upper, right, and lower pixel
# coordinate.
# <p>
# This is a lazy operation. Changes to the source image may or
# may not be reflected in the cropped image. To break the
# connection, call the {@link #Image.load} method on the cropped
# copy.
#
# @param The crop rectangle, as a (left, upper, right, lower)-tuple.
# @return An Image object.
def name_registration_request(self, nbname, destaddr, qtype, scope, nb_flags=0, nb_address='0.0.0.0'):
netbios_name = nbname.upper()
qn_label = encode_name(netbios_name, qtype, scope)
p = NAME_REGISTRATION_REQUEST()
p['NAME_TRN_ID'] = randint(1, 32000)
p['QUESTION_NAME'] = qn_label[:-1]
p['RR_NAME'] = qn_label[:-1]
p['TTL'] = 0xffff
p['NB_FLAGS'] = nb_flags
p['NB_ADDRESS'] = socket.inet_aton(nb_address)
if not destaddr:
p['FLAGS'] |= NM_FLAGS_BROADCAST
destaddr = self.__broadcastaddr
req = p.getData()
res = self.send(p, destaddr, 1)
return res
def name_query_request(self, nbname, destaddr = None, qtype = TYPE_SERVER, scope = None, timeout = 1):
netbios_name = nbname.upper()
qn_label = encode_name(netbios_name, qtype, scope)
p = NAME_QUERY_REQUEST()
p['NAME_TRN_ID'] = randint(1, 32000)
p['QUESTION_NAME'] = qn_label[:-1]
p['FLAGS'] = NM_FLAGS_RD
if not destaddr:
p['FLAGS'] |= NM_FLAGS_BROADCAST
destaddr = self.__broadcastaddr
req = p.getData()
res = self.send(p, destaddr, timeout)
return NBPositiveNameQueryResponse(res['ANSWERS'])
def node_status_request(self, nbname, destaddr, type, scope, timeout):
netbios_name = string.upper(nbname)
qn_label = encode_name(netbios_name, type, scope)
p = NODE_STATUS_REQUEST()
p['NAME_TRN_ID'] = randint(1, 32000)
p['QUESTION_NAME'] = qn_label[:-1]
if not destaddr:
p['FLAGS'] = NM_FLAGS_BROADCAST
destaddr = self.__broadcastaddr
res = self.send(p, destaddr, timeout)
answ = NBNodeStatusResponse(res['ANSWERS'])
self.mac = answ.get_mac()
return answ.entries
################################################################################
# 4.2 SESSION SERVICE PACKETS
################################################################################
def __init__( self, matchString, identChars=DEFAULT_KEYWORD_CHARS, caseless=False ):
super(Keyword,self).__init__()
self.match = matchString
self.matchLen = len(matchString)
try:
self.firstMatchChar = matchString[0]
except IndexError:
warnings.warn("null string passed to Keyword; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.name = '"%s"' % self.match
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = False
#self.myException.msg = self.errmsg
self.mayIndexError = False
self.caseless = caseless
if caseless:
self.caselessmatch = matchString.upper()
identChars = identChars.upper()
self.identChars = _str2dict(identChars)
def parseImpl( self, instring, loc, doActions=True ):
if self.caseless:
if ( (instring[ loc:loc+self.matchLen ].upper() == self.caselessmatch) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen].upper() not in self.identChars) and
(loc == 0 or instring[loc-1].upper() not in self.identChars) ):
return loc+self.matchLen, self.match
else:
if (instring[loc] == self.firstMatchChar and
(self.matchLen==1 or instring.startswith(self.match,loc)) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen] not in self.identChars) and
(loc == 0 or instring[loc-1] not in self.identChars) ):
return loc+self.matchLen, self.match
#~ raise ParseException( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
def copy(self):
"Copy raster data"
self.load()
im = self.im.copy()
return self._new(im)
##
# Returns a rectangular region from this image. The box is a
# 4-tuple defining the left, upper, right, and lower pixel
# coordinate.
# <p>
# This is a lazy operation. Changes to the source image may or
# may not be reflected in the cropped image. To break the
# connection, call the {@link #Image.load} method on the cropped
# copy.
#
# @param The crop rectangle, as a (left, upper, right, lower)-tuple.
# @return An Image object.
def _initializePOSTables():
global _POSNormalizationTable, _POStoDictionaryTable
_POSNormalizationTable = {}
_POStoDictionaryTable = {}
for pos, abbreviations in (
(NOUN, "noun n n."),
(VERB, "verb v v."),
(ADJECTIVE, "adjective adj adj. a s"),
(ADVERB, "adverb adv adv. r")):
tokens = string.split(abbreviations)
for token in tokens:
_POSNormalizationTable[token] = pos
_POSNormalizationTable[string.upper(token)] = pos
for dict in Dictionaries:
_POSNormalizationTable[dict] = dict.pos
_POStoDictionaryTable[dict.pos] = dict
def _initializePOSTables():
global _POSNormalizationTable, _POStoDictionaryTable
_POSNormalizationTable = {}
_POStoDictionaryTable = {}
for pos, abbreviations in (
(NOUN, "noun n n."),
(VERB, "verb v v."),
(ADJECTIVE, "adjective adj adj. a s"),
(ADVERB, "adverb adv adv. r")):
tokens = string.split(abbreviations)
for token in tokens:
_POSNormalizationTable[token] = pos
_POSNormalizationTable[string.upper(token)] = pos
for dict in Dictionaries:
_POSNormalizationTable[dict] = dict.pos
_POStoDictionaryTable[dict.pos] = dict
def __init__(self, sequence, **kwargs):
SeqRecord.__init__(self, sequence, **kwargs)
sequence = upper(sequence)
g_count = sequence.count('G')
c_count = sequence.count('C')
# make GC content as a percent
content = sum([g_count, c_count]) / float(len(sequence))
content = content * 100
self.gc_content = round(content, 0)
# set the start stop in parent seq
self.start = int(kwargs.get('id', -1))
self.stop = self.start + len(sequence) - 1
# set up score
self.score = -1
self.genes = []
def _process_subject(self, input, output, indent=0):
# trace = sys.stdout
while not input.eof():
tag = input.peek()
if tag[1] == ASN1.TypePrimitive:
tag, value = input.read()
if tag[0] == ASN1.PrintableString:
value = string.upper(value)
output.write(value, tag[0], tag[1], tag[2])
#trace.write(' ' * indent)
#trace.write('[%s] %s (value %s)' %
# (strclass(tag[2]), strid(tag[0]), repr(value)))
#trace.write('\n')
elif tag[1] == ASN1.TypeConstructed:
#trace.write(' ' * indent)
#trace.write('[%s] %s:\n' % (strclass(tag[2]), strid(tag[0])))
input.enter()
output.enter(tag[0], tag[2])
self._process_subject(input, output, indent+2)
output.leave()
input.leave()
#----------------------------------------------------------------------
# IOS TrustStore.sqlite3 handling
#----------------------------------------------------------------------
def copy(self):
"Copy raster data"
self.load()
im = self.im.copy()
return self._new(im)
##
# Returns a rectangular region from this image. The box is a
# 4-tuple defining the left, upper, right, and lower pixel
# coordinate.
# <p>
# This is a lazy operation. Changes to the source image may or
# may not be reflected in the cropped image. To break the
# connection, call the {@link #Image.load} method on the cropped
# copy.
#
# @param The crop rectangle, as a (left, upper, right, lower)-tuple.
# @return An Image object.
def cmdln():
"""Setup command line parser.
"""
cmdln = optparse.OptionParser(usage=USAGE, description=DESCR)
cmdln.add_option('-r', dest='recurse', action='store_true',
help='Recurse into subdirs')
cmdln.add_option('-s', dest='silent', action='store_true',
help='Silent mode')
cmdln.add_option('-n', dest='dryrun', action='store_true',
help='dry run/No-op mode (don\'t actually rename)')
cmdln.add_option('-L', dest='lower', action='store_true',
help='make Lower case (string.lower)')
cmdln.add_option('-U', dest='upper', action='store_true',
help='make Upper case (string.upper)')
cmdln.add_option('-C', dest='capwords', action='store_true',
help='Capitalize words (string.capwords)')
cmdln.add_option('-f', dest='fromchars', default='',
help='translate From FROMCHARS characters (requires -t)')
cmdln.add_option('-t', dest='tochars', default='',
help='translate To TOCHARS characters (requires -f)')
cmdln.add_option('-d', dest='delchars', default='',
help='Delete DELCHARS characters from file names')
cmdln.add_option('-l', dest='limitglob', default='*',
help='Limit file globbing to LIMITGLOB pattern')
opts, args = cmdln.parse_args(sys.argv[1:])
opts.stringfunc = lambda x: x
if opts.capwords: opts.stringfunc = string.capwords
if opts.upper: opts.stringfunc = string.upper
if opts.lower: opts.stringfunc = string.lower
error_checks(cmdln, args, opts)
return opts, args[0]
def upcase(s):
return string.upper(s)