Sridhar Nerur asked 1 year ago

The code example for topics extraction shown below works, but I would like to use a variable for the “text” parameter instead of embedding the string.
response =“”,
headers={“X-Mashape-Key”: “iqVgO6c7iTmshDHYFaEWN7uwrpRDp1o53UBjsnaQ4PUys6l063”, “Content-Type”: “application/json”,
“Accept”: “application/json”
params=(“{\”type\”:\”chunk\”,\”text\”:\”PARIS (Reuters) – Charlie Hebdo’s first edition ………\”}”))

Why can’t i just say: params={“type”: “chunk”, “text”: txt} where txt is a string variable? The example code for topics extraction is not consistent with the example in

Any help will be greatly appreciated.

2 Answers
kganes Staff answered 1 year ago

Hi Sridhar,
I am not sure I understand your question. The unirest example does use two parameters. If you look at the CURL example it would be much clearer:

curl -X POST --include '' \
-H 'X-Mashape-Key: key' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
--data-binary '{"type":"chunk","text":"PARIS (Reuters) - Charlie Hebdo's first edition since an attack by Islamist gunmen sold out within minutes on Wednesday, featuring a cartoon of the Prophet Mohammad on a cover that defenders praised as art but critics saw as a new provocation. French readers queued at dawn for copies to support the satirical newspaper, even as al Qaeda's branch in Yemen claimed responsibility for the attack last week, saying it ordered the killings because it deemed the weekly had insulted the Prophet."}'

Depending on the libraries you are using you might be able to achieve what you suggested using variables. Here is an example python code for the Sentence Clustering API in python. The parameters are quite similar to Topics Extraction:


kganes Staff answered 1 year ago


This is another example that uses variables in python to send the request: