Best Python code snippet using slash
test-tokenize.py
Source:test-tokenize.py
1#!/usr/bin/env python 2# -*- coding: utf-8 -*-3# ==============================================================================4# \file test-tokenize.py5# \author chenghuige 6# \date 2018-02-14 23:49:07.8156327# \Description 8# ==============================================================================9 10from __future__ import absolute_import11from __future__ import division12from __future__ import print_function13import sys, os14import tokenizer 15import gezi16def tokenize(text):17 print(text)18 results = tokenizer.tokenize(text, True)19 print(results)20 #results = tokenizer.full_tokenize(text)21 #print(results)22 #print(list(zip(results.tokens, results.poses, results.tags, results.ners)))23 #print(len(results))24tokenize('motherfuck')25# TODO fuck with * edit distance ?26tokenize('fu*k')27tokenize('fc*k')28tokenize('fuck')29tokenize('fu**ck')30tokenize('f**in')31tokenize('f*cked')32tokenize('mother\n\nfuck')33tokenize('SECURITYFUCK')34tokenize('WikiNazis')35tokenize('WikiNazis.')36tokenize('Small|penis/////Small|penis/////')37tokenize('Shut up, sit down. Nig(g)er')38tokenize('you\'re so idi.o.t, so st.u.p.id guy, fu.c.k.i.n.g portuguese, i ha.te the portugueses')39tokenize('''\nOf course a true Dub will say 'depaaarted' or, more likely ""f**in' gone"".''')40tokenize('F u c k i n g c u n t s get a life you sad f u c k i n g gits.')41tokenize('f u c k y o u a s u a r e a b i t c h a s s n i g g e r')42tokenize('T w a t, are you f u c k i n g having a laugh, what kind of thick s h i t, thinks that william shakespeare, my ancestor!, died in. 1616, R.I.P bro,i find that highly rude that you are criticising my ancetors death date......')43tokenize('{{unblock|Please unblock me, my friend was drunk and f*cked up several articles. I would like this account back. Thank you.')44tokenize('chtippDick \n\nYou. You boy. Youuuuuu. Terisoaio! Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah.')45#tokenize('''"== I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f == 46#I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! == August 2010 == I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! == August 2010 == I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel it needs to be corrected. Have a nice day and f u c k o f f ! ! I will edit whatever I want if I feel"47#''')48#49#tokenize('''Request to Unblock50#I began writing the following statement (excepting its two postscripts) before I was blocked. I suspect that User: AuburnPilot had me blocked, in order to prevent me from complaining to administrators about his misconduct. Although I was directed to request an unblock of User: Physicq210, who had blocked me, requesting such of the latter would require that I censor myself, and write as though User: Physicq210 had acted in good faith, and was one of the good guys. That would be surreal, and would give User: Physicq210 a moral legitimacy belied by his actions. And so, the following request for unblocking is directed at any administrator BUT User: Physicq210, but since Iâm not a devious sort, I have nothing against the latter reading this. Indeed, I want User: Physicq210 to read it. For if I can be banned from Wikipedia for standing up to censors, then it is vastly preferable to go down fighting, than to go down the long dark road of self-abnegation and self-censorship, including the use of bad English. After all, if I wanted to be a lackey, I could go to graduate school.51#52#WIKI Administratorsâ Notice Board Incidents53#http://en.wikipedia.org/wiki/Wikipedia:Administrators%27_noticeboard/Incidents54#55#User: AuburnPilot56#57#A few days ago, User: AuburnPilot began stalking me, checking wherever I had made edits, and going to the articles in question and vandalizing them. He or she has been manipulating Wikipedia rules as cover for what is clearly political censorship. User: AuburnPilot cannot even stand for Wikipedia readers to find out about factual material that upsets his political applecart through footnotes. Zero tolerance!58#59#He claims of any source he politically dislikes, that it is either âspamâ or a âblogâ (or âPOV,â another favorite dodge for those at Wikipedia seeking to censor those who fail to conform to their own POV), even though the one source is a previously published, classic magazine article otherwise unavailable on the Web (http://geocities.com/nstix/waronpolice.html), which the author has seen fit to publish on his Web site, and the other source is the longest, most thorough exposé yet published on the Duke rape hoax (http://vdare.com/stix/070113_duke.htm).60#61#Note that I am not even talking about censoring writing within articles, since I hadnât done any writing on the articles in question: Crystal Gail Mangum, Michael Nifong, 2006 Duke University lacrosse team scandal and Racial profiling.62#Iâve been involved in edit wars before, though I have never been the aggressor, and have never initiated an elective edit war, though given the self-assurance that aggressors such as User: AuburnPilot exude, perhaps I ought to reconsider that position. It seems that aggressors rule here.63#64#The reason I am making a formal complaint is that User: AuburnPilot has tonight upped the ante, threatening to have me banned65#(http://en.wikipedia.org/w/index.php?title=User_talk:70.23.199.239&redirect;=no), if I do not surrender to his censorship. Should you find for me, please serve this individual with the wikiquivalent of a cease-and-desist order. Should you, however, find for the censor, please provide an Index of banned publications and a list of official wikicensors.66#67#P.S. January 19, 2007 115A EST. Since beginning this complaint, I see that User: AuburnPilot has in fact succeeded at getting a crony, User: Physicq210, to block me, thus not only getting administrative support in censoring me, but preventing me from responding to his thuggery. (And no, I am not going to use cutesy, euphemistic language. If I were into such deception, I would have become a liar, er, lawyer, and would be worthless as an encyclopedist.) And I was unable to e-mail User: Physicq210 because I am not logged in and âYou must be logged in and have a valid authenticated e-mail address in your preferences to send e-mail to other users.â (http://en.wikipedia.org/wiki/Special:Emailuser/Physicq210)68#69#If this isnât cyber-Stalinism, I donât know what is! So, let me get this straight. Stalking and censoring an editor while using the equivalent of smiley faces (User: AuburnPilotâs penchant for saying âThank youâ after vandalizing oneâs links) is âcivil,â but complaining about such abuse counts as âspam, disruption, incivility, and personal attacks.â If that is verily so, then 2 + 2 = 5.70#71#72#P.P.S The message here says that I was âtemporarily blocked from editing Wikipedia as a result of your disruptive edits.â What the heck is that supposed to mean? For restoring footnotes and links that User: AuburnPilot had vandalized? If that constitutes âdisruptive edits,â then youâve utterly given up on honest English and all human decency. Sorry, but I donât have any sympathy for the Devil.''')73tokenize('''I don't want''')74tokenize('''I DON'T want''')75tokenize('''i'm''')76tokenize('''I'm''')77tokenize('''I'M''')78tokenize('''You're bitch''')79print(tokenizer.has('''DONT'T'''))80print(tokenizer.has('''don't'''))81print(tokenizer.has('''i'm'''))82print(tokenizer.has('''I'm'''))83print(tokenizer.has('''I'M'''))84tokenize('he INSISTS upon keeping Boston(as the center of the world. Clearly biased) in no matter what')85print(gezi.segment.tokenize_filter_empty('he INSISTS upon keeping Boston(as the center of the world. Clearly biased) in no matter what'))86tokenize('''19 August 2011 (UTC)\nLook who is talking. Legilas is the user who's got Autopatrolled rights although he has 16 articles on the list.''')87tokenize('Hi\n\nwhy did you give User:Barneca a kindness star.')88tokenize('proud to be indonesial')89tokenize('SECURITYFUCK dimension dimenison really fuck you')90tokenize('Uh I hate to break it to you but Jusdafax is not an administrator')91tokenize('I love beijing university. Mike is a Chinese boy. You are a ditry Frenchman')...
maslow.py
Source:maslow.py
...217 raise IndexError218 def __len__(self):219 '''Returns the number of needs registered.'''220 return len(self.needs)221 def clean_needs(self):222 '''Removes needs from the need list that have no update_function223 This speeds up searches, updates, and clears memory. Needs such224 as this may enter the needs list upon initialization.225 '''226 new_needs = []227 for n in self.needs:228 if hasattr(n.update_function, '__call__'):229 new_needs.append(n)230 self.needs = new_needs231 def update_needs(self):232 '''Updates the value of all needs by having each call its233 update_function.'''234 for n in self.needs:235 n.update()236 def most_urgent(self, threshold=80, update=True):237 '''Gets the most urgent need from the lowest possible need238 level that breaches the threshold. Return None if there are239 no breaches.240 If the threshold is None, just return the Need with the highest241 value.242 Paramaters:243 threshold -- The number the need's value must be over to consider244 returning the need. (int/None)245 Default: 80246 update -- Should the needs be updated before calling? (boolean)247 Default: True248 '''249 #Update needs if desired250 if update:251 self.update_needs()252 #If threshhold is none return need with highest value (last).253 if not threshold:254 return sorted(self.needs, key=lambda i:i.value)[-1]255 #Get all needs over threshold.256 over = []257 for n in self.needs:258 if n.value > threshold:259 over.append(n)260 #Sort so the most important is first261 try:262 return sorted(over, key=lambda i:i.sortvalue())[0]263 except IndexError:264 return None265if __name__ == "__main__":266 h = Heirarchy(LOVE)267 for n in h.needs:268 print n269 print h.most_urgent()270 #Test needs cleaning271 def friend():272 return 81273 def food():274 return 81275 h['friendship'].update_function = friend276 h['food'].update_function = food277 h.clean_needs()278 #Test urgency rating...
maslow.py.svn-base
Source:maslow.py.svn-base
...217 raise IndexError218 def __len__(self):219 '''Returns the number of needs registered.'''220 return len(self.needs)221 def clean_needs(self):222 '''Removes needs from the need list that have no update_function223 This speeds up searches, updates, and clears memory. Needs such224 as this may enter the needs list upon initialization.225 '''226 new_needs = []227 for n in self.needs:228 if hasattr(n.update_function, '__call__'):229 new_needs.append(n)230 self.needs = new_needs231 def update_needs(self):232 '''Updates the value of all needs by having each call its233 update_function.'''234 for n in self.needs:235 n.update()236 def most_urgent(self, threshold=80, update=True):237 '''Gets the most urgent need from the lowest possible need238 level that breaches the threshold. Return None if there are239 no breaches.240 If the threshold is None, just return the Need with the highest241 value.242 Paramaters:243 threshold -- The number the need's value must be over to consider244 returning the need. (int/None)245 Default: 80246 update -- Should the needs be updated before calling? (boolean)247 Default: True248 '''249 #Update needs if desired250 if update:251 self.update_needs()252 #If threshhold is none return need with highest value (last).253 if not threshold:254 return sorted(self.needs, key=lambda i:i.value)[-1]255 #Get all needs over threshold.256 over = []257 for n in self.needs:258 if n.value > threshold:259 over.append(n)260 #Sort so the most important is first261 try:262 return sorted(over, key=lambda i:i.sortvalue())[0]263 except IndexError:264 return None265if __name__ == "__main__":266 h = Heirarchy(LOVE)267 for n in h.needs:268 print n269 print h.most_urgent()270 #Test needs cleaning271 def friend():272 return 81273 def food():274 return 81275 h['friendship'].update_function = friend276 h['food'].update_function = food277 h.clean_needs()278 #Test urgency rating...
ChiggerObject.py
Source:ChiggerObject.py
1#pylint: disable=missing-docstring2#* This file is part of the MOOSE framework3#* https://www.mooseframework.org4#*5#* All rights reserved, see COPYRIGHT for full restrictions6#* https://github.com/idaholab/moose/blob/master/COPYRIGHT7#*8#* Licensed under LGPL 2.1, please see LICENSE for details9#* https://www.gnu.org/licenses/lgpl-2.1.html10import mooseutils11from .. import utils12class ChiggerObject(object):13 """14 Base for all user-facing object in chigger.15 The primary purpose is to provide a method for getting key, value16 options and consistent update methods.17 """18 @staticmethod19 def getOptions():20 """21 All object should define a static getOptions method to add new key, value options. (public)22 """23 opt = utils.Options()24 opt.add('debug', False, "Enable/disable debug messaging.")25 return opt26 def __init__(self, **kwargs):27 super(ChiggerObject, self).__init__()28 self._options = getattr(self.__class__, 'getOptions')()29 self.__initial_options = kwargs30 self.__needs_initialize = True31 self.__needs_update = True32 def options(self):33 """34 Return the utils.Options object for this class.35 """36 return self._options37 def needsUpdate(self):38 """39 Return True if the object requires an Update method call. (public)40 """41 mooseutils.mooseDebug("{}.needsUpdate() = {}".format(self.__class__.__name__,42 self.__needs_update))43 return self.__needs_update44 def needsInitialize(self):45 """46 Return True if the object requires an _initialize method call. (public)47 """48 mooseutils.mooseDebug("{}.needsInitialize() = {}".format(self.__class__.__name__,49 self.__needs_initialize))50 return self.__needs_initialize51 def update(self, initialize=True, **kwargs):52 """53 Update method should contain calls to underlying vtk objects. (public)54 Inputs:55 initialize[bool]: When True the initialize() method will be called, but only if needed.56 """57 if self.__needs_initialize and initialize:58 self.initialize()59 mooseutils.mooseDebug("{}.update()".format(self.__class__.__name__))60 self.setOptions(**kwargs)61 self.setNeedsUpdate(False)62 def isOptionValid(self, name):63 """64 Test if the given option is valid (i.e., not None). (public)65 """66 return self._options.isOptionValid(name)67 def getOption(self, name):68 """69 Return the value of an option. (public)70 Inputs:71 name[str]: The name of the option to retrieve72 """73 return self._options[name]74 def setOption(self, name, value):75 """76 Set single option. (public)77 Inputs:78 name[str]: The name of the option to retrieve79 value: The value to set the option to80 """81 changed = (self._options[name] != value)82 if changed:83 self._options[name] = value84 self.setNeedsUpdate(True)85 def setOptions(self, *args, **kwargs):86 """87 A method for setting/updating an objects options. (public)88 Usage:89 setOptions(sub0, sub1, ..., key0=value0, key1=value1, ...)90 Updates all suboptions with the provided key value pairs91 setOptions(key0=value0, key1=value1, ...)92 Updates the main options with the provided key,value pairs93 """94 # Sub-options case95 changed = [self.needsUpdate()] # default changed status to the current status96 if len(args) > 0:97 for sub in args:98 if (self._options.hasOption(sub)) and isinstance(self.getOption(sub),99 utils.Options):100 changed.append(self._options[sub].update(**kwargs))101 elif isinstance(sub, utils.Options):102 changed.append(self._options.update(sub))103 # Main options case104 else:105 changed.append(self._options.update(**kwargs))106 changed = any(changed)107 self.setNeedsUpdate(changed)108 return changed109 def updateOptions(self, *args):110 """111 Apply the supplied option objects to this object and the contained ChiggerFilterSourceBase112 objects. (override)113 Inputs:114 see ChiggerResultBase115 """116 changed = [self.needsUpdate()]117 for sub in args:118 changed.append(self._options.update(sub))119 changed = any(changed)120 self.setNeedsUpdate(changed)121 return changed122 def reset(self):123 """124 Reset initialization flag, so the _initialize method will be called again on next update.125 """126 self.__needs_initialize = True127 def initialize(self):128 """129 Initialize method that runs once when update() is first called. (protected)130 """131 mooseutils.mooseDebug("{}.initialize()".format(self.__class__.__name__))132 self.__needs_initialize = False133 self._setInitialOptions()134 def _setInitialOptions(self):135 """136 Method for applying the options passed to constructor, this is called by the137 initialize() method automatically.138 """139 if self.__initial_options:140 self.setOptions(**self.__initial_options)141 self.__initial_options = None142 def setNeedsUpdate(self, value):143 """144 Set the value of the need update flag. (protected)145 Inputs:146 value[bool]: The value for the update flag.147 """148 mooseutils.mooseDebug("{}.setNeedsUpdate({})".format(self.__class__.__name__, value))149 self.__needs_update = value150 def _setNeedsInitialize(self, value):151 """152 Set the initialize flag for the _initialize method. (protected)153 """154 mooseutils.mooseDebug("{}._setNeedsInitialize({})".format(self.__class__.__name__, value))155 self.__needs_initialize = value156 def checkUpdateState(self):157 """158 Checks if the object needs update and performs updated, if needed.159 """160 if self.needsUpdate():...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!