text_analytics = TextAnalyticsClient(endpoint=endpoint, credentials=credentials)
documents = [
{
"id": "1",
"language": "en",
"text": "I had the best day of my life."
}
]
response = text_analytics.sentiment(documents=documents)
for document in response.documents:
print("Document Id: ", document.id, ", Sentiment Score: ",
"{:.2f}".format(document.score))
Hi, with the sample code from API manual https://learn.microsoft.com/en-us/azure/cognitive-services/text-analytics/quickstarts/python-sdk#sentiment-analysis
I got the following error while trying to call the sentiment classifier
HttpOperationError Traceback (most recent call last)
<ipython-input-18-f0fb322c9e8c> in <module>
8 }
9 ]
---> 10 response = text_analytics.sentiment(documents=documents)
11 for document in response.documents:
12 print("Document Id: ", document.id, ", Sentiment Score: ",
~/anaconda3/envs/lib/python3.6/site-packages/azure/cognitiveservices/language/textanalytics/text_analytics_client.py in sentiment(self, show_stats, documents, custom_headers, raw, **operation_config)
361
362 if response.status_code not in [200, 500]:
--> 363 raise HttpOperationError(self._deserialize, response)
364
365 deserialized = None
HttpOperationError: Operation returned an invalid status code 'Resource Not Found'
It works for me on my side , pls follow or check the steps below to get started with python sentiment analysis SDK :
Create a text analysis service on Azure portal :
Once created , note its endpoint and either one of two keys.
Try the code below :
from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
from msrest.authentication import CognitiveServicesCredentials
subscriptionKey = "<your Azure servcice key >"
endpoint = "<your Azure servcice endpoint>"
credentials = CognitiveServicesCredentials(subscriptionKey)
text_analytics = TextAnalyticsClient(endpoint=endpoint, credentials=credentials)
documents = [
{
"id": "1",
"language": "en",
"text": "I had the best day of my life."
}
]
response = text_analytics.sentiment(documents=documents)
for document in response.documents:
print("Document Id: ", document.id, ", Sentiment Score: ",
"{:.2f}".format(document.score))
Result :
Hope it helps .
Related
Please help the below format to develop post meth web api to store the data into Database.
{
"jobcardID": "100023",
"breakdownID": "417217",
"vehicleNumber": "UP32GB4717",
"ODOmeter": 3023232,
" spareparts ":
[
{
"spItemCode": 231,
"spitemName": "Engine Oil",
"spitemCost": "234",
"spitemManhours": "2",
"spitemEstStartDTM ": "2021-06-04 12:32:59",
"spitemEstEndDTM": "2021-06-04 12:35:59"
},
{
"spItemCode": 342,
"spitemName": "Piston",
"spitemCost": "3450",
"spitemManhours": "5",
"spitemEstStartDTM ": "2021-06-04 12:32:59",
"spitemEstEndDTM": "2021-06-04 12:35:59"
}
]
" totalSpareCost":8000,
“totalLabourTime":”23hrs”,
“totalLabourCost":2000,
“TotalCost":10000,
“vehicleRecoveryTime":"2021-06-04 12:35:59",
}
I'm trying to define some docs in ES Painless Lab, to test some logic in Painless Lab, before running it on the actual index, but can't figure out how to do it, and the docs are not helping either. There is very little documentation on the actual syntax and it's not much help for someone with no Java background.
If I try to define a doc like this:
def docs = [{ "id": 1, "name": "Apple" }];
I get an error:
Unhandled Exception illegal_argument_exception
invalid sequence of tokens near ['{'].
Stack:
[
"def docs = [{ \"id\": 1, \"name\": \"Apple ...",
" ^---- HERE"
]
If I want to do it the Java way:
String message;
JSONObject json = new JSONObject();
json.put("test1", "value1");
message = json.toString();
I'm also getting an error:
Unhandled Exception illegal_argument_exception
invalid declaration: cannot resolve type [JSONObject]
Stack:
[
"... ring message;\nJSONObject json = new JSONObject();\n ...",
" ^---- HERE"
]
So what's the proper way to define an array of json objects to play with in Painless Lab?
After more experimenting, I found out that the docs can be passed in the parameters tab as:
{
"docs": [
{ "id": 1, "name": "Apple" },
{ "id": 2, "name": "Pear" },
{ "id": 3, "name": "Pineapple" }
]
}
and then access it from the code as
def doc = params.docs[1];
return doc["name"];
I'd be still interested how to define an object or array in the code itself.
There's been some changes made to the API since I used it last. This is the way I've successfully used it in the past:
if($host == 'youtube.com'){
/* Long YT link. It will be a GET var. */
parse_str("$query",$vidArray);
$ytStatusURL = 'https://www.googleapis.com/youtube/v3/videos?id='.$vidArray['v'].'&key=AIzaS...EQ5rN4czs&part=snippet';
$json = file_get_contents($ytStatusURL);
$obj = json_decode($json, true);
$ytStatus = $obj[pageInfo][totalResults];
if($ytStatus == '1'){
$embed_type = 'youtube';
$vid_string = substr($vidArray['v'], 0, 11);
$vidKey['a'] = $embed_type;
$vidKey['b'] = $vid_string;
return $vidKey;
}
}
Which now results in:
{
"error": {
"code": 403,
"message": "The request cannot be completed because you have exceeded your \u003ca href=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.",
"errors": [
{
"message": "The request cannot be completed because you have exceeded your \u003ca href=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.",
"domain": "youtube.quota",
"reason": "quotaExceeded"
}
]
}
}
So I went to check on how many requests have been made:
YouTube Data API v3 Requests: 3 Errors: 100 Latency: 49 Latency, 95%: 63
Either 3 requests is too many or something has changed to cause my api key to start failing and Google's not giving a ton of info on why.
I've followed all the provided links and Googled a bunch but I can't figure out why it's not working. What do I need to do to raise the API key to something more than zero allowed requests?
While importing the dashboard, API is not returning proper dashboard ID.
For all the dashboard ID it provides id as 0
If I check the dashboard using Chrome Devtools > Network tab, I'm able to get some id (in increment order).
What Grafana version are you using?
5.2.0-beta3 (previously using 5.1.4)
What datasource are you using?
InfluxDB
What OS are you running grafana on?
Windows 10 Pro
What did you do?
Imported the dashboard using Grafana API
What was the expected result?
Should be able to import the dashboard and as response it should return a dashboard ID
What happened instead?
Able to import the dashboard but not getting proper dashboard ID. For all dashboard it gives ID=0
import requests
url='http://admin:admin#localhost:3000/api/dashboards/import'
data='''{
"dashboard": {}
"folderId": 8,
"overwrite": false
}'''
headers={"Content-Type": 'application/json'}
response = requests.post(url, data=data,headers=headers)
print(response)
print(response.status_code)
print (response.text)
Response
Response [200]
200
{
"pluginId": "",
"title": "Template dfsad",
"imported": true,
"importedUri": "db/template-dfsad",
"importedUrl": "/d/uid1098/template-dfsad",
"slug": "",
"dashboardId": 0,
"folderId": 8,
"importedRevision": 1,
"revision": 1,
"description": "",
"path": "",
"removed": false
}
I'm trying to create a simple demo of how API Blueprint works with Apiary.io. For the demo, I wanted to put an endpoint from the Mashape Weather API into blueprint.
Here's the attempt:
http://docs.weatherapi3.apiary.io/#reference/weather/weather-data/get-the-weather-data?console=1
It seems to work (meaning, the Try it out button in the Console gives a response), but I get this result:
{
"query": {
"count": 0,
"created": "2015-06-21T11:12:06Z",
"lang": "en-US",
"results": null
}
}
The same result passed via cURL does give a correct response, which is an output of the weather.
Is there something I am misconfiguring in the blueprint?
Alternatively, does Mashape block calls from Apiary.io?
Here's the blueprint:
FORMAT: 1A
HOST: https://simple-weather.p.mashape.com
# Weather API
Display Weather forecast data by latitude and longitude. Get raw weather data OR simple label description of weather forecast of some places.
# Weather API Root [/]
# Group Weather
Resources related to weather in the API.
## Weather data [/weatherdata{?lat}{?lng}]
### Get the weather data [GET]
Get the weather data in your area.
+ Parameters
+ lat: 55.749792 (required, number) - Latitude
+ lng: 37.632495 (required, number) - Longitude
+ Request JSON Message
+ Headers
X-Mashape-Authorization: {hidden in this post}
Accept: text/plain
+ Response 200 (application/json)
+ Body
[
{
"query": {
"count": 1,
"created": "2014-05-03T03:57:53Z",
"lang": "en-US",
"results": {
"channel": {
"title": "Yahoo! Weather - Tebrau, MY",
"link": "http://us.rd.yahoo.com/dailynews/rss/weather/Tebrau__MY/*http://weather.yahoo.com/forecast/MYXX0004_c.html",
"description": "Yahoo! Weather for Tebrau, MY",
"language": "en-us",
"lastBuildDate": "Sat, 03 May 2014 11:00 am MYT",
"ttl": "60",
"location": {
"city": "Tebrau",
"country": "Malaysia",
"region": ""
},
...//truncated for this post
}
}
}
}
}
]
There is a tiny mistake in Blueprint in GET parameters. Parameters should be written like: {?param1,param2} (See: URI Templates)
So if you just change
## Weather data [/weatherdata{?lat}{?lng}] to ## Weather data [/weatherdata{?lat,lng}] it works.