How to use tagged method in locust

Best Python code snippet using locust

tagged.py

Source:tagged.py Github

copy

Full Screen

1# Natural Language Toolkit: Tagged Corpus Reader2#3# Copyright (C) 2001-2015 NLTK Project4# Author: Edward Loper <edloper@gmail.com>5# Steven Bird <stevenbird1@gmail.com>6# Jacob Perkins <japerk@gmail.com>7# URL: <http://nltk.org/>8# For license information, see LICENSE.TXT9"""10A reader for corpora whose documents contain part-of-speech-tagged words.11"""12import os13from nltk import compat14from nltk.tag import str2tuple, map_tag15from nltk.tokenize import *16from nltk.corpus.reader.api import *17from nltk.corpus.reader.util import *18from nltk.corpus.reader.timit import read_timit_block19class TaggedCorpusReader(CorpusReader):20 """21 Reader for simple part-of-speech tagged corpora. Paragraphs are22 assumed to be split using blank lines. Sentences and words can be23 tokenized using the default tokenizers, or by custom tokenizers24 specified as parameters to the constructor. Words are parsed25 using ``nltk.tag.str2tuple``. By default, ``'/'`` is used as the26 separator. I.e., words should have the form::27 word1/tag1 word2/tag2 word3/tag3 ...28 But custom separators may be specified as parameters to the29 constructor. Part of speech tags are case-normalized to upper30 case.31 """32 def __init__(self, root, fileids,33 sep='/', word_tokenizer=WhitespaceTokenizer(),34 sent_tokenizer=RegexpTokenizer('\n', gaps=True),35 para_block_reader=read_blankline_block,36 encoding='utf8',37 tagset=None):38 """39 Construct a new Tagged Corpus reader for a set of documents40 located at the given root directory. Example usage:41 >>> root = '/...path to corpus.../'42 >>> reader = TaggedCorpusReader(root, '.*', '.txt') # doctest: +SKIP43 :param root: The root directory for this corpus.44 :param fileids: A list or regexp specifying the fileids in this corpus.45 """46 CorpusReader.__init__(self, root, fileids, encoding)47 self._sep = sep48 self._word_tokenizer = word_tokenizer49 self._sent_tokenizer = sent_tokenizer50 self._para_block_reader = para_block_reader51 self._tagset = tagset52 def raw(self, fileids=None):53 """54 :return: the given file(s) as a single string.55 :rtype: str56 """57 if fileids is None: fileids = self._fileids58 elif isinstance(fileids, compat.string_types): fileids = [fileids]59 return concat([self.open(f).read() for f in fileids])60 def words(self, fileids=None):61 """62 :return: the given file(s) as a list of words63 and punctuation symbols.64 :rtype: list(str)65 """66 return concat([TaggedCorpusView(fileid, enc,67 False, False, False,68 self._sep, self._word_tokenizer,69 self._sent_tokenizer,70 self._para_block_reader,71 None)72 for (fileid, enc) in self.abspaths(fileids, True)])73 def sents(self, fileids=None):74 """75 :return: the given file(s) as a list of76 sentences or utterances, each encoded as a list of word77 strings.78 :rtype: list(list(str))79 """80 return concat([TaggedCorpusView(fileid, enc,81 False, True, False,82 self._sep, self._word_tokenizer,83 self._sent_tokenizer,84 self._para_block_reader,85 None)86 for (fileid, enc) in self.abspaths(fileids, True)])87 def paras(self, fileids=None):88 """89 :return: the given file(s) as a list of90 paragraphs, each encoded as a list of sentences, which are91 in turn encoded as lists of word strings.92 :rtype: list(list(list(str)))93 """94 return concat([TaggedCorpusView(fileid, enc,95 False, True, True,96 self._sep, self._word_tokenizer,97 self._sent_tokenizer,98 self._para_block_reader,99 None)100 for (fileid, enc) in self.abspaths(fileids, True)])101 def tagged_words(self, fileids=None, tagset=None):102 """103 :return: the given file(s) as a list of tagged104 words and punctuation symbols, encoded as tuples105 ``(word,tag)``.106 :rtype: list(tuple(str,str))107 """108 if tagset and tagset != self._tagset:109 tag_mapping_function = lambda t: map_tag(self._tagset, tagset, t)110 else:111 tag_mapping_function = None112 return concat([TaggedCorpusView(fileid, enc,113 True, False, False,114 self._sep, self._word_tokenizer,115 self._sent_tokenizer,116 self._para_block_reader,117 tag_mapping_function)118 for (fileid, enc) in self.abspaths(fileids, True)])119 def tagged_sents(self, fileids=None, tagset=None):120 """121 :return: the given file(s) as a list of122 sentences, each encoded as a list of ``(word,tag)`` tuples.123 :rtype: list(list(tuple(str,str)))124 """125 if tagset and tagset != self._tagset:126 tag_mapping_function = lambda t: map_tag(self._tagset, tagset, t)127 else:128 tag_mapping_function = None129 return concat([TaggedCorpusView(fileid, enc,130 True, True, False,131 self._sep, self._word_tokenizer,132 self._sent_tokenizer,133 self._para_block_reader,134 tag_mapping_function)135 for (fileid, enc) in self.abspaths(fileids, True)])136 def tagged_paras(self, fileids=None, tagset=None):137 """138 :return: the given file(s) as a list of139 paragraphs, each encoded as a list of sentences, which are140 in turn encoded as lists of ``(word,tag)`` tuples.141 :rtype: list(list(list(tuple(str,str))))142 """143 if tagset and tagset != self._tagset:144 tag_mapping_function = lambda t: map_tag(self._tagset, tagset, t)145 else:146 tag_mapping_function = None147 return concat([TaggedCorpusView(fileid, enc,148 True, True, True,149 self._sep, self._word_tokenizer,150 self._sent_tokenizer,151 self._para_block_reader,152 tag_mapping_function)153 for (fileid, enc) in self.abspaths(fileids, True)])154class CategorizedTaggedCorpusReader(CategorizedCorpusReader,155 TaggedCorpusReader):156 """157 A reader for part-of-speech tagged corpora whose documents are158 divided into categories based on their file identifiers.159 """160 def __init__(self, *args, **kwargs):161 """162 Initialize the corpus reader. Categorization arguments163 (``cat_pattern``, ``cat_map``, and ``cat_file``) are passed to164 the ``CategorizedCorpusReader`` constructor. The remaining arguments165 are passed to the ``TaggedCorpusReader``.166 """167 CategorizedCorpusReader.__init__(self, kwargs)168 TaggedCorpusReader.__init__(self, *args, **kwargs)169 def _resolve(self, fileids, categories):170 if fileids is not None and categories is not None:171 raise ValueError('Specify fileids or categories, not both')172 if categories is not None:173 return self.fileids(categories)174 else:175 return fileids176 def raw(self, fileids=None, categories=None):177 return TaggedCorpusReader.raw(178 self, self._resolve(fileids, categories))179 def words(self, fileids=None, categories=None):180 return TaggedCorpusReader.words(181 self, self._resolve(fileids, categories))182 def sents(self, fileids=None, categories=None):183 return TaggedCorpusReader.sents(184 self, self._resolve(fileids, categories))185 def paras(self, fileids=None, categories=None):186 return TaggedCorpusReader.paras(187 self, self._resolve(fileids, categories))188 def tagged_words(self, fileids=None, categories=None, tagset=None):189 return TaggedCorpusReader.tagged_words(190 self, self._resolve(fileids, categories), tagset)191 def tagged_sents(self, fileids=None, categories=None, tagset=None):192 return TaggedCorpusReader.tagged_sents(193 self, self._resolve(fileids, categories), tagset)194 def tagged_paras(self, fileids=None, categories=None, tagset=None):195 return TaggedCorpusReader.tagged_paras(196 self, self._resolve(fileids, categories), tagset)197class TaggedCorpusView(StreamBackedCorpusView):198 """199 A specialized corpus view for tagged documents. It can be200 customized via flags to divide the tagged corpus documents up by201 sentence or paragraph, and to include or omit part of speech tags.202 ``TaggedCorpusView`` objects are typically created by203 ``TaggedCorpusReader`` (not directly by nltk users).204 """205 def __init__(self, corpus_file, encoding, tagged, group_by_sent,206 group_by_para, sep, word_tokenizer, sent_tokenizer,207 para_block_reader, tag_mapping_function=None):208 self._tagged = tagged209 self._group_by_sent = group_by_sent210 self._group_by_para = group_by_para211 self._sep = sep212 self._word_tokenizer = word_tokenizer213 self._sent_tokenizer = sent_tokenizer214 self._para_block_reader = para_block_reader215 self._tag_mapping_function = tag_mapping_function216 StreamBackedCorpusView.__init__(self, corpus_file, encoding=encoding)217 def read_block(self, stream):218 """Reads one paragraph at a time."""219 block = []220 for para_str in self._para_block_reader(stream):221 para = []222 for sent_str in self._sent_tokenizer.tokenize(para_str):223 sent = [str2tuple(s, self._sep) for s in224 self._word_tokenizer.tokenize(sent_str)]225 if self._tag_mapping_function:226 sent = [(w, self._tag_mapping_function(t)) for (w,t) in sent]227 if not self._tagged:228 sent = [w for (w,t) in sent]229 if self._group_by_sent:230 para.append(sent)231 else:232 para.extend(sent)233 if self._group_by_para:234 block.append(para)235 else:236 block.extend(para)237 return block238# needs to implement simplified tags239class MacMorphoCorpusReader(TaggedCorpusReader):240 """241 A corpus reader for the MAC_MORPHO corpus. Each line contains a242 single tagged word, using '_' as a separator. Sentence boundaries243 are based on the end-sentence tag ('_.'). Paragraph information244 is not included in the corpus, so each paragraph returned by245 ``self.paras()`` and ``self.tagged_paras()`` contains a single246 sentence.247 """248 def __init__(self, root, fileids, encoding='utf8', tagset=None):249 TaggedCorpusReader.__init__(250 self, root, fileids, sep='_',251 word_tokenizer=LineTokenizer(),252 sent_tokenizer=RegexpTokenizer('.*\n'),253 para_block_reader=self._read_block,254 encoding=encoding,255 tagset=tagset)256 def _read_block(self, stream):257 return read_regexp_block(stream, r'.*', r'.*_\.')258class TimitTaggedCorpusReader(TaggedCorpusReader):259 """260 A corpus reader for tagged sentences that are included in the TIMIT corpus.261 """262 def __init__(self, *args, **kwargs):263 TaggedCorpusReader.__init__(264 self, para_block_reader=read_timit_block, *args, **kwargs)265 def paras(self):266 raise NotImplementedError('use sents() instead')267 def tagged_paras(self):...

Full Screen

Full Screen

test_ec2object.py

Source:test_ec2object.py Github

copy

Full Screen

1#!/usr/bin/env python2from tests.unit import unittest3from tests.unit import AWSMockServiceTestCase4from boto.ec2.connection import EC2Connection5from boto.ec2.ec2object import TaggedEC2Object6CREATE_TAGS_RESPONSE = br"""<?xml version="1.0" encoding="UTF-8"?>7<CreateTagsResponse xmlns="http://ec2.amazonaws.com/doc/2014-05-01/">8 <requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>9 <return>true</return>10</CreateTagsResponse>11"""12DELETE_TAGS_RESPONSE = br"""<?xml version="1.0" encoding="UTF-8"?>13<DeleteTagsResponse xmlns="http://ec2.amazonaws.com/doc/2014-05-01/">14 <requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>15 <return>true</return>16</DeleteTagsResponse>17"""18class TestAddTags(AWSMockServiceTestCase):19 connection_class = EC2Connection20 def default_body(self):21 return CREATE_TAGS_RESPONSE22 def test_add_tag(self):23 self.set_http_response(status_code=200)24 taggedEC2Object = TaggedEC2Object(self.service_connection)25 taggedEC2Object.id = "i-abcd1234"26 taggedEC2Object.tags["already_present_key"] = "already_present_value"27 taggedEC2Object.add_tag("new_key", "new_value")28 self.assert_request_parameters({29 'ResourceId.1': 'i-abcd1234',30 'Action': 'CreateTags',31 'Tag.1.Key': 'new_key',32 'Tag.1.Value': 'new_value'},33 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',34 'SignatureVersion', 'Timestamp',35 'Version'])36 self.assertEqual(taggedEC2Object.tags, {37 "already_present_key": "already_present_value",38 "new_key": "new_value"})39 def test_add_tags(self):40 self.set_http_response(status_code=200)41 taggedEC2Object = TaggedEC2Object(self.service_connection)42 taggedEC2Object.id = "i-abcd1234"43 taggedEC2Object.tags["already_present_key"] = "already_present_value"44 taggedEC2Object.add_tags({"key1": "value1", "key2": "value2"})45 self.assert_request_parameters({46 'ResourceId.1': 'i-abcd1234',47 'Action': 'CreateTags',48 'Tag.1.Key': 'key1',49 'Tag.1.Value': 'value1',50 'Tag.2.Key': 'key2',51 'Tag.2.Value': 'value2'},52 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',53 'SignatureVersion', 'Timestamp',54 'Version'])55 self.assertEqual(taggedEC2Object.tags, {56 "already_present_key": "already_present_value",57 "key1": "value1",58 "key2": "value2"})59class TestRemoveTags(AWSMockServiceTestCase):60 connection_class = EC2Connection61 def default_body(self):62 return DELETE_TAGS_RESPONSE63 def test_remove_tag(self):64 self.set_http_response(status_code=200)65 taggedEC2Object = TaggedEC2Object(self.service_connection)66 taggedEC2Object.id = "i-abcd1234"67 taggedEC2Object.tags["key1"] = "value1"68 taggedEC2Object.tags["key2"] = "value2"69 taggedEC2Object.remove_tag("key1", "value1")70 self.assert_request_parameters({71 'ResourceId.1': 'i-abcd1234',72 'Action': 'DeleteTags',73 'Tag.1.Key': 'key1',74 'Tag.1.Value': 'value1'},75 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',76 'SignatureVersion', 'Timestamp',77 'Version'])78 self.assertEqual(taggedEC2Object.tags, {"key2": "value2"})79 def test_remove_tag_no_value(self):80 self.set_http_response(status_code=200)81 taggedEC2Object = TaggedEC2Object(self.service_connection)82 taggedEC2Object.id = "i-abcd1234"83 taggedEC2Object.tags["key1"] = "value1"84 taggedEC2Object.tags["key2"] = "value2"85 taggedEC2Object.remove_tag("key1")86 self.assert_request_parameters({87 'ResourceId.1': 'i-abcd1234',88 'Action': 'DeleteTags',89 'Tag.1.Key': 'key1'},90 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',91 'SignatureVersion', 'Timestamp',92 'Version'])93 self.assertEqual(taggedEC2Object.tags, {"key2": "value2"})94 def test_remove_tag_empty_value(self):95 self.set_http_response(status_code=200)96 taggedEC2Object = TaggedEC2Object(self.service_connection)97 taggedEC2Object.id = "i-abcd1234"98 taggedEC2Object.tags["key1"] = "value1"99 taggedEC2Object.tags["key2"] = "value2"100 taggedEC2Object.remove_tag("key1", "")101 self.assert_request_parameters({102 'ResourceId.1': 'i-abcd1234',103 'Action': 'DeleteTags',104 'Tag.1.Key': 'key1',105 'Tag.1.Value': ''},106 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',107 'SignatureVersion', 'Timestamp',108 'Version'])109 self.assertEqual(taggedEC2Object.tags,110 {"key1": "value1", "key2": "value2"})111 def test_remove_tags(self):112 self.set_http_response(status_code=200)113 taggedEC2Object = TaggedEC2Object(self.service_connection)114 taggedEC2Object.id = "i-abcd1234"115 taggedEC2Object.tags["key1"] = "value1"116 taggedEC2Object.tags["key2"] = "value2"117 taggedEC2Object.remove_tags({"key1": "value1", "key2": "value2"})118 self.assert_request_parameters({119 'ResourceId.1': 'i-abcd1234',120 'Action': 'DeleteTags',121 'Tag.1.Key': 'key1',122 'Tag.1.Value': 'value1',123 'Tag.2.Key': 'key2',124 'Tag.2.Value': 'value2'},125 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',126 'SignatureVersion', 'Timestamp',127 'Version'])128 self.assertEqual(taggedEC2Object.tags, {})129 def test_remove_tags_wrong_values(self):130 self.set_http_response(status_code=200)131 taggedEC2Object = TaggedEC2Object(self.service_connection)132 taggedEC2Object.id = "i-abcd1234"133 taggedEC2Object.tags["key1"] = "value1"134 taggedEC2Object.tags["key2"] = "value2"135 taggedEC2Object.remove_tags({"key1": "value1", "key2": "value3"})136 self.assert_request_parameters({137 'ResourceId.1': 'i-abcd1234',138 'Action': 'DeleteTags',139 'Tag.1.Key': 'key1',140 'Tag.1.Value': 'value1',141 'Tag.2.Key': 'key2',142 'Tag.2.Value': 'value3'},143 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',144 'SignatureVersion', 'Timestamp',145 'Version'])146 self.assertEqual(taggedEC2Object.tags, {"key2": "value2"})147 def test_remove_tags_none_values(self):148 self.set_http_response(status_code=200)149 taggedEC2Object = TaggedEC2Object(self.service_connection)150 taggedEC2Object.id = "i-abcd1234"151 taggedEC2Object.tags["key1"] = "value1"152 taggedEC2Object.tags["key2"] = "value2"153 taggedEC2Object.remove_tags({"key1": "value1", "key2": None})154 self.assert_request_parameters({155 'ResourceId.1': 'i-abcd1234',156 'Action': 'DeleteTags',157 'Tag.1.Key': 'key1',158 'Tag.1.Value': 'value1',159 'Tag.2.Key': 'key2'},160 ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',161 'SignatureVersion', 'Timestamp',162 'Version'])163 self.assertEqual(taggedEC2Object.tags, {})164if __name__ == '__main__':...

Full Screen

Full Screen

param_TaggedPrefetcher.py

Source:param_TaggedPrefetcher.py Github

copy

Full Screen

1# This file was automatically generated by SWIG (http://www.swig.org).2# Version 3.0.123#4# Do not make changes to this file unless you know what you are doing--modify5# the SWIG interface file instead.6from sys import version_info as _swig_python_version_info7if _swig_python_version_info >= (2, 7, 0):8 def swig_import_helper():9 import importlib10 pkg = __name__.rpartition('.')[0]11 mname = '.'.join((pkg, '_param_TaggedPrefetcher')).lstrip('.')12 try:13 return importlib.import_module(mname)14 except ImportError:15 return importlib.import_module('_param_TaggedPrefetcher')16 _param_TaggedPrefetcher = swig_import_helper()17 del swig_import_helper18elif _swig_python_version_info >= (2, 6, 0):19 def swig_import_helper():20 from os.path import dirname21 import imp22 fp = None23 try:24 fp, pathname, description = imp.find_module('_param_TaggedPrefetcher', [dirname(__file__)])25 except ImportError:26 import _param_TaggedPrefetcher27 return _param_TaggedPrefetcher28 try:29 _mod = imp.load_module('_param_TaggedPrefetcher', fp, pathname, description)30 finally:31 if fp is not None:32 fp.close()33 return _mod34 _param_TaggedPrefetcher = swig_import_helper()35 del swig_import_helper36else:37 import _param_TaggedPrefetcher38del _swig_python_version_info39try:40 _swig_property = property41except NameError:42 pass # Python < 2.2 doesn't have 'property'.43try:44 import builtins as __builtin__45except ImportError:46 import __builtin__47def _swig_setattr_nondynamic(self, class_type, name, value, static=1):48 if (name == "thisown"):49 return self.this.own(value)50 if (name == "this"):51 if type(value).__name__ == 'SwigPyObject':52 self.__dict__[name] = value53 return54 method = class_type.__swig_setmethods__.get(name, None)55 if method:56 return method(self, value)57 if (not static):58 object.__setattr__(self, name, value)59 else:60 raise AttributeError("You cannot add attributes to %s" % self)61def _swig_setattr(self, class_type, name, value):62 return _swig_setattr_nondynamic(self, class_type, name, value, 0)63def _swig_getattr(self, class_type, name):64 if (name == "thisown"):65 return self.this.own()66 method = class_type.__swig_getmethods__.get(name, None)67 if method:68 return method(self)69 raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))70def _swig_repr(self):71 try:72 strthis = "proxy of " + self.this.__repr__()73 except __builtin__.Exception:74 strthis = ""75 return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)76def _swig_setattr_nondynamic_method(set):77 def set_attr(self, name, value):78 if (name == "thisown"):79 return self.this.own(value)80 if hasattr(self, name) or (name == "this"):81 set(self, name, value)82 else:83 raise AttributeError("You cannot add attributes to %s" % self)84 return set_attr85import m5.internal.param_QueuedPrefetcher86import m5.internal.param_BasePrefetcher87import m5.internal.param_System88import m5.internal.enum_MemoryMode89import m5.internal.AddrRange_vector90import m5.internal.AbstractMemory_vector91import m5.internal.param_AbstractMemory92import m5.internal.param_MemObject93import m5.internal.param_ClockedObject94import m5.internal.param_ClockDomain95import m5.internal.param_SimObject96import m5.internal.drain97import m5.internal.serialize98import m5.internal.SimObject_vector99import m5.internal.param_ThermalModel100class TaggedPrefetcher(m5.internal.param_QueuedPrefetcher.QueuedPrefetcher):101 thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')102 def __init__(self, *args, **kwargs):103 raise AttributeError("No constructor defined - class is abstract")104 __repr__ = _swig_repr105TaggedPrefetcher_swigregister = _param_TaggedPrefetcher.TaggedPrefetcher_swigregister106TaggedPrefetcher_swigregister(TaggedPrefetcher)107class TaggedPrefetcherParams(m5.internal.param_QueuedPrefetcher.QueuedPrefetcherParams):108 thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')109 __repr__ = _swig_repr110 def create(self):111 return _param_TaggedPrefetcher.TaggedPrefetcherParams_create(self)112 degree = _swig_property(_param_TaggedPrefetcher.TaggedPrefetcherParams_degree_get, _param_TaggedPrefetcher.TaggedPrefetcherParams_degree_set)113 def __init__(self):114 this = _param_TaggedPrefetcher.new_TaggedPrefetcherParams()115 try:116 self.this.append(this)117 except __builtin__.Exception:118 self.this = this119 __swig_destroy__ = _param_TaggedPrefetcher.delete_TaggedPrefetcherParams120 __del__ = lambda self: None121TaggedPrefetcherParams_swigregister = _param_TaggedPrefetcher.TaggedPrefetcherParams_swigregister...

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 locust 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