Getting Started

This tutorial shows how to make your first request to Anacode’s Web&Text API using Python.

To get started, you first need to register for a free account:

  1. Go to the registration page and fill out the form.
  2. You will receive an activation email. Click on the link to activate your account.
  3. Sign in on our web page, go to your token page and generate a new token.

You are now ready to use Anacode Web&Text API! Let’s test your account and extract some concepts from the following example text:

>>> chinese_text = '因消耗做挞多出来的杏仁奶油馅而出现的衍生品' \
>>>                '结果好吃到我决定下次单独做它!!'

We will the use requests library for making HTTPS requests. In the code below, we supply you with the correct URL for the concept extraction HTTPS call, but you have to edit auth yourself to include your token.

>>> import requests
>>> url = 'https://api.anacode.de/analyze/'
>>> auth = {'Authorization': 'Token <your token goes here>'}
>>> request_data = json={'texts': [chinese_text], 'analysis': ['concepts']}
>>> concepts = requests.post(url, headers=auth, json=request_data)
>>> concepts.json()['concepts']
[[{'surface': [{'surface_string': '奶油', 'span': (11, 13)}],
   'relevance_score': None,
   'type': 'product',
   'freq': 1,
   'concept': 'CreamCondiment'},
  {'surface': [{'surface_string': '好吃', 'span': (23, 25)}],
   'relevance_score': 0.6724752226778945,
   'type': 'feature',
   'freq': 1,
   'concept': 'Tasty'},
  {'surface': [{'surface_string': '杏仁', 'span': (9, 11)}],
   'relevance_score': 0.7401196355213907,
   'type': 'feature',
   'freq': 1,
   'concept': 'ApricotKernel'}]]

Congratulations - you have just made your first request with Anacode Web&Text API! Where to go from here?

  • Download and run this demo script in python which illustrates the various calls. Please provide your token as argument to the script, as follows:

    python3 webtext_api_demo.py <your token>
    
  • Check out the API reference to learn what you can do with our API.

  • Download clean, structured data samples to get started with Chinese data analysis immediately.

  • Follow our use cases to get inspired for your own applications.