Skip to content

Commit 3ab83e9

Browse files
committed
TableQA changes
1 parent aff8e23 commit 3ab83e9

File tree

150 files changed

+2050
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+2050
-355
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

example_Stemmer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from firstlanguage_python.firstlanguage_client import Client
2+
from firstlanguage_python.configuration import Environment
3+
import jsonpickle
4+
5+
6+
client = Client(
7+
apikey='63af276e-34fe-4fd5-a474-0c69847f25e1',
8+
environment=Environment.PRODUCTION,)
9+
10+
reqbody='{"input":{"text":"அவள் வேகமாக ஓடினாள்","lang":"ta"} }'
11+
12+
body = jsonpickle.decode(reqbody)
13+
basic_api_controller = client.basic_api
14+
15+
advanced_api_controller = client.advanced_api
16+
17+
result = basic_api_controller.get_stemmer(body)
18+
19+
for res in result:
20+
print("Original Text passed: "+res.orginal_text)
21+
print("Stemmed result: "+res.stem)
22+
23+
reqbody='{"input":{"text":"Welcome to Google and FirstLanguage","lang":"en"} }'
24+
25+
body = jsonpickle.decode(reqbody)
26+
27+
result = advanced_api_controller.get_translate(body)
28+
29+
print(result)

examples/example_Stemmer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@
1212
body = jsonpickle.decode(reqbody)
1313
basic_api_controller = client.basic_api
1414

15+
advanced_api_controller = client.advanced_api
16+
1517
result = basic_api_controller.get_stemmer(body)
1618

1719
for res in result:
1820
print("Original Text passed: "+res.orginal_text)
1921
print("Stemmed result: "+res.stem)
22+
23+
reqbody='{"input":{"text":"Welcome to Google and FirstLanguage","lang":"ta"} }'
24+
25+
body = jsonpickle.decode(reqbody)
26+
27+
result = advanced_api_controller.get_translate(body)
28+
29+
print(result)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

firstlanguage_python/api_helper.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
firstlanguage
4+
firstlanguage_python
55
66
This file was automatically generated by APIMATIC v3.0 (
77
https://www.apimatic.io ).
@@ -142,13 +142,14 @@ def get_schema_path(path):
142142
return path
143143

144144
@staticmethod
145-
def serialize_array(key, array, formatting="indexed"):
145+
def serialize_array(key, array, formatting="indexed", is_query=False):
146146
"""Converts an array parameter to a list of key value tuples.
147147
148148
Args:
149149
key (str): The name of the parameter.
150150
array (list): The value of the parameter.
151151
formatting (str): The type of key formatting expected.
152+
is_query (bool): Decides if the parameters are for query or form.
152153
153154
Returns:
154155
list: A list with key value tuples for the array elements.
@@ -168,6 +169,16 @@ def serialize_array(key, array, formatting="indexed"):
168169
tuples += [("{0}[{1}]".format(key, index), element) for index, element in enumerate(array)]
169170
elif formatting == "plain":
170171
tuples += [(key, element) for element in array]
172+
elif is_query:
173+
if formatting == "csv":
174+
tuples += [(key, ",".join(str(x) for x in array))]
175+
176+
elif formatting == "psv":
177+
tuples += [(key, "|".join(str(x) for x in array))]
178+
179+
elif formatting == "tsv":
180+
tuples += [(key, "\t".join(str(x) for x in array))]
181+
171182
else:
172183
raise ValueError("Invalid format provided.")
173184
else:
@@ -231,41 +242,25 @@ def append_url_with_query_parameters(url,
231242
raise ValueError("URL is None.")
232243
if parameters is None:
233244
return url
234-
235-
for key, value in parameters.items():
245+
parameters = APIHelper.process_complex_types_parameters(parameters, array_serialization)
246+
for index, value in enumerate(parameters):
247+
key = value[0]
248+
val = value[1]
236249
seperator = '&' if '?' in url else '?'
237250
if value is not None:
238-
if isinstance(value, list):
239-
value = [element for element in value if element]
240-
if array_serialization == "csv":
241-
url += "{0}{1}={2}".format(
242-
seperator,
243-
key,
244-
",".join(quote(str(x), safe='') for x in value)
245-
)
246-
elif array_serialization == "psv":
247-
url += "{0}{1}={2}".format(
248-
seperator,
249-
key,
250-
"|".join(quote(str(x), safe='') for x in value)
251-
)
252-
elif array_serialization == "tsv":
253-
url += "{0}{1}={2}".format(
254-
seperator,
255-
key,
256-
"\t".join(quote(str(x), safe='') for x in value)
257-
)
258-
else:
259-
url += "{0}{1}".format(
260-
seperator,
261-
"&".join(("{0}={1}".format(k, quote(str(v), safe='')))
262-
for k, v in APIHelper.serialize_array(key, value, array_serialization))
263-
)
264-
else:
265-
url += "{0}{1}={2}".format(seperator, key, quote(str(value), safe=''))
251+
url += "{0}{1}={2}".format(seperator, key, quote(str(val), safe=''))
266252

267253
return url
268254

255+
@staticmethod
256+
def process_complex_types_parameters(query_parameters, array_serialization):
257+
processed_params = []
258+
for key, value in query_parameters.items():
259+
processed_params.extend(
260+
APIHelper.form_encode(value, key, array_serialization=array_serialization, is_query=True))
261+
return processed_params
262+
263+
269264
@staticmethod
270265
def clean_url(url):
271266
"""Validates and processes the given query Url to clean empty slashes.
@@ -315,14 +310,15 @@ def form_encode_parameters(form_parameters,
315310
@staticmethod
316311
def form_encode(obj,
317312
instance_name,
318-
array_serialization="indexed"):
313+
array_serialization="indexed", is_query=False):
319314
"""Encodes a model in a form-encoded manner such as person[Name]
320315
321316
Args:
322317
obj (object): The given Object to form encode.
323318
instance_name (string): The base name to appear before each entry
324319
for this object.
325320
array_serialization (string): The format of array parameter serialization.
321+
is_query (bool): Decides if the parameters are for query or form.
326322
327323
Returns:
328324
dict: A dictionary of form encoded properties of the model.
@@ -336,11 +332,11 @@ def form_encode(obj,
336332
if obj is None:
337333
return []
338334
elif isinstance(obj, list):
339-
for element in APIHelper.serialize_array(instance_name, obj, array_serialization):
340-
retval += APIHelper.form_encode(element[1], element[0], array_serialization)
335+
for element in APIHelper.serialize_array(instance_name, obj, array_serialization, is_query):
336+
retval += APIHelper.form_encode(element[1], element[0], array_serialization, is_query)
341337
elif isinstance(obj, dict):
342338
for item in obj:
343-
retval += APIHelper.form_encode(obj[item], instance_name + "[" + item + "]", array_serialization)
339+
retval += APIHelper.form_encode(obj[item], instance_name + "[" + item + "]", array_serialization, is_query)
344340
else:
345341
retval.append((instance_name, obj))
346342

firstlanguage_python/configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
firstlanguage
4+
firstlanguage_python
55
66
This file was automatically generated by APIMATIC v3.0 (
77
https://www.apimatic.io ).
@@ -72,7 +72,7 @@ def __init__(
7272
backoff_factor=2,
7373
retry_statuses=[408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
7474
retry_methods=['GET', 'PUT'], environment=Environment.PRODUCTION,
75-
apikey='BHbLvTKeT4y9PACVomcGBF3GrCv1OUOc'
75+
apikey='TODO: Replace'
7676
):
7777
# The Http Client passed from the sdk user for making requests
7878
self._http_client_instance = http_client_instance
@@ -100,7 +100,7 @@ def __init__(
100100
# Current API environment
101101
self._environment = environment
102102

103-
# API Key can be copied from your dashboard
103+
# TODO: Replace
104104
self._apikey = apikey
105105

106106
# The Http Client to use for making requests.

firstlanguage_python/controllers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
'base_controller',
33
'basic_ap_is_controller',
44
'advanced_ap_is_controller',
5+
'enterprise_only_controller',
56
]

0 commit comments

Comments
 (0)