An open API service indexing awesome lists of open source software.

https://github.com/natlibfi/annif-client

Python client library for accessing Annif REST API
https://github.com/natlibfi/annif-client

annif

Last synced: 12 months ago
JSON representation

Python client library for accessing Annif REST API

Awesome Lists containing this project

README

          

# Annif-client

This is a minimal Python 3.x client library for accessing the
[Annif](http://annif.org) REST API which can be used for automated subject
indexing and classification of text documents.

## Installation

The easiest way to install is via pip:

pip3 install annif-client

## Dependencies

The library depends on the
[requests](http://docs.python-requests.org/en/master/#) module which is used
for HTTP/REST access. If you install this via pip, the dependencies will be
handled automatically.

## How to use

The client library comes with examples demonstrating its usage. You can invoke
the example by running the [annif_client.py](annif_client.py) script.

In your own code, you can use the AnnifClient class like this:

from annif_client import AnnifClient

# then you can create your own client
annif = AnnifClient()

## Example invocation

Here is the output from a typical example session:

$ python3 annif_client.py
Demonstrating usage of AnnifClient

* Creating an AnnifClient object
* The client uses Annif API at https://api.annif.org/v1/
* The version of Annif serving the API is 0.61.0

* Finding the available projects
Project id: yso-fi lang: fi name: YSO NN ensemble Finnish
Project id: yso-sv lang: sv name: YSO NN ensemble Swedish
Project id: yso-en lang: en name: YSO NN ensemble English
Project id: yso-mllm-fi lang: fi name: YSO MLLM Finnish
Project id: yso-mllm-en lang: en name: YSO MLLM English
Project id: yso-mllm-sv lang: sv name: YSO MLLM Swedish
Project id: yso-bonsai-fi lang: fi name: YSO Omikuji Bonsai Finnish
Project id: yso-bonsai-sv lang: sv name: YSO Omikuji Bonsai Swedish
Project id: yso-bonsai-en lang: en name: YSO Omikuji Bonsai English
Project id: yso-fasttext-fi lang: fi name: YSO fastText Finnish
Project id: yso-fasttext-sv lang: sv name: YSO fastText Swedish
Project id: yso-fasttext-en lang: en name: YSO fastText English

* Looking up information about a specific project
Project id: yso-en lang: en name: YSO NN ensemble English

* Analyzing a short text from a string
0.2852 dog
0.1401 laziness
0.1052 red fox
0.0914 singers
0.0679 pets
0.0651 jumping
0.0631 brown
0.0584 animals
0.0453 jazz
0.0357 clicker training

* Analyzing a longer text from a file, with a limit on number of results
0.6324 copyright
0.4211 licences (permits)
0.1882 computer programmes
0.1434 patents
0.1044 intellectual property law

* Analyzing a batch of text documents
doc-0
0.2852 dog
0.1401 laziness
0.1052 red fox
0.0914 singers
0.0679 pets
0.0651 jumping
0.0631 brown
0.0584 animals
0.0453 jazz
0.0357 clicker training
doc-1
0.7189 history
0.7167 libraries
0.6425 national libraries
0.3903 Finland
0.3430 collections
0.2621 architecture
0.2586 library buildings
0.2577 scientific libraries
0.2208 histories (literary works)
0.2120 university libraries
doc-2
0.5751 museums
0.5510 libraries
0.4488 archives (memory organisations)
0.4123 subject indexing
0.2768 automation
0.2394 subject cataloging
0.1884 indexing (information technology)
0.0799 data storage
0.0771 information management
0.0749 long-term preservation

## License

The code is published under the [Apache 2.0](LICENSE.txt) license.