How to use es method in localstack

Best Python code snippet using localstack_python

test_es.py

Source:test_es.py Github

copy

Full Screen

...154 u'sea', u'seas', u'seamos', u'seáis', u'sean', 155 u'fuera', u'fueras', u'fuéramos', u'fuerais', u'fueran'156 ])157 print "pattern.es.inflect.lexeme()"158 def test_tenses(self):159 # Assert tense recognition.160 self.assertTrue((es.PRESENT, 3, es.SG) in es.tenses("es"))161 self.assertTrue("2sg" in es.tenses("eres"))162 # The CONDITIONAL is sometimes described as a mood, 163 # and sometimes as a tense of the indicative mood (e.g., in Spanish):164 t1 = (es.CONDITIONAL, 1, es.SG)165 t2 = (es.PRESENT, 1, es.SG, es.CONDITIONAL)166 self.assertTrue("1sg->" in es.tenses(u"sería"))167 self.assertTrue(t1 in es.tenses(u"sería"))168 self.assertTrue(t2 in es.tenses(u"sería"))169 self.assertTrue(t1 in es.tenses(es.conjugate("ser", mood=es.INDICATIVE, tense=es.CONDITIONAL)))170 self.assertTrue(t2 in es.tenses(es.conjugate("ser", mood=es.CONDITIONAL)))171 print "pattern.es.tenses()"172#---------------------------------------------------------------------------------------------------173class TestParser(unittest.TestCase):174 175 def setUp(self):176 pass177 178 def test_find_lemmata(self):179 # Assert lemmata for nouns, adjectives, verbs and determiners.180 v = es.parser.find_lemmata([181 ["Los", "DT"], ["gatos", "NNS"], [u"negros", "JJ"], ["se", "PRP"], [u"sentó", "VB"],182 ["en", "IN"], ["la", "DT"], ["alfombra", "NN"]])183 self.assertEqual(v, [184 ["Los", "DT", "el"], 185 ["gatos", "NNS", "gato"], 186 ["negros", "JJ", "negro"], 187 ["se", "PRP", "se"], 188 [u"sentó", "VB", "sentar"],189 ["en", "IN", "en"], 190 ["la", "DT", "el"], 191 ["alfombra", "NN", "alfombra"]])192 print "pattern.es.parser.find_lemmata()"193 def test_parse(self):194 # Assert parsed output with Penn Treebank II tags (slash-formatted).195 # "el gato negro" is a noun phrase, "en la alfombra" is a prepositional noun phrase.196 v = es.parser.parse(u"El gato negro se sentó en la alfombra.")197 self.assertEqual(v, # XXX - shouldn't "se" be part of the verb phrase?198 u"El/DT/B-NP/O gato/NN/I-NP/O negro/JJ/I-NP/O " + \199 u"se/PRP/B-NP/O sentó/VB/B-VP/O " + \200 u"en/IN/B-PP/B-PNP la/DT/B-NP/I-PNP alfombra/NN/I-NP/I-PNP ././O/O"201 )202 # Assert the accuracy of the Spanish tagger.203 i, n = 0, 0204 for sentence in open(os.path.join(PATH, "corpora", "tagged-es-wikicorpus.txt")).readlines():205 sentence = sentence.decode("utf-8").strip()206 s1 = [w.split("/") for w in sentence.split(" ")]207 s2 = [[w for w, pos in s1]]208 s2 = es.parse(s2, tokenize=False, tagset=es.PAROLE)209 s2 = [w.split("/") for w in s2.split(" ")]210 for j in range(len(s1)):211 if s1[j][1] == s2[j][1]:212 i += 1213 n += 1214 #print float(i) / n215 self.assertTrue(float(i) / n > 0.92)216 print "pattern.es.parser.parse()"217 def test_tag(self):218 # Assert [("el", "DT"), ("gato", "NN"), ("negro", "JJ")]....

Full Screen

Full Screen

easyscan.py_backup

Source:easyscan.py_backup Github

copy

Full Screen

