hanlp_restful

class hanlp_restful.HanLPClient(url: str, auth: str = None, language=None, timeout=5)[source]
Parameters
  • url (str) – An API endpoint to a service provider.

  • auth (str) – An auth key licenced from a service provider.

  • language (str) – The default language for each parse() call. Contact the service provider for the list of languages supported. Conventionally, zh is used for Chinese and mul for multilingual. Leave None to use the default language on server.

  • timeout (int) – Maximum waiting time in seconds for a request.

__call__(text: Union[str, List[str]] = None, tokens: List[List[str]] = None, tasks: Optional[Union[str, List[str]]] = None, skip_tasks: Optional[Union[str, List[str]]] = None, language: str = None)hanlp_common.document.Document[source]

Parse a piece of text.

Parameters
  • text – A paragraph (str), or a list of sentences (List[str]).

  • tokens – A list of sentences where each sentence is a list of tokens.

  • tasks – The tasks to predict.

  • skip_tasks – The tasks to skip.

  • language – The language of input text or tokens. None to use the default language on server.

Returns

A Document.

Raises

HTTPError – Any errors happening on the Internet side or the server side. Refer to the code and msg of the exception for more details. A list of common errors :

  • 400 Bad Request indicates that the server cannot process the request due to a client fault (e.g., text too long, language unsupported).

  • 401 Unauthorized indicates that the request lacks valid auth credentials for the API.

  • 422 Unprocessable Entity indicates that the content type of the request entity is not in proper json format.

  • 429 Too Many Requests indicates the user has sent too many requests in a given amount of time (“rate limiting”).

about() → Dict[str, Any][source]

Get the information about server and your client.

Returns

A dict containing your rate limit and server version etc.

parse(text: Union[str, List[str]] = None, tokens: List[List[str]] = None, tasks: Optional[Union[str, List[str]]] = None, skip_tasks: Optional[Union[str, List[str]]] = None, language: str = None)hanlp_common.document.Document[source]

Parse a piece of text.

Parameters
  • text – A paragraph (str), or a list of sentences (List[str]).

  • tokens – A list of sentences where each sentence is a list of tokens.

  • tasks – The tasks to predict.

  • skip_tasks – The tasks to skip.

  • language – The language of input text or tokens. None to use the default language on server.

Returns

A Document.

Raises

HTTPError – Any errors happening on the Internet side or the server side. Refer to the code and msg of the exception for more details. A list of common errors :

  • 400 Bad Request indicates that the server cannot process the request due to a client fault (e.g., text too long, language unsupported).

  • 401 Unauthorized indicates that the request lacks valid auth credentials for the API.

  • 422 Unprocessable Entity indicates that the content type of the request entity is not in proper json format.

  • 429 Too Many Requests indicates the user has sent too many requests in a given amount of time (“rate limiting”).