Next, we introduce Text Graph API.
The other APIs of TexSmart can be found in: Text Understanding API 和 Text Matching API。
The API supports access via HTTP-POST and its url is: https://texsmart.qq.com/api/text_graph.
The input post-data needs to be in JSON format, and the output is also in JSON format.
It is recommended to use Postman for testing.
obj = { "text": happy, "lang": "en", "relation": "similar_to", "k": 10 }Example codes for calling the API: Python Code | Java Code | C++ Code | C# Code
{ "header":{"time_cost_ms":0.243,"time_cost":0.000243,"core_time_cost_ms":0.215,"ret_code":"succ"}, "item_list":[ {"order":1,"text":"excited"}, {"order":2,"text":"confident"}, {"order":3,"text":"grateful"}, {"order":4,"text":"unhappy"}, {"order":5,"text":"proud"}, {"order":6,"text":"surprised"}, {"order":7,"text":"satisfied"}, {"order":8,"text":"glad"}, {"order":9,"text":"beautiful"}, {"order":10,"text":"frustrated"} ] }Note that, the field “header” gives some auxiliary information (time cost, error codes, etc.) which explains this API call. The field “item_list” returns the results of the query word under the given conditions.
An introduction of each field of the input JSON object is as follows:
Field Name | Data Type | Field Introduction |
---|---|---|
text | str | The word to be retrieved. |
lang | str | The language of the queried text, "zh" and "en" are supported. |
relation | str | The queried relation, supportting: "synonym_of" (synonym), "antonym_of" (antonym), "instance_of"(下位词), "class_of" (hypernym), "similar_to" (hyponym). |
k | int | The number of returned items.
Notice: (1) For the relation "class_of", only the top 10 items will be returned if k>10. For the other relations, only the top 20 items will be returned if k>20. (2) When the number of results (items) in the database is fewer than k, all the items will be returned and it is smaller than k. |
The introduction of each field of output JSON object is as follows:
Field Name | Data Type | Field Introduction |
---|---|---|
header | JSON Object | Auxiliary information returned after calling and execution.
Field time_cost_ms: The total time for processing request calculated with millisecond (ms). Field time_cost: The total time for processing request calculated with second (s). Field ret_code: Return code. "succ" denotes success, and others are false codes. The main error is "error.invalid_mode": the requested relation is not in the candidate relation set. |
item_list | JSON list | The returned results
It is a list of JSON objects, each object corresponds to a text and its index. |
# -*- coding: utf8 -*- import json import http.client import requests obj = { "text": happy, "lang": "en", "relation": "similar_to", "k": 10 } r = requests.post(url="https://texsmart.qq.com/api/text_graph", json= obj) print(r.text)
[TBD]
[TBD]
[TBD]
TexSmart is a text understanding system built by NLP Team at Tencent AI Lab, which is used to analyze morphology, syntax and semantics for text in both Chinese and English. It provides basic natural language understanding functions such as word segmentation, part-of-speech tagging, named entity recognition(NER), semantic expansion, and particularly supports some key functions including fine-grained named entity recognition, semantic expansion and deep semantic expression for specific entities.
Experience Demo | System Introduction