1#!/usr/bin/env python2#########################################################################3"""4 ____ ____ ____ _ _ ____ ____ ____ _ _ _ _ ____ ___5 |___ |__| [__ \_/ [__ | |__| |\ | |__| |___ |__]6 |___ | | ___] | ___] |___ | | | \| | | |___ |7 An Easy-to-use tool providing a comfortable way connecting programs 8 to Scan the parameter space for high energy physics(HEP) models.9 10 Author: Junjie Cao, Liangliang Shang, Jin Min Yang and Yang Zhang11 Version: Beta_1.0.112 Date: 2016.07.2813 """14##########################################################################15## External modules.16import os,sys,math17sys.path.append(os.path.join(os.path.split(os.path.split(os.path.realpath(__file__))[0])[0], "Tools"))18## Internal modules.19import subfun as sf20import manfun as mf21import statfun as stat22import readin23# define basic class object24ES = mf.EasyScanInput()25Programs ={}26CS = mf.constraint()27Ploter = mf.plot()28ProgID = readin.ReadIn(sys.argv[1],ES,Programs,CS,Ploter)29# logarithm of likelihood function30def LogLikelihood(cube, ndim, nparams):31 # pass the input value from cube to InPar32 for i,name in enumerate(ES.InPar) :33 ES.InPar [name]=cube[i]34 ES.AllPar[name]=cube[i]35 # Run each programs36 for ii in ProgID:37 if Programs[ii].getRunFlag(ES.AllPar):38 Programs[ii].WriteInputFile(ES.AllPar)39 Programs[ii].RunProgram()40 Phy = Programs[ii].ReadOutputFile(ES.AllPar,ES.getFileName())41 else:42 Phy = Programs[ii].SetOutput(ES.AllPar)43 # if the point is unphysical, return log(0)44 if not Phy : return sf.log_zero45 # pass the output value to AllPar46 for i,name in enumerate(ES.OutPar) :47 48 #yuanfang49 50 # yy=raw_input('yuanang cube begin....')51 # print 'cube=',cube52 # print 'nparams',nparams53 # print 'enumerate(ES.OutPar)=',ES.OutPar54 # print 'i=',i55 # print 'ndim=',ndim56 # print 'name=',name57 # print 'i+ndim=',i+ndim58 # print 'ES.AllPar[name]=',ES.AllPar[name]59 60# yuanfang modified in 11.661 if ES.getScanMethod() == 'MULTINEST':62 try:63 float(ES.AllPar[name])64 except:65 # yy=raw_input('yuanang cube string exception begin....')66 # print 'i=',i67 # print 'name=',name68 # print 'ES.AllPar[name]=',ES.AllPar[name]69 cube[i+ndim]=0.0 70 # yy=raw_input('yuanang cube string exception end....')71 continue # skip this loop72 cube[i+ndim] = ES.AllPar[name]73 # print(type(ES.AllPar))74 # print(type(ES.AllPar[name]))75 # import ctypes76 # import numpy77 # array_length=378 # buffer=numpy.core.multiarray.int_asbuffer(ctypes.addressof(cube.contents),8*array_length)79 # yuanfang_cube=numpy.frombuffer(buffer,float)80 # print "yuanfang_cube",yuanfang_cube81 # a=raw_input('yuanfang cube end,waiting for the input1...')82 # a=raw_input('yuanfang cube end,waiting for the input2...')83 84 85 return - CS.getChisq(ES.AllPar)/2.086def Prior(cube, ndim, nparams):87 #print "easyscan.py 01llllllllllllllllllllllllllll"88 for i,name in enumerate(ES.InPar):89 if ES.InputPar[name][1].lower() == 'flat':90 min = float(ES.InputPar[name][2])91 max = float(ES.InputPar[name][3])92 cube[i] = cube[i] * (max - min) + min93 #print cube[i]94 elif ES.InputPar[name][1].lower() == 'log':95 min = math.log10(float(ES.InputPar[name][2]))96 max = math.log10(float(ES.InputPar[name][3]))97 cube[i] = 10.0**(cube[i]*(max - min) + min )98 else:99 sf.ErrorStop( 'Not ready. Only "flat" and "log" prior can be used.' )100""" Scan the parameter space """101if ES.getScanMethod() == 'RANDOM':102 from scanmanner import randomrun103 ResultFile = 'RandomData.txt'104 randomrun(105 LogLikelihood = LogLikelihood,106 Prior = Prior,107 n_dims = len(ES.InPar),108 n_params = len(ES.AllPar),109 n_live_points = ES.getPointNum(),110 n_print = ES.getPrintNum(),111 outputfiles_basename = ES.getFileName(),112 outputfiles_filename = ResultFile )113elif ES.getScanMethod() == 'MCMC':114 from scanmanner import mcmcrun115 ResultFile = 'MCMCData.txt'116 mcmcrun(117 LogLikelihood = LogLikelihood,118 Prior = Prior,119 n_dims = len(ES.InPar),120 n_params = len(ES.AllPar),121 n_live_points = ES.getPointNum(),122 inpar = ES.InPar,123 outpar = ES.OutPar,124 StepSize = ES.getStepSize(),125 AccepRate = ES.getAccepRate(),126 FalgTune = ES.getFalgTuneR(),127 InitVal = ES.getInitialValue(),128 n_print = ES.getPrintNum(),129 outputfiles_basename = ES.getFileName(),130 outputfiles_filename = ResultFile)131elif ES.getScanMethod() == 'MULTINEST':132 import pymultinest133 ResultFile = 'MultiNestData/ev.dat'134 pymultinest.run(135 LogLikelihood = LogLikelihood, 136 Prior = Prior,137 n_dims = len(ES.InPar),138 n_params = len(ES.AllPar),139 seed = ES.getRandomSeed(),140 outputfiles_basename = ES.MNOutputFile,141 n_live_points = ES.getPointNum(),142 n_clustering_params = 2,143 wrapped_params = None,144 multimodal = True,145 const_efficiency_mode = False,146 evidence_tolerance = 1.0,147 sampling_efficiency = 2.0,148 n_iter_before_update = 1,149 null_log_evidence = -1e+90,150 max_modes = 5,151 verbose = True,152 resume = False, #!!!!!!!!!153 context = 0,154 importance_nested_sampling = True)155elif ES.getScanMethod() == 'GRID':156 from scanmanner import gridrun157 ResultFile = 'GridData.txt'158 gridrun(159 LogLikelihood = LogLikelihood,160 Prior = Prior,161 n_dims = len(ES.InPar),162 n_params = len(ES.AllPar),163 inpar = ES.InPar,164 bin_num = ES.GridBin,165 n_print = ES.getPrintNum(),166 outputfiles_basename = ES.getFileName(),167 outputfiles_filename = ResultFile )168elif ES.getScanMethod() == 'READ':169 from scanmanner import readrun170 ResultFile = 'READData.txt'171 readrun(172 LogLikelihood = LogLikelihood,173 Prior = Prior,174 n_dims = len(ES.InPar),175 n_params = len(ES.AllPar),176 inpar = ES.InPar,177 bin_num = ES.GridBin,178 n_print = ES.getPrintNum(),179 outputfiles_basename = ES.getFileName(),180 outputfiles_filename = ResultFile )181""" After programs run """182if ES.getScanMethod() != 'PLOT':183 for ii in Programs: Programs[ii].Recover()184 sf.WriteResultInf(ES.InPar,ES.OutPar,ES.getFileName(),ResultFile,ES.getScanMethod())185""" Plot """186Ploter.setPlotPar(ES.getFileName())...

Full Screen

Full Screen

es.py

Source:es.py Github

copy

Full Screen

...48 else:49 raise Exception("insert_es_data func just support list or dict to insert")50 except Exception as e:51 print "[Error]%s" % e52 def get_field_from_es(self, es_index, field_list, es = "", start = 0, depth = 10):53 '''54 this func return dict like:55 {u'hits': {u'hits': [{u'_source': {u'CVE': u'CVE-0000-0000'}}, \56 {u'_source': {u'CVE': u'CVE-0000-0001'}}, {u'_source': \57 {u'CVE': u'CVE-0000-0002'}}]}} 58 '''59 es = self.get_es_conn() if es == "" else es60 try:61 body = {"from": start, "size": depth}62 filter_path = []63 for field in field_list:64 filter_path.append("hits.hits._source." + field)65 print filter_path66 data = es.search(index = es_index, filter_path = filter_path, body = body)67 return data68 except Exception as e:69 print "[Error]%s" % e70 def search_from_es(self, es_index, field, value, multi = False, fuzz = True, es = ''):71 es = self.get_es_conn() if es == "" else es72 try:73 body = {}74 if fuzz:75 if multi:76 if type(field) is not list:77 raise Exception("Use fuzz search and multi field,need set list type' field")78 else:79 field_list = [f for f in field] 80 body = {81 "query":{82 "multi_match":{83 "query" : value, 84 "fields": field_list...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful