mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-27 03:44:19 +00:00
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from .api import APIClient
|
|
from .models.corpora import CorpusCollection
|
|
|
|
|
|
class CQiClient:
|
|
"""
|
|
A client for communicating with a CQi server.
|
|
|
|
Example:
|
|
>>> import cqi
|
|
>>> client = cqi.CQiClient('127.0.0.1')
|
|
>>> client.connect()
|
|
{'code': 258, 'msg': 'CQI_STATUS_CONNECT_OK'}
|
|
>>> client.ping()
|
|
{'code': 260, 'msg': 'CQI_STATUS_PING_OK'}
|
|
>>> client.disconnect()
|
|
{'code': 259, 'msg': 'CQI_STATUS_BYE_OK'}
|
|
Attributes:
|
|
api (APIClient): A client pointing to the specified to the CQP server.
|
|
"""
|
|
|
|
def __init__(self, host, port=4877):
|
|
"""
|
|
CQiClient constructor
|
|
|
|
Args:
|
|
host (str): URL to the CQP server. For example,
|
|
``cqpserver.localhost`` or ``127.0.0.1``.
|
|
port (int): Port the CQP server listens on. Default: ``4877``
|
|
"""
|
|
self.api = APIClient(host, port=port)
|
|
|
|
def connect(self, username='anonymous', password=''):
|
|
status = self.api.ctrl_connect(username, password)
|
|
self.corpora = CorpusCollection(self)
|
|
return status
|
|
|
|
def disconnect(self):
|
|
del self.corpora
|
|
return self.api.ctrl_bye()
|
|
|
|
def ping(self):
|
|
return self.api.ctrl_ping()
|