_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q8900
InlineQueryResultCachedVoice.to_array
train
def to_array(self): """ Serializes this InlineQueryResultCachedVoice to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultCachedVoice, self).to_array() # 'type' and 'id' given by superclass array['voice_file_id'] = u(self.voice_file_id) # py2: type unicode, py3: type str array['title'] = u(self.title) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8901
InlineQueryResultCachedAudio.from_array
train
def from_array(array): """ Deserialize a new InlineQueryResultCachedAudio from a given dictionary. :return: new InlineQueryResultCachedAudio instance. :rtype: InlineQueryResultCachedAudio """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.sendable.reply_markup import InlineKeyboardMarkup data = {} # 'type' is given by class type data['id'] = u(array.get('id')) data['audio_file_id'] = u(array.get('audio_file_id')) data['caption'] = u(array.get('caption')) if array.get('caption') is not None else None data['parse_mode'] = u(array.get('parse_mode')) if array.get('parse_mode') is not None else None data['reply_markup'] = InlineKeyboardMarkup.from_array(array.get('reply_markup')) if array.get('reply_markup') is not None else None data['input_message_content'] = InputMessageContent.from_array(array.get('input_message_content')) if array.get('input_message_content') is not None else None instance = InlineQueryResultCachedAudio(**data) instance._raw = array return instance
python
{ "resource": "" }
q8902
InputTextMessageContent.to_array
train
def to_array(self): """ Serializes this InputTextMessageContent to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InputTextMessageContent, self).to_array() array['message_text'] = u(self.message_text) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.disable_web_page_preview is not None: array['disable_web_page_preview'] = bool(self.disable_web_page_preview) # type bool return array
python
{ "resource": "" }
q8903
InputLocationMessageContent.to_array
train
def to_array(self): """ Serializes this InputLocationMessageContent to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InputLocationMessageContent, self).to_array() array['latitude'] = float(self.latitude) # type float array['longitude'] = float(self.longitude) # type float if self.live_period is not None: array['live_period'] = int(self.live_period) # type int return array
python
{ "resource": "" }
q8904
InputLocationMessageContent.from_array
train
def from_array(array): """ Deserialize a new InputLocationMessageContent from a given dictionary. :return: new InputLocationMessageContent instance. :rtype: InputLocationMessageContent """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['latitude'] = float(array.get('latitude')) data['longitude'] = float(array.get('longitude')) data['live_period'] = int(array.get('live_period')) if array.get('live_period') is not None else None instance = InputLocationMessageContent(**data) instance._raw = array return instance
python
{ "resource": "" }
q8905
InputVenueMessageContent.to_array
train
def to_array(self): """ Serializes this InputVenueMessageContent to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InputVenueMessageContent, self).to_array() array['latitude'] = float(self.latitude) # type float array['longitude'] = float(self.longitude) # type float array['title'] = u(self.title) # py2: type unicode, py3: type str array['address'] = u(self.address) # py2: type unicode, py3: type str if self.foursquare_id is not None: array['foursquare_id'] = u(self.foursquare_id) # py2: type unicode, py3: type str if self.foursquare_type is not None: array['foursquare_type'] = u(self.foursquare_type) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8906
InputVenueMessageContent.from_array
train
def from_array(array): """ Deserialize a new InputVenueMessageContent from a given dictionary. :return: new InputVenueMessageContent instance. :rtype: InputVenueMessageContent """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['latitude'] = float(array.get('latitude')) data['longitude'] = float(array.get('longitude')) data['title'] = u(array.get('title')) data['address'] = u(array.get('address')) data['foursquare_id'] = u(array.get('foursquare_id')) if array.get('foursquare_id') is not None else None data['foursquare_type'] = u(array.get('foursquare_type')) if array.get('foursquare_type') is not None else None instance = InputVenueMessageContent(**data) instance._raw = array return instance
python
{ "resource": "" }
q8907
InputContactMessageContent.to_array
train
def to_array(self): """ Serializes this InputContactMessageContent to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InputContactMessageContent, self).to_array() array['phone_number'] = u(self.phone_number) # py2: type unicode, py3: type str array['first_name'] = u(self.first_name) # py2: type unicode, py3: type str if self.last_name is not None: array['last_name'] = u(self.last_name) # py2: type unicode, py3: type str if self.vcard is not None: array['vcard'] = u(self.vcard) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8908
can_strip_prefix
train
def can_strip_prefix(text:str, prefix:str) -> (bool, str): """ If the given text starts with the given prefix, True and the text without that prefix is returned. Else False and the original text is returned. Note: the text always is stripped, before returning. :param text: :param prefix: :return: (bool, str) :class:`bool` whether he text started with given prefix, :class:`str` the text without prefix """ if text.startswith(prefix): return True, text[len(prefix):].strip() return False, text.strip()
python
{ "resource": "" }
q8909
Function.class_name
train
def class_name(self) -> str: """ Makes the fist letter big, keep the rest of the camelCaseApiName. """ if not self.api_name: # empty string return self.api_name # end if return self.api_name[0].upper() + self.api_name[1:]
python
{ "resource": "" }
q8910
Function.class_name_teleflask_message
train
def class_name_teleflask_message(self) -> str: """ If it starts with `Send` remove that. """ # strip leading "Send" name = self.class_name # "sendPhoto" -> "SendPhoto" name = name[4:] if name.startswith('Send') else name # "SendPhoto" -> "Photo" name = name + "Message" # "Photo" -> "PhotoMessage" # e.g. "MessageMessage" will be replaced as "TextMessage" # b/c "sendMessage" -> "SendMessage" -> "Message" -> "MessageMessage" ==> "TextMessage" if name in MESSAGE_CLASS_OVERRIDES: return MESSAGE_CLASS_OVERRIDES[name] # end if return name
python
{ "resource": "" }
q8911
Import.full
train
def full(self): """ self.path + "." + self.name """ if self.path: if self.name: return self.path + "." + self.name else: return self.path # end if else: if self.name: return self.name else: return ""
python
{ "resource": "" }
q8912
ResponseBot.do
train
def do(self, command, files=None, use_long_polling=False, request_timeout=None, **query): """ Return the request params we would send to the api. """ url, params = self._prepare_request(command, query) return { "url": url, "params": params, "files": files, "stream": use_long_polling, "verify": True, # No self signed certificates. Telegram should be trustworthy anyway... "timeout": request_timeout }
python
{ "resource": "" }
q8913
Update.to_array
train
def to_array(self): """ Serializes this Update to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Update, self).to_array() array['update_id'] = int(self.update_id) # type int if self.message is not None: array['message'] = self.message.to_array() # type Message if self.edited_message is not None: array['edited_message'] = self.edited_message.to_array() # type Message if self.channel_post is not None: array['channel_post'] = self.channel_post.to_array() # type Message if self.edited_channel_post is not None: array['edited_channel_post'] = self.edited_channel_post.to_array() # type Message if self.inline_query is not None: array['inline_query'] = self.inline_query.to_array() # type InlineQuery if self.chosen_inline_result is not None: array['chosen_inline_result'] = self.chosen_inline_result.to_array() # type ChosenInlineResult if self.callback_query is not None: array['callback_query'] = self.callback_query.to_array() # type CallbackQuery if self.shipping_query is not None: array['shipping_query'] = self.shipping_query.to_array() # type ShippingQuery if self.pre_checkout_query is not None: array['pre_checkout_query'] = self.pre_checkout_query.to_array() # type PreCheckoutQuery return array
python
{ "resource": "" }
q8914
WebhookInfo.to_array
train
def to_array(self): """ Serializes this WebhookInfo to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(WebhookInfo, self).to_array() array['url'] = u(self.url) # py2: type unicode, py3: type str array['has_custom_certificate'] = bool(self.has_custom_certificate) # type bool array['pending_update_count'] = int(self.pending_update_count) # type int if self.last_error_date is not None: array['last_error_date'] = int(self.last_error_date) # type int if self.last_error_message is not None: array['last_error_message'] = u(self.last_error_message) # py2: type unicode, py3: type str if self.max_connections is not None: array['max_connections'] = int(self.max_connections) # type int if self.allowed_updates is not None: array['allowed_updates'] = self._as_array(self.allowed_updates) # type list of str return array
python
{ "resource": "" }
q8915
WebhookInfo.from_array
train
def from_array(array): """ Deserialize a new WebhookInfo from a given dictionary. :return: new WebhookInfo instance. :rtype: WebhookInfo """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['url'] = u(array.get('url')) data['has_custom_certificate'] = bool(array.get('has_custom_certificate')) data['pending_update_count'] = int(array.get('pending_update_count')) data['last_error_date'] = int(array.get('last_error_date')) if array.get('last_error_date') is not None else None data['last_error_message'] = u(array.get('last_error_message')) if array.get('last_error_message') is not None else None data['max_connections'] = int(array.get('max_connections')) if array.get('max_connections') is not None else None data['allowed_updates'] = WebhookInfo._builtin_from_array_list(required_type=unicode_type, value=array.get('allowed_updates'), list_level=1) if array.get('allowed_updates') is not None else None data['_raw'] = array return WebhookInfo(**data)
python
{ "resource": "" }
q8916
CallbackQuery.to_array
train
def to_array(self): """ Serializes this CallbackQuery to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(CallbackQuery, self).to_array() array['id'] = u(self.id) # py2: type unicode, py3: type str array['from'] = self.from_peer.to_array() # type User array['chat_instance'] = u(self.chat_instance) # py2: type unicode, py3: type str if self.message is not None: array['message'] = self.message.to_array() # type Message if self.inline_message_id is not None: array['inline_message_id'] = u(self.inline_message_id) # py2: type unicode, py3: type str if self.data is not None: array['data'] = u(self.data) # py2: type unicode, py3: type str if self.game_short_name is not None: array['game_short_name'] = u(self.game_short_name) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8917
CallbackQuery.from_array
train
def from_array(array): """ Deserialize a new CallbackQuery from a given dictionary. :return: new CallbackQuery instance. :rtype: CallbackQuery """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from ..receivable.peer import User data = {} data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['chat_instance'] = u(array.get('chat_instance')) data['message'] = Message.from_array(array.get('message')) if array.get('message') is not None else None data['inline_message_id'] = u(array.get('inline_message_id')) if array.get('inline_message_id') is not None else None data['data'] = u(array.get('data')) if array.get('data') is not None else None data['game_short_name'] = u(array.get('game_short_name')) if array.get('game_short_name') is not None else None data['_raw'] = array return CallbackQuery(**data)
python
{ "resource": "" }
q8918
ResponseParameters.to_array
train
def to_array(self): """ Serializes this ResponseParameters to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ResponseParameters, self).to_array() if self.migrate_to_chat_id is not None: array['migrate_to_chat_id'] = int(self.migrate_to_chat_id) # type int if self.retry_after is not None: array['retry_after'] = int(self.retry_after) # type int return array
python
{ "resource": "" }
q8919
ResponseParameters.from_array
train
def from_array(array): """ Deserialize a new ResponseParameters from a given dictionary. :return: new ResponseParameters instance. :rtype: ResponseParameters """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['migrate_to_chat_id'] = int(array.get('migrate_to_chat_id')) if array.get('migrate_to_chat_id') is not None else None data['retry_after'] = int(array.get('retry_after')) if array.get('retry_after') is not None else None data['_raw'] = array return ResponseParameters(**data)
python
{ "resource": "" }
q8920
Xmrs.from_xmrs
train
def from_xmrs(cls, xmrs, **kwargs): """ Facilitate conversion among subclasses. Args: xmrs (:class:`Xmrs`): instance to convert from; possibly an instance of a subclass, such as :class:`Mrs` or :class:`Dmrs` **kwargs: additional keyword arguments that may be used by a subclass's redefinition of :meth:`from_xmrs`. """ x = cls() x.__dict__.update(xmrs.__dict__) return x
python
{ "resource": "" }
q8921
Xmrs.is_connected
train
def is_connected(self): """ Return `True` if the Xmrs represents a connected graph. Subgraphs can be connected through things like arguments, QEQs, and label equalities. """ nids = set(self._nodeids) # the nids left to find if len(nids) == 0: raise XmrsError('Cannot compute connectedness of an empty Xmrs.') # build a basic dict graph of relations edges = [] # label connections for lbl in self.labels(): lblset = self.labelset(lbl) edges.extend((x, y) for x in lblset for y in lblset if x != y) # argument connections _vars = self._vars for nid in nids: for rarg, tgt in self.args(nid).items(): if tgt not in _vars: continue if IVARG_ROLE in _vars[tgt]['refs']: tgtnids = list(_vars[tgt]['refs'][IVARG_ROLE]) elif tgt in self._hcons: tgtnids = list(self.labelset(self.hcon(tgt)[2])) elif 'LBL' in _vars[tgt]['refs']: tgtnids = list(_vars[tgt]['refs']['LBL']) else: tgtnids = [] # connections are bidirectional edges.extend((nid, t) for t in tgtnids if nid != t) edges.extend((t, nid) for t in tgtnids if nid != t) g = {nid: set() for nid in nids} for x, y in edges: g[x].add(y) connected_nids = _bfs(g) if connected_nids == nids: return True elif connected_nids.difference(nids): raise XmrsError( 'Possibly bogus nodeids: {}' .format(', '.join(connected_nids.difference(nids))) ) return False
python
{ "resource": "" }
q8922
Xmrs.validate
train
def validate(self): """ Check that the Xmrs is well-formed. The Xmrs is analyzed and a list of problems is compiled. If any problems exist, an :exc:`XmrsError` is raised with the list joined as the error message. A well-formed Xmrs has the following properties: * All predications have an intrinsic variable * Every intrinsic variable belongs one predication and maybe one quantifier * Every predication has no more than one quantifier * All predications have a label * The graph of predications form a net (i.e. are connected). Connectivity can be established with variable arguments, QEQs, or label-equality. * The lo-handle for each QEQ must exist as the label of a predication """ errors = [] ivs, bvs = {}, {} _vars = self._vars _hcons = self._hcons labels = defaultdict(set) # ep_args = {} for ep in self.eps(): nid, lbl, args, is_q = ( ep.nodeid, ep.label, ep.args, ep.is_quantifier() ) if lbl is None: errors.append('EP ({}) is missing a label.'.format(nid)) labels[lbl].add(nid) iv = args.get(IVARG_ROLE) if iv is None: errors.append('EP {nid} is missing an intrinsic variable.' .format(nid)) if is_q: if iv in bvs: errors.append('{} is the bound variable for more than ' 'one quantifier.'.format(iv)) bvs[iv] = nid else: if iv in ivs: errors.append('{} is the intrinsic variable for more ' 'than one EP.'.format(iv)) ivs[iv] = nid # ep_args[nid] = args for hc in _hcons.values(): if hc[2] not in labels: errors.append('Lo variable of HCONS ({} {} {}) is not the ' 'label of any EP.'.format(*hc)) if not self.is_connected(): errors.append('Xmrs structure is not connected.') if errors: raise XmrsError('\n'.join(errors))
python
{ "resource": "" }
q8923
Mrs.to_dict
train
def to_dict(self, short_pred=True, properties=True): """ Encode the Mrs as a dictionary suitable for JSON serialization. """ def _lnk(obj): return {'from': obj.cfrom, 'to': obj.cto} def _ep(ep, short_pred=True): p = ep.pred.short_form() if short_pred else ep.pred.string d = dict(label=ep.label, predicate=p, arguments=ep.args) if ep.lnk is not None: d['lnk'] = _lnk(ep) return d def _hcons(hc): return {'relation':hc[1], 'high':hc[0], 'low':hc[2]} def _icons(ic): return {'relation':ic[1], 'left':ic[0], 'right':ic[2]} def _var(v): d = {'type': var_sort(v)} if properties and self.properties(v): d['properties'] = self.properties(v) return d d = dict( relations=[_ep(ep, short_pred=short_pred) for ep in self.eps()], constraints=([_hcons(hc) for hc in self.hcons()] + [_icons(ic) for ic in self.icons()]), variables={v: _var(v) for v in self.variables()} ) if self.top is not None: d['top'] = self.top if self.index is not None: d['index'] = self.index # if self.xarg is not None: d['xarg'] = self.xarg # if self.lnk is not None: d['lnk'] = self.lnk # if self.surface is not None: d['surface'] = self.surface # if self.identifier is not None: d['identifier'] = self.identifier return d
python
{ "resource": "" }
q8924
Dmrs.to_dict
train
def to_dict(self, short_pred=True, properties=True): """ Encode the Dmrs as a dictionary suitable for JSON serialization. """ qs = set(self.nodeids(quantifier=True)) def _lnk(obj): return {'from': obj.cfrom, 'to': obj.cto} def _node(node, short_pred=True): p = node.pred.short_form() if short_pred else node.pred.string d = dict(nodeid=node.nodeid, predicate=p) if node.lnk is not None: d['lnk'] = _lnk(node) if properties and node.sortinfo: if node.nodeid not in qs: d['sortinfo'] = node.sortinfo if node.surface is not None: d['surface'] = node.surface if node.base is not None: d['base'] = node.base if node.carg is not None: d['carg'] = node.carg return d def _link(link): return { 'from': link.start, 'to': link.end, 'rargname': link.rargname, 'post': link.post } d = dict( nodes=[_node(n) for n in nodes(self)], links=[_link(l) for l in links(self)] ) # if self.top is not None: ... currently handled by links if self.index is not None: idx = self.nodeid(self.index) if idx is not None: d['index'] = idx if self.xarg is not None: xarg = self.nodeid(self.index) if xarg is not None: d['index'] = xarg if self.lnk is not None: d['lnk'] = _lnk(self) if self.surface is not None: d['surface'] = self.surface if self.identifier is not None: d['identifier'] = self.identifier return d
python
{ "resource": "" }
q8925
Dmrs.to_triples
train
def to_triples(self, short_pred=True, properties=True): """ Encode the Dmrs as triples suitable for PENMAN serialization. """ ts = [] qs = set(self.nodeids(quantifier=True)) for n in nodes(self): pred = n.pred.short_form() if short_pred else n.pred.string ts.append((n.nodeid, 'predicate', pred)) if n.lnk is not None: ts.append((n.nodeid, 'lnk', '"{}"'.format(str(n.lnk)))) if n.carg is not None: ts.append((n.nodeid, 'carg', '"{}"'.format(n.carg))) if properties and n.nodeid not in qs: for key, value in n.sortinfo.items(): ts.append((n.nodeid, key.lower(), value)) for l in links(self): if safe_int(l.start) == LTOP_NODEID: ts.append((l.start, 'top', l.end)) else: relation = '{}-{}'.format(l.rargname.upper(), l.post) ts.append((l.start, relation, l.end)) return ts
python
{ "resource": "" }
q8926
Invoice.to_array
train
def to_array(self): """ Serializes this Invoice to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Invoice, self).to_array() array['title'] = u(self.title) # py2: type unicode, py3: type str array['description'] = u(self.description) # py2: type unicode, py3: type str array['start_parameter'] = u(self.start_parameter) # py2: type unicode, py3: type str array['currency'] = u(self.currency) # py2: type unicode, py3: type str array['total_amount'] = int(self.total_amount) # type int return array
python
{ "resource": "" }
q8927
ShippingAddress.to_array
train
def to_array(self): """ Serializes this ShippingAddress to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ShippingAddress, self).to_array() array['country_code'] = u(self.country_code) # py2: type unicode, py3: type str array['state'] = u(self.state) # py2: type unicode, py3: type str array['city'] = u(self.city) # py2: type unicode, py3: type str array['street_line1'] = u(self.street_line1) # py2: type unicode, py3: type str array['street_line2'] = u(self.street_line2) # py2: type unicode, py3: type str array['post_code'] = u(self.post_code) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8928
OrderInfo.to_array
train
def to_array(self): """ Serializes this OrderInfo to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(OrderInfo, self).to_array() if self.name is not None: array['name'] = u(self.name) # py2: type unicode, py3: type str if self.phone_number is not None: array['phone_number'] = u(self.phone_number) # py2: type unicode, py3: type str if self.email is not None: array['email'] = u(self.email) # py2: type unicode, py3: type str if self.shipping_address is not None: array['shipping_address'] = self.shipping_address.to_array() # type ShippingAddress return array
python
{ "resource": "" }
q8929
SuccessfulPayment.to_array
train
def to_array(self): """ Serializes this SuccessfulPayment to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(SuccessfulPayment, self).to_array() array['currency'] = u(self.currency) # py2: type unicode, py3: type str array['total_amount'] = int(self.total_amount) # type int array['invoice_payload'] = u(self.invoice_payload) # py2: type unicode, py3: type str array['telegram_payment_charge_id'] = u(self.telegram_payment_charge_id) # py2: type unicode, py3: type str array['provider_payment_charge_id'] = u(self.provider_payment_charge_id) # py2: type unicode, py3: type str if self.shipping_option_id is not None: array['shipping_option_id'] = u(self.shipping_option_id) # py2: type unicode, py3: type str if self.order_info is not None: array['order_info'] = self.order_info.to_array() # type OrderInfo return array
python
{ "resource": "" }
q8930
SuccessfulPayment.from_array
train
def from_array(array): """ Deserialize a new SuccessfulPayment from a given dictionary. :return: new SuccessfulPayment instance. :rtype: SuccessfulPayment """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['currency'] = u(array.get('currency')) data['total_amount'] = int(array.get('total_amount')) data['invoice_payload'] = u(array.get('invoice_payload')) data['telegram_payment_charge_id'] = u(array.get('telegram_payment_charge_id')) data['provider_payment_charge_id'] = u(array.get('provider_payment_charge_id')) data['shipping_option_id'] = u(array.get('shipping_option_id')) if array.get('shipping_option_id') is not None else None data['order_info'] = OrderInfo.from_array(array.get('order_info')) if array.get('order_info') is not None else None data['_raw'] = array return SuccessfulPayment(**data)
python
{ "resource": "" }
q8931
ShippingQuery.to_array
train
def to_array(self): """ Serializes this ShippingQuery to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ShippingQuery, self).to_array() array['id'] = u(self.id) # py2: type unicode, py3: type str array['from'] = self.from_peer.to_array() # type User array['invoice_payload'] = u(self.invoice_payload) # py2: type unicode, py3: type str array['shipping_address'] = self.shipping_address.to_array() # type ShippingAddress return array
python
{ "resource": "" }
q8932
ShippingQuery.from_array
train
def from_array(array): """ Deserialize a new ShippingQuery from a given dictionary. :return: new ShippingQuery instance. :rtype: ShippingQuery """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.peer import User data = {} data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['invoice_payload'] = u(array.get('invoice_payload')) data['shipping_address'] = ShippingAddress.from_array(array.get('shipping_address')) data['_raw'] = array return ShippingQuery(**data)
python
{ "resource": "" }
q8933
PreCheckoutQuery.to_array
train
def to_array(self): """ Serializes this PreCheckoutQuery to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(PreCheckoutQuery, self).to_array() array['id'] = u(self.id) # py2: type unicode, py3: type str array['from'] = self.from_peer.to_array() # type User array['currency'] = u(self.currency) # py2: type unicode, py3: type str array['total_amount'] = int(self.total_amount) # type int array['invoice_payload'] = u(self.invoice_payload) # py2: type unicode, py3: type str if self.shipping_option_id is not None: array['shipping_option_id'] = u(self.shipping_option_id) # py2: type unicode, py3: type str if self.order_info is not None: array['order_info'] = self.order_info.to_array() # type OrderInfo return array
python
{ "resource": "" }
q8934
PreCheckoutQuery.from_array
train
def from_array(array): """ Deserialize a new PreCheckoutQuery from a given dictionary. :return: new PreCheckoutQuery instance. :rtype: PreCheckoutQuery """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.peer import User data = {} data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['currency'] = u(array.get('currency')) data['total_amount'] = int(array.get('total_amount')) data['invoice_payload'] = u(array.get('invoice_payload')) data['shipping_option_id'] = u(array.get('shipping_option_id')) if array.get('shipping_option_id') is not None else None data['order_info'] = OrderInfo.from_array(array.get('order_info')) if array.get('order_info') is not None else None data['_raw'] = array return PreCheckoutQuery(**data)
python
{ "resource": "" }
q8935
InputMediaPhoto.to_array
train
def to_array(self): """ Serializes this InputMediaPhoto to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InputMediaPhoto, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['media'] = u(self.media) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8936
dump
train
def dump(destination, ms, single=False, pretty_print=False, **kwargs): """ Serialize Xmrs objects to the Prolog representation and write to a file. Args: destination: filename or file object where data will be written ms: an iterator of Xmrs objects to serialize (unless the *single* option is `True`) single: if `True`, treat *ms* as a single Xmrs object instead of as an iterator pretty_print: if `True`, add newlines and indentation """ text = dumps(ms, single=single, pretty_print=pretty_print, **kwargs) if hasattr(destination, 'write'): print(text, file=destination) else: with open(destination, 'w') as fh: print(text, file=fh)
python
{ "resource": "" }
q8937
dumps
train
def dumps(ms, single=False, pretty_print=False, **kwargs): """ Serialize an Xmrs object to the Prolog representation Args: ms: an iterator of Xmrs objects to serialize (unless the *single* option is `True`) single: if `True`, treat *ms* as a single Xmrs object instead of as an iterator pretty_print: if `True`, add newlines and indentation Returns: the Prolog string representation of a corpus of Xmrs """ if single: ms = [ms] return serialize(ms, pretty_print=pretty_print, **kwargs)
python
{ "resource": "" }
q8938
convert
train
def convert(path, source_fmt, target_fmt, select='result:mrs', properties=True, show_status=False, predicate_modifiers=False, color=False, pretty_print=False, indent=None): """ Convert between various DELPH-IN Semantics representations. Args: path (str, file): filename, testsuite directory, open file, or stream of input representations source_fmt (str): convert from this format target_fmt (str): convert to this format select (str): TSQL query for selecting data (ignored if *path* is not a testsuite directory; default: `"result:mrs"`) properties (bool): include morphosemantic properties if `True` (default: `True`) show_status (bool): show disconnected EDS nodes (ignored if *target_fmt* is not `"eds"`; default: `False`) predicate_modifiers (bool): apply EDS predicate modification for certain kinds of patterns (ignored if *target_fmt* is not an EDS format; default: `False`) color (bool): apply syntax highlighting if `True` and *target_fmt* is `"simplemrs"` (default: `False`) pretty_print (bool): if `True`, format the output with newlines and default indentation (default: `False`) indent (int, optional): specifies an explicit number of spaces for indentation (implies *pretty_print*) Returns: str: the converted representation """ if source_fmt.startswith('eds') and not target_fmt.startswith('eds'): raise ValueError( 'Conversion from EDS to non-EDS currently not supported.') if indent: pretty_print = True indent = 4 if indent is True else safe_int(indent) if len(tsql.inspect_query('select ' + select)['projection']) != 1: raise ValueError('Exactly 1 column must be given in selection query: ' '(e.g., result:mrs)') # read loads = _get_codec(source_fmt) if path is None: xs = loads(sys.stdin.read()) elif hasattr(path, 'read'): xs = loads(path.read()) elif os.path.isdir(path): ts = itsdb.TestSuite(path) xs = [ next(iter(loads(r[0])), None) for r in tsql.select(select, ts) ] else: xs = loads(open(path, 'r').read()) # write dumps = _get_codec(target_fmt, load=False) kwargs = {} if color: kwargs['color'] = color if pretty_print: kwargs['pretty_print'] = pretty_print if indent: kwargs['indent'] = indent if target_fmt == 'eds': kwargs['pretty_print'] = pretty_print kwargs['show_status'] = show_status if target_fmt.startswith('eds'): kwargs['predicate_modifiers'] = predicate_modifiers kwargs['properties'] = properties # this is not a great way to improve robustness when converting # many representations, but it'll do until v1.0.0. Also, it only # improves robustness on the output, not the input. # Note that all the code below is to replace the following: # return dumps(xs, **kwargs) head, joiner, tail = _get_output_details(target_fmt) parts = [] if pretty_print: joiner = joiner.strip() + '\n' def _trim(s): if head and s.startswith(head): s = s[len(head):].lstrip('\n') if tail and s.endswith(tail): s = s[:-len(tail)].rstrip('\n') return s for x in xs: try: s = dumps([x], **kwargs) except (PyDelphinException, KeyError, IndexError): logging.exception('could not convert representation') else: s = _trim(s) parts.append(s) # set these after so head and tail are used correctly in _trim if pretty_print: if head: head += '\n' if tail: tail = '\n' + tail return head + joiner.join(parts) + tail
python
{ "resource": "" }
q8939
non_argument_modifiers
train
def non_argument_modifiers(role='ARG1', only_connecting=True): """ Return a function that finds non-argument modifier dependencies. Args: role (str): the role that is assigned to the dependency only_connecting (bool): if `True`, only return dependencies that connect separate components in the basic dependencies; if `False`, all non-argument modifier dependencies are included Returns: a function with signature `func(xmrs, deps)` that returns a mapping of non-argument modifier dependencies Examples: The default function behaves like the LKB: >>> func = non_argument_modifiers() A variation is similar to DMRS's MOD/EQ links: >>> func = non_argument_modifiers(role="MOD", only_connecting=False) """ def func(xmrs, deps): edges = [] for src in deps: for _, tgt in deps[src]: edges.append((src, tgt)) components = _connected_components(xmrs.nodeids(), edges) ccmap = {} for i, component in enumerate(components): for n in component: ccmap[n] = i addl = {} if not only_connecting or len(components) > 1: lsh = xmrs.labelset_heads lblheads = {v: lsh(v) for v, vd in xmrs._vars.items() if 'LBL' in vd['refs']} for heads in lblheads.values(): if len(heads) > 1: first = heads[0] joined = set([ccmap[first]]) for other in heads[1:]: occ = ccmap[other] srt = var_sort(xmrs.args(other).get(role, 'u0')) needs_edge = not only_connecting or occ not in joined edge_available = srt == 'u' if needs_edge and edge_available: addl.setdefault(other, []).append((role, first)) joined.add(occ) return addl return func
python
{ "resource": "" }
q8940
dumps
train
def dumps(ms, single=False, properties=False, pretty_print=True, show_status=False, predicate_modifiers=False, **kwargs): """ Serialize an Xmrs object to a Eds representation Args: ms: an iterator of :class:`~delphin.mrs.xmrs.Xmrs` objects to serialize (unless the *single* option is `True`) single (bool): if `True`, treat *ms* as a single :class:`~delphin.mrs.xmrs.Xmrs` object instead of as an iterator properties (bool): if `False`, suppress variable properties pretty_print (bool): if `True`, add newlines and indentation show_status (bool): if `True`, annotate disconnected graphs and nodes Returns: an :class:`Eds` string representation of a corpus of Xmrs """ if not pretty_print and kwargs.get('indent'): pretty_print = True if single: ms = [ms] return serialize( ms, properties=properties, pretty_print=pretty_print, show_status=show_status, predicate_modifiers=predicate_modifiers, **kwargs )
python
{ "resource": "" }
q8941
Eds.nodes
train
def nodes(self): """Return the list of nodes.""" getnode = self._nodes.__getitem__ return [getnode(nid) for nid in self._nodeids]
python
{ "resource": "" }
q8942
Eds.to_dict
train
def to_dict(self, properties=True): """ Encode the Eds as a dictionary suitable for JSON serialization. """ nodes = {} for node in self.nodes(): nd = { 'label': node.pred.short_form(), 'edges': self.edges(node.nodeid) } if node.lnk is not None: nd['lnk'] = {'from': node.cfrom, 'to': node.cto} if properties: if node.cvarsort is not None: nd['type'] = node.cvarsort props = node.properties if props: nd['properties'] = props if node.carg is not None: nd['carg'] = node.carg nodes[node.nodeid] = nd return {'top': self.top, 'nodes': nodes}
python
{ "resource": "" }
q8943
Eds.to_triples
train
def to_triples(self, short_pred=True, properties=True): """ Encode the Eds as triples suitable for PENMAN serialization. """ node_triples, edge_triples = [], [] # sort nodeids just so top var is first nodes = sorted(self.nodes(), key=lambda n: n.nodeid != self.top) for node in nodes: nid = node.nodeid pred = node.pred.short_form() if short_pred else node.pred.string node_triples.append((nid, 'predicate', pred)) if node.lnk: node_triples.append((nid, 'lnk', '"{}"'.format(str(node.lnk)))) if node.carg: node_triples.append((nid, 'carg', '"{}"'.format(node.carg))) if properties: if node.cvarsort is not None: node_triples.append((nid, 'type', node.cvarsort)) props = node.properties node_triples.extend((nid, p, v) for p, v in props.items()) edge_triples.extend( (nid, rargname, tgt) for rargname, tgt in sorted( self.edges(nid).items(), key=lambda x: rargname_sortkey(x[0]) ) ) return node_triples + edge_triples
python
{ "resource": "" }
q8944
LookaheadIterator.next
train
def next(self, skip=None): """ Remove the next datum from the buffer and return it. """ buffer = self._buffer popleft = buffer.popleft if skip is not None: while True: try: if not skip(buffer[0]): break popleft() except IndexError: self._buffer_fill() try: datum = popleft() except IndexError: self._buffer_fill() datum = popleft() return datum
python
{ "resource": "" }
q8945
InlineQueryResultPhoto.to_array
train
def to_array(self): """ Serializes this InlineQueryResultPhoto to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultPhoto, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['photo_url'] = u(self.photo_url) # py2: type unicode, py3: type str array['thumb_url'] = u(self.thumb_url) # py2: type unicode, py3: type str if self.photo_width is not None: array['photo_width'] = int(self.photo_width) # type int if self.photo_height is not None: array['photo_height'] = int(self.photo_height) # type int if self.title is not None: array['title'] = u(self.title) # py2: type unicode, py3: type str if self.description is not None: array['description'] = u(self.description) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8946
InlineQueryResultMpeg4Gif.to_array
train
def to_array(self): """ Serializes this InlineQueryResultMpeg4Gif to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultMpeg4Gif, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['mpeg4_url'] = u(self.mpeg4_url) # py2: type unicode, py3: type str array['thumb_url'] = u(self.thumb_url) # py2: type unicode, py3: type str if self.mpeg4_width is not None: array['mpeg4_width'] = int(self.mpeg4_width) # type int if self.mpeg4_height is not None: array['mpeg4_height'] = int(self.mpeg4_height) # type int if self.mpeg4_duration is not None: array['mpeg4_duration'] = int(self.mpeg4_duration) # type int if self.title is not None: array['title'] = u(self.title) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8947
InlineQueryResultVideo.to_array
train
def to_array(self): """ Serializes this InlineQueryResultVideo to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultVideo, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['video_url'] = u(self.video_url) # py2: type unicode, py3: type str array['mime_type'] = u(self.mime_type) # py2: type unicode, py3: type str array['thumb_url'] = u(self.thumb_url) # py2: type unicode, py3: type str array['title'] = u(self.title) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.video_width is not None: array['video_width'] = int(self.video_width) # type int if self.video_height is not None: array['video_height'] = int(self.video_height) # type int if self.video_duration is not None: array['video_duration'] = int(self.video_duration) # type int if self.description is not None: array['description'] = u(self.description) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8948
InlineQueryResultVoice.to_array
train
def to_array(self): """ Serializes this InlineQueryResultVoice to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultVoice, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['voice_url'] = u(self.voice_url) # py2: type unicode, py3: type str array['title'] = u(self.title) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.voice_duration is not None: array['voice_duration'] = int(self.voice_duration) # type int if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8949
InlineQueryResultDocument.to_array
train
def to_array(self): """ Serializes this InlineQueryResultDocument to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultDocument, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['title'] = u(self.title) # py2: type unicode, py3: type str array['document_url'] = u(self.document_url) # py2: type unicode, py3: type str array['mime_type'] = u(self.mime_type) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.description is not None: array['description'] = u(self.description) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent if self.thumb_url is not None: array['thumb_url'] = u(self.thumb_url) # py2: type unicode, py3: type str if self.thumb_width is not None: array['thumb_width'] = int(self.thumb_width) # type int if self.thumb_height is not None: array['thumb_height'] = int(self.thumb_height) # type int return array
python
{ "resource": "" }
q8950
InlineQueryResultVenue.to_array
train
def to_array(self): """ Serializes this InlineQueryResultVenue to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultVenue, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['latitude'] = float(self.latitude) # type float array['longitude'] = float(self.longitude) # type float array['title'] = u(self.title) # py2: type unicode, py3: type str array['address'] = u(self.address) # py2: type unicode, py3: type str if self.foursquare_id is not None: array['foursquare_id'] = u(self.foursquare_id) # py2: type unicode, py3: type str if self.foursquare_type is not None: array['foursquare_type'] = u(self.foursquare_type) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent if self.thumb_url is not None: array['thumb_url'] = u(self.thumb_url) # py2: type unicode, py3: type str if self.thumb_width is not None: array['thumb_width'] = int(self.thumb_width) # type int if self.thumb_height is not None: array['thumb_height'] = int(self.thumb_height) # type int return array
python
{ "resource": "" }
q8951
InlineQueryResultCachedPhoto.to_array
train
def to_array(self): """ Serializes this InlineQueryResultCachedPhoto to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultCachedPhoto, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['photo_file_id'] = u(self.photo_file_id) # py2: type unicode, py3: type str if self.title is not None: array['title'] = u(self.title) # py2: type unicode, py3: type str if self.description is not None: array['description'] = u(self.description) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8952
InlineQueryResultCachedMpeg4Gif.to_array
train
def to_array(self): """ Serializes this InlineQueryResultCachedMpeg4Gif to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultCachedMpeg4Gif, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['mpeg4_file_id'] = u(self.mpeg4_file_id) # py2: type unicode, py3: type str if self.title is not None: array['title'] = u(self.title) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8953
InlineQueryResultCachedSticker.to_array
train
def to_array(self): """ Serializes this InlineQueryResultCachedSticker to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultCachedSticker, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['sticker_file_id'] = u(self.sticker_file_id) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8954
InlineQueryResultCachedVideo.to_array
train
def to_array(self): """ Serializes this InlineQueryResultCachedVideo to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultCachedVideo, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['video_file_id'] = u(self.video_file_id) # py2: type unicode, py3: type str array['title'] = u(self.title) # py2: type unicode, py3: type str if self.description is not None: array['description'] = u(self.description) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8955
InlineQueryResultCachedAudio.to_array
train
def to_array(self): """ Serializes this InlineQueryResultCachedAudio to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQueryResultCachedAudio, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['id'] = u(self.id) # py2: type unicode, py3: type str array['audio_file_id'] = u(self.audio_file_id) # py2: type unicode, py3: type str if self.caption is not None: array['caption'] = u(self.caption) # py2: type unicode, py3: type str if self.parse_mode is not None: array['parse_mode'] = u(self.parse_mode) # py2: type unicode, py3: type str if self.reply_markup is not None: array['reply_markup'] = self.reply_markup.to_array() # type InlineKeyboardMarkup if self.input_message_content is not None: array['input_message_content'] = self.input_message_content.to_array() # type InputMessageContent return array
python
{ "resource": "" }
q8956
MessageEntity.to_array
train
def to_array(self): """ Serializes this MessageEntity to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(MessageEntity, self).to_array() array['type'] = u(self.type) # py2: type unicode, py3: type str array['offset'] = int(self.offset) # type int array['length'] = int(self.length) # type int if self.url is not None: array['url'] = u(self.url) # py2: type unicode, py3: type str if self.user is not None: array['user'] = self.user.to_array() # type User return array
python
{ "resource": "" }
q8957
PhotoSize.to_array
train
def to_array(self): """ Serializes this PhotoSize to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(PhotoSize, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str array['width'] = int(self.width) # type int array['height'] = int(self.height) # type int if self.file_size is not None: array['file_size'] = int(self.file_size) # type int return array
python
{ "resource": "" }
q8958
Audio.to_array
train
def to_array(self): """ Serializes this Audio to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Audio, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str array['duration'] = int(self.duration) # type int if self.performer is not None: array['performer'] = u(self.performer) # py2: type unicode, py3: type str if self.title is not None: array['title'] = u(self.title) # py2: type unicode, py3: type str if self.mime_type is not None: array['mime_type'] = u(self.mime_type) # py2: type unicode, py3: type str if self.file_size is not None: array['file_size'] = int(self.file_size) # type int if self.thumb is not None: array['thumb'] = self.thumb.to_array() # type PhotoSize return array
python
{ "resource": "" }
q8959
Audio.from_array
train
def from_array(array): """ Deserialize a new Audio from a given dictionary. :return: new Audio instance. :rtype: Audio """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.media import PhotoSize data = {} data['file_id'] = u(array.get('file_id')) data['duration'] = int(array.get('duration')) data['performer'] = u(array.get('performer')) if array.get('performer') is not None else None data['title'] = u(array.get('title')) if array.get('title') is not None else None data['mime_type'] = u(array.get('mime_type')) if array.get('mime_type') is not None else None data['file_size'] = int(array.get('file_size')) if array.get('file_size') is not None else None data['thumb'] = PhotoSize.from_array(array.get('thumb')) if array.get('thumb') is not None else None data['_raw'] = array return Audio(**data)
python
{ "resource": "" }
q8960
Document.to_array
train
def to_array(self): """ Serializes this Document to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Document, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str if self.thumb is not None: array['thumb'] = self.thumb.to_array() # type PhotoSize if self.file_name is not None: array['file_name'] = u(self.file_name) # py2: type unicode, py3: type str if self.mime_type is not None: array['mime_type'] = u(self.mime_type) # py2: type unicode, py3: type str if self.file_size is not None: array['file_size'] = int(self.file_size) # type int return array
python
{ "resource": "" }
q8961
Animation.to_array
train
def to_array(self): """ Serializes this Animation to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Animation, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str array['width'] = int(self.width) # type int array['height'] = int(self.height) # type int array['duration'] = int(self.duration) # type int if self.thumb is not None: array['thumb'] = self.thumb.to_array() # type PhotoSize if self.file_name is not None: array['file_name'] = u(self.file_name) # py2: type unicode, py3: type str if self.mime_type is not None: array['mime_type'] = u(self.mime_type) # py2: type unicode, py3: type str if self.file_size is not None: array['file_size'] = int(self.file_size) # type int return array
python
{ "resource": "" }
q8962
Voice.to_array
train
def to_array(self): """ Serializes this Voice to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Voice, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str array['duration'] = int(self.duration) # type int if self.mime_type is not None: array['mime_type'] = u(self.mime_type) # py2: type unicode, py3: type str if self.file_size is not None: array['file_size'] = int(self.file_size) # type int return array
python
{ "resource": "" }
q8963
VideoNote.to_array
train
def to_array(self): """ Serializes this VideoNote to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(VideoNote, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str array['length'] = int(self.length) # type int array['duration'] = int(self.duration) # type int if self.thumb is not None: array['thumb'] = self.thumb.to_array() # type PhotoSize if self.file_size is not None: array['file_size'] = int(self.file_size) # type int return array
python
{ "resource": "" }
q8964
Contact.to_array
train
def to_array(self): """ Serializes this Contact to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Contact, self).to_array() array['phone_number'] = u(self.phone_number) # py2: type unicode, py3: type str array['first_name'] = u(self.first_name) # py2: type unicode, py3: type str if self.last_name is not None: array['last_name'] = u(self.last_name) # py2: type unicode, py3: type str if self.user_id is not None: array['user_id'] = int(self.user_id) # type int if self.vcard is not None: array['vcard'] = u(self.vcard) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8965
Location.to_array
train
def to_array(self): """ Serializes this Location to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Location, self).to_array() array['longitude'] = float(self.longitude) # type float array['latitude'] = float(self.latitude) # type float return array
python
{ "resource": "" }
q8966
Location.from_array
train
def from_array(array): """ Deserialize a new Location from a given dictionary. :return: new Location instance. :rtype: Location """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['longitude'] = float(array.get('longitude')) data['latitude'] = float(array.get('latitude')) data['_raw'] = array return Location(**data)
python
{ "resource": "" }
q8967
Venue.to_array
train
def to_array(self): """ Serializes this Venue to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Venue, self).to_array() array['location'] = self.location.to_array() # type Location array['title'] = u(self.title) # py2: type unicode, py3: type str array['address'] = u(self.address) # py2: type unicode, py3: type str if self.foursquare_id is not None: array['foursquare_id'] = u(self.foursquare_id) # py2: type unicode, py3: type str if self.foursquare_type is not None: array['foursquare_type'] = u(self.foursquare_type) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8968
UserProfilePhotos.to_array
train
def to_array(self): """ Serializes this UserProfilePhotos to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(UserProfilePhotos, self).to_array() array['total_count'] = int(self.total_count) # type int array['photos'] = self._as_array(self.photos) # type list of list of PhotoSize return array
python
{ "resource": "" }
q8969
File.to_array
train
def to_array(self): """ Serializes this File to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(File, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str if self.file_size is not None: array['file_size'] = int(self.file_size) # type int if self.file_path is not None: array['file_path'] = u(self.file_path) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8970
ChatPhoto.to_array
train
def to_array(self): """ Serializes this ChatPhoto to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ChatPhoto, self).to_array() array['small_file_id'] = u(self.small_file_id) # py2: type unicode, py3: type str array['big_file_id'] = u(self.big_file_id) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8971
Sticker.to_array
train
def to_array(self): """ Serializes this Sticker to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Sticker, self).to_array() array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str array['width'] = int(self.width) # type int array['height'] = int(self.height) # type int if self.thumb is not None: array['thumb'] = self.thumb.to_array() # type PhotoSize if self.emoji is not None: array['emoji'] = u(self.emoji) # py2: type unicode, py3: type str if self.set_name is not None: array['set_name'] = u(self.set_name) # py2: type unicode, py3: type str if self.mask_position is not None: array['mask_position'] = self.mask_position.to_array() # type MaskPosition if self.file_size is not None: array['file_size'] = int(self.file_size) # type int return array
python
{ "resource": "" }
q8972
Game.to_array
train
def to_array(self): """ Serializes this Game to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(Game, self).to_array() array['title'] = u(self.title) # py2: type unicode, py3: type str array['description'] = u(self.description) # py2: type unicode, py3: type str array['photo'] = self._as_array(self.photo) # type list of PhotoSize if self.text is not None: array['text'] = u(self.text) # py2: type unicode, py3: type str if self.text_entities is not None: array['text_entities'] = self._as_array(self.text_entities) # type list of MessageEntity if self.animation is not None: array['animation'] = self.animation.to_array() # type Animation return array
python
{ "resource": "" }
q8973
VideoNote.from_array
train
def from_array(array): """ Deserialize a new VideoNote from a given dictionary. :return: new VideoNote instance. :rtype: VideoNote """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['file_id'] = u(array.get('file_id')) data['length'] = int(array.get('length')) data['duration'] = int(array.get('duration')) data['thumb'] = PhotoSize.from_array(array.get('thumb')) if array.get('thumb') is not None else None data['file_size'] = int(array.get('file_size')) if array.get('file_size') is not None else None data['_raw'] = array return VideoNote(**data)
python
{ "resource": "" }
q8974
ReplyKeyboardMarkup.to_array
train
def to_array(self): """ Serializes this ReplyKeyboardMarkup to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ReplyKeyboardMarkup, self).to_array() array['keyboard'] = self._as_array(self.keyboard) # type list of list of KeyboardButton if self.resize_keyboard is not None: array['resize_keyboard'] = bool(self.resize_keyboard) # type bool if self.one_time_keyboard is not None: array['one_time_keyboard'] = bool(self.one_time_keyboard) # type bool if self.selective is not None: array['selective'] = bool(self.selective) # type bool return array
python
{ "resource": "" }
q8975
KeyboardButton.to_array
train
def to_array(self): """ Serializes this KeyboardButton to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(KeyboardButton, self).to_array() array['text'] = u(self.text) # py2: type unicode, py3: type str if self.request_contact is not None: array['request_contact'] = bool(self.request_contact) # type bool if self.request_location is not None: array['request_location'] = bool(self.request_location) # type bool return array
python
{ "resource": "" }
q8976
KeyboardButton.from_array
train
def from_array(array): """ Deserialize a new KeyboardButton from a given dictionary. :return: new KeyboardButton instance. :rtype: KeyboardButton """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['text'] = u(array.get('text')) data['request_contact'] = bool(array.get('request_contact')) if array.get('request_contact') is not None else None data['request_location'] = bool(array.get('request_location')) if array.get('request_location') is not None else None instance = KeyboardButton(**data) instance._raw = array return instance
python
{ "resource": "" }
q8977
ReplyKeyboardRemove.to_array
train
def to_array(self): """ Serializes this ReplyKeyboardRemove to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ReplyKeyboardRemove, self).to_array() array['remove_keyboard'] = bool(self.remove_keyboard) # type bool if self.selective is not None: array['selective'] = bool(self.selective) # type bool return array
python
{ "resource": "" }
q8978
InlineKeyboardMarkup.to_array
train
def to_array(self): """ Serializes this InlineKeyboardMarkup to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineKeyboardMarkup, self).to_array() array['inline_keyboard'] = self._as_array(self.inline_keyboard) # type list of list of InlineKeyboardButton return array
python
{ "resource": "" }
q8979
InlineKeyboardButton.to_array
train
def to_array(self): """ Serializes this InlineKeyboardButton to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineKeyboardButton, self).to_array() array['text'] = u(self.text) # py2: type unicode, py3: type str if self.url is not None: array['url'] = u(self.url) # py2: type unicode, py3: type str if self.callback_data is not None: array['callback_data'] = u(self.callback_data) # py2: type unicode, py3: type str if self.switch_inline_query is not None: array['switch_inline_query'] = u(self.switch_inline_query) # py2: type unicode, py3: type str if self.switch_inline_query_current_chat is not None: array['switch_inline_query_current_chat'] = u(self.switch_inline_query_current_chat) # py2: type unicode, py3: type str if self.callback_game is not None: array['callback_game'] = self.callback_game.to_array() # type CallbackGame if self.pay is not None: array['pay'] = bool(self.pay) # type bool return array
python
{ "resource": "" }
q8980
InlineKeyboardButton.from_array
train
def from_array(array): """ Deserialize a new InlineKeyboardButton from a given dictionary. :return: new InlineKeyboardButton instance. :rtype: InlineKeyboardButton """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.updates import CallbackGame data = {} data['text'] = u(array.get('text')) data['url'] = u(array.get('url')) if array.get('url') is not None else None data['callback_data'] = u(array.get('callback_data')) if array.get('callback_data') is not None else None data['switch_inline_query'] = u(array.get('switch_inline_query')) if array.get('switch_inline_query') is not None else None data['switch_inline_query_current_chat'] = u(array.get('switch_inline_query_current_chat')) if array.get('switch_inline_query_current_chat') is not None else None data['callback_game'] = CallbackGame.from_array(array.get('callback_game')) if array.get('callback_game') is not None else None data['pay'] = bool(array.get('pay')) if array.get('pay') is not None else None instance = InlineKeyboardButton(**data) instance._raw = array return instance
python
{ "resource": "" }
q8981
ForceReply.to_array
train
def to_array(self): """ Serializes this ForceReply to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ForceReply, self).to_array() array['force_reply'] = bool(self.force_reply) # type bool if self.selective is not None: array['selective'] = bool(self.selective) # type bool return array
python
{ "resource": "" }
q8982
ForceReply.from_array
train
def from_array(array): """ Deserialize a new ForceReply from a given dictionary. :return: new ForceReply instance. :rtype: ForceReply """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['force_reply'] = bool(array.get('force_reply')) data['selective'] = bool(array.get('selective')) if array.get('selective') is not None else None instance = ForceReply(**data) instance._raw = array return instance
python
{ "resource": "" }
q8983
PassportElementErrorDataField.to_array
train
def to_array(self): """ Serializes this PassportElementErrorDataField to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(PassportElementErrorDataField, self).to_array() array['source'] = u(self.source) # py2: type unicode, py3: type str array['type'] = u(self.type) # py2: type unicode, py3: type str array['field_name'] = u(self.field_name) # py2: type unicode, py3: type str array['data_hash'] = u(self.data_hash) # py2: type unicode, py3: type str array['message'] = u(self.message) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8984
PassportElementErrorReverseSide.to_array
train
def to_array(self): """ Serializes this PassportElementErrorReverseSide to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(PassportElementErrorReverseSide, self).to_array() array['source'] = u(self.source) # py2: type unicode, py3: type str array['type'] = u(self.type) # py2: type unicode, py3: type str array['file_hash'] = u(self.file_hash) # py2: type unicode, py3: type str array['message'] = u(self.message) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8985
PassportElementErrorFiles.to_array
train
def to_array(self): """ Serializes this PassportElementErrorFiles to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(PassportElementErrorFiles, self).to_array() array['source'] = u(self.source) # py2: type unicode, py3: type str array['type'] = u(self.type) # py2: type unicode, py3: type str array['file_hashes'] = self._as_array(self.file_hashes) # type list of str array['message'] = u(self.message) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8986
PassportElementErrorFiles.from_array
train
def from_array(array): """ Deserialize a new PassportElementErrorFiles from a given dictionary. :return: new PassportElementErrorFiles instance. :rtype: PassportElementErrorFiles """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['source'] = u(array.get('source')) data['type'] = u(array.get('type')) data['file_hashes'] = PassportElementErrorFiles._builtin_from_array_list(required_type=unicode_type, value=array.get('file_hashes'), list_level=1) data['message'] = u(array.get('message')) instance = PassportElementErrorFiles(**data) instance._raw = array return instance
python
{ "resource": "" }
q8987
PassportElementErrorUnspecified.to_array
train
def to_array(self): """ Serializes this PassportElementErrorUnspecified to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(PassportElementErrorUnspecified, self).to_array() array['source'] = u(self.source) # py2: type unicode, py3: type str array['type'] = u(self.type) # py2: type unicode, py3: type str array['element_hash'] = u(self.element_hash) # py2: type unicode, py3: type str array['message'] = u(self.message) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8988
PassportElementErrorUnspecified.from_array
train
def from_array(array): """ Deserialize a new PassportElementErrorUnspecified from a given dictionary. :return: new PassportElementErrorUnspecified instance. :rtype: PassportElementErrorUnspecified """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") data = {} data['source'] = u(array.get('source')) data['type'] = u(array.get('type')) data['element_hash'] = u(array.get('element_hash')) data['message'] = u(array.get('message')) instance = PassportElementErrorUnspecified(**data) instance._raw = array return instance
python
{ "resource": "" }
q8989
InlineQuery.to_array
train
def to_array(self): """ Serializes this InlineQuery to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(InlineQuery, self).to_array() array['id'] = u(self.id) # py2: type unicode, py3: type str array['from'] = self.from_peer.to_array() # type User array['query'] = u(self.query) # py2: type unicode, py3: type str array['offset'] = u(self.offset) # py2: type unicode, py3: type str if self.location is not None: array['location'] = self.location.to_array() # type Location return array
python
{ "resource": "" }
q8990
InlineQuery.from_array
train
def from_array(array): """ Deserialize a new InlineQuery from a given dictionary. :return: new InlineQuery instance. :rtype: InlineQuery """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.media import Location from pytgbot.api_types.receivable.peer import User data = {} data['id'] = u(array.get('id')) data['from_peer'] = User.from_array(array.get('from')) data['query'] = u(array.get('query')) data['offset'] = u(array.get('offset')) data['location'] = Location.from_array(array.get('location')) if array.get('location') is not None else None data['_raw'] = array return InlineQuery(**data)
python
{ "resource": "" }
q8991
ChosenInlineResult.to_array
train
def to_array(self): """ Serializes this ChosenInlineResult to a dictionary. :return: dictionary representation of this object. :rtype: dict """ array = super(ChosenInlineResult, self).to_array() array['result_id'] = u(self.result_id) # py2: type unicode, py3: type str array['from'] = self.from_peer.to_array() # type User array['query'] = u(self.query) # py2: type unicode, py3: type str if self.location is not None: array['location'] = self.location.to_array() # type Location if self.inline_message_id is not None: array['inline_message_id'] = u(self.inline_message_id) # py2: type unicode, py3: type str return array
python
{ "resource": "" }
q8992
ChosenInlineResult.from_array
train
def from_array(array): """ Deserialize a new ChosenInlineResult from a given dictionary. :return: new ChosenInlineResult instance. :rtype: ChosenInlineResult """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from ..receivable.media import Location from ..receivable.peer import User data = {} data['result_id'] = u(array.get('result_id')) data['from_peer'] = User.from_array(array.get('from')) data['query'] = u(array.get('query')) data['location'] = Location.from_array(array.get('location')) if array.get('location') is not None else None data['inline_message_id'] = u(array.get('inline_message_id')) if array.get('inline_message_id') is not None else None data['_raw'] = array return ChosenInlineResult(**data)
python
{ "resource": "" }
q8993
Update.from_array
train
def from_array(array): """ Deserialize a new Update from a given dictionary. :return: new Update instance. :rtype: Update """ if array is None or not array: return None # end if assert_type_or_raise(array, dict, parameter_name="array") from pytgbot.api_types.receivable.inline import ChosenInlineResult from pytgbot.api_types.receivable.inline import InlineQuery from pytgbot.api_types.receivable.payments import PreCheckoutQuery from pytgbot.api_types.receivable.payments import ShippingQuery from pytgbot.api_types.receivable.updates import CallbackQuery from pytgbot.api_types.receivable.updates import Message data = {} data['update_id'] = int(array.get('update_id')) data['message'] = Message.from_array(array.get('message')) if array.get('message') is not None else None data['edited_message'] = Message.from_array(array.get('edited_message')) if array.get('edited_message') is not None else None data['channel_post'] = Message.from_array(array.get('channel_post')) if array.get('channel_post') is not None else None data['edited_channel_post'] = Message.from_array(array.get('edited_channel_post')) if array.get('edited_channel_post') is not None else None data['inline_query'] = InlineQuery.from_array(array.get('inline_query')) if array.get('inline_query') is not None else None data['chosen_inline_result'] = ChosenInlineResult.from_array(array.get('chosen_inline_result')) if array.get('chosen_inline_result') is not None else None data['callback_query'] = CallbackQuery.from_array(array.get('callback_query')) if array.get('callback_query') is not None else None data['shipping_query'] = ShippingQuery.from_array(array.get('shipping_query')) if array.get('shipping_query') is not None else None data['pre_checkout_query'] = PreCheckoutQuery.from_array(array.get('pre_checkout_query')) if array.get('pre_checkout_query') is not None else None data['_raw'] = array return Update(**data)
python
{ "resource": "" }
q8994
YyToken.to_dict
train
def to_dict(self): """ Encode the token as a dictionary suitable for JSON serialization. """ d = { 'id': self.id, 'start': self.start, 'end': self.end, 'form': self.form } if self.lnk is not None: cfrom, cto = self.lnk.data d['from'] = cfrom d['to'] = cto # d['paths'] = self.paths if self.surface is not None: d['surface'] = self.surface # d['ipos'] = self.ipos # d['lrules'] = self.lrules if self.pos: d['tags'] = [ps[0] for ps in self.pos] d['probabilities'] = [ps[1] for ps in self.pos] return d
python
{ "resource": "" }
q8995
YyTokenLattice.from_string
train
def from_string(cls, s): """ Decode from the YY token lattice format. """ def _qstrip(s): return s[1:-1] # remove assumed quote characters tokens = [] for match in _yy_re.finditer(s): d = match.groupdict() lnk, pos = None, [] if d['lnkfrom'] is not None: lnk = Lnk.charspan(d['lnkfrom'], d['lnkto']) if d['pos'] is not None: ps = d['pos'].strip().split() pos = list(zip(map(_qstrip, ps[::2]), map(float, ps[1::2]))) tokens.append( YyToken( int(d['id']), int(d['start']), int(d['end']), lnk, list(map(int, d['paths'].strip().split())), _qstrip(d['form']), None if d['surface'] is None else _qstrip(d['surface']), int(d['ipos']), list(map(_qstrip, d['lrules'].strip().split())), pos ) ) return cls(tokens)
python
{ "resource": "" }
q8996
loads
train
def loads(s, single=False, version=_default_version, strict=False, errors='warn'): """ Deserialize SimpleMRS string representations Args: s (str): a SimpleMRS string single (bool): if `True`, only return the first Xmrs object Returns: a generator of Xmrs objects (unless *single* is `True`) """ ms = deserialize(s, version=version, strict=strict, errors=errors) if single: return next(ms) else: return ms
python
{ "resource": "" }
q8997
dumps
train
def dumps(ms, single=False, version=_default_version, properties=True, pretty_print=False, color=False, **kwargs): """ Serialize an Xmrs object to a SimpleMRS representation Args: ms: an iterator of Xmrs objects to serialize (unless the *single* option is `True`) single: if `True`, treat *ms* as a single Xmrs object instead of as an iterator properties: if `False`, suppress variable properties pretty_print: if `True`, add newlines and indentation color: if `True`, colorize the output with ANSI color codes Returns: a SimpleMrs string representation of a corpus of Xmrs """ if not pretty_print and kwargs.get('indent'): pretty_print = True if single: ms = [ms] return serialize(ms, version=version, properties=properties, pretty_print=pretty_print, color=color)
python
{ "resource": "" }
q8998
_read_lnk
train
def _read_lnk(tokens): """Read and return a tuple of the pred's lnk type and lnk value, if a pred lnk is specified.""" # < FROM : TO > or < FROM # TO > or < TOK... > or < @ EDGE > lnk = None if tokens[0] == '<': tokens.popleft() # we just checked this is a left angle if tokens[0] == '>': pass # empty <> brackets the same as no lnk specified # edge lnk: ['@', EDGE, ...] elif tokens[0] == '@': tokens.popleft() # remove the @ lnk = Lnk.edge(tokens.popleft()) # edge lnks only have one number # character span lnk: [FROM, ':', TO, ...] elif tokens[1] == ':': lnk = Lnk.charspan(tokens.popleft(), tokens[1]) tokens.popleft() # this should be the colon tokens.popleft() # and this is the cto # chart vertex range lnk: [FROM, '#', TO, ...] elif tokens[1] == '#': lnk = Lnk.chartspan(tokens.popleft(), tokens[1]) tokens.popleft() # this should be the hash tokens.popleft() # and this is the to vertex # tokens lnk: [(TOK,)+ ...] else: lnkdata = [] while tokens[0] != '>': lnkdata.append(int(tokens.popleft())) lnk = Lnk.tokens(lnkdata) _read_literals(tokens, '>') return lnk
python
{ "resource": "" }
q8999
serialize
train
def serialize(ms, version=_default_version, properties=True, pretty_print=False, color=False): """Serialize an MRS structure into a SimpleMRS string.""" delim = '\n' if pretty_print else _default_mrs_delim output = delim.join( _serialize_mrs(m, properties=properties, version=version, pretty_print=pretty_print) for m in ms ) if color: output = highlight(output) return output
python
{ "resource": "" }