1 CURL *curl;
2 CURLcode res;
3 curl = curl_easy_init();
4 if(curl) {
5 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
6 curl_easy_setopt(curl, CURLOPT_URL, "https://api.meaningcloud.com/class-1.1?key=<your_key>&txt=<text>&model=<model>");
7 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
8 curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
9 struct curl_slist *headers = NULL;
10 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
11 res = curl_easy_perform(curl);
12 }
13 curl_easy_cleanup(curl);
1#! /usr/bin/env python
2
3# Created by MeaningCloud Support Team
4# Date: 26/02/18
5
6import sys
7import meaningcloud
8
9# @param model str - Name of the model to use. Example: "IAB_en" by default = "IPTC_en"
10model = 'IAB_en'
11
12# @param license_key - Your license key (found in the subscription section in https://www.meaningcloud.com/developer/)
13license_key = '<<<<< your license key >>>>>'
14
15# @param text - Text to use for different API calls
16text = 'London is a very nice city but I also love Madrid.'
17
18
19try:
20 # We are going to make a request to the Topics Extraction API
21 topics_response = meaningcloud.TopicsResponse(meaningcloud.TopicsRequest(license_key, txt=text, lang='en',
22 topicType='e').sendReq())
23
24 # If there are no errors in the request, we print the output
25 if topics_response.isSuccessful():
26 print("\nThe request to 'Topics Extraction' finished successfully!\n")
27
28 entities = topics_response.getEntities()
29 if entities:
30 print("\tEntities detected (" + str(len(entities)) + "):\n")
31 for entity in entities:
32 print("\t\t" + topics_response.getTopicForm(entity) + ' --> ' +
33 topics_response.getTypeLastNode(topics_response.getOntoType(entity)) + "\n")
34
35 else:
36 print("\tNo entities detected!\n")
37 else:
38 if topics_response.getResponse() is None:
39 print("\nOh no! The request sent did not return a Json\n")
40 else:
41 print("\nOh no! There was the following error: " + topics_response.getStatusMsg() + "\n")
42
43 # CLASS API CALL
44 # class_response = meaningcloud.ClassResponse(
45 # meaningcloud.ClassRequest(license_key, txt=text, model=model).sendReq())
46
47 # SENTIMENT API CALL
48 # sentiment_response = meaningcloud.SentimentResponse(
49 # meaningcloud.SentimentRequest(license_key, lang='en', txt=text, txtf='plain').sendReq())
50
51 # GENERIC API CALL
52 # generic = meaningcloud.Request(url="url_of_specific_API",key=key)
53 # generic.addParam('parameter','value')
54 # generic_result = generic.sendRequest()
55 # generic_response = meaningcloud.Response(generic_result)
56
57 # We are going to make a request to the Language Identification API
58 lang_response = meaningcloud.LanguageResponse(meaningcloud.LanguageRequest(license_key, txt=text).sendReq())
59
60 # If there are no errors in the request, we will use the language detected to make a request to Sentiment and Topics
61 if lang_response.isSuccessful():
62 print("\nThe request to 'Language Identification' finished successfully!\n")
63 first_lang = lang_response.getFirstLanguage()
64 if first_lang:
65 language = lang_response.getLanguageCode(first_lang)
66 print("\tLanguage detected: " + lang_response.getLanguageName(first_lang) + ' (' + language + ")\n")
67 else:
68 print("\tNo language detected!\n")
69
70 # We are going to make a request to the Lemmatization, PoS and Parsing API
71 parser_response = meaningcloud.ParserResponse(
72 meaningcloud.ParserRequest(license_key, txt=text, lang='en').sendReq())
73
74 # If there are no errors in the request, print tokenization and lemmatization
75 if parser_response.isSuccessful():
76 print("\nThe request to 'Lemmatization, PoS and Parsing' finished successfully!\n")
77 lemmatization = parser_response.getLemmatization(True)
78 print("\tLemmatization and PoS Tagging:\n")
79 for token, analyses in lemmatization.items():
80 print("\t\tToken -->", token)
81 for analysis in analyses:
82 print("\t\t\tLemma -->", analysis['lemma'])
83 print("\t\t\tPoS Tag -->", analysis['pos'], "\n")
84
85
86except ValueError:
87 e = sys.exc_info()[0]
88 print("\nException: " + str(e))
89