From 606c4dee8514799189e688f35e4c9ce673e1b8d2 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 6 Apr 2020 14:53:50 +0200 Subject: [PATCH] CQi updates --- app/corpora/cqi/api/client.py | 2 ++ app/corpora/cqi/client.py | 27 +++++++++++++++++++++++++++ app/corpora/cqi/models/attributes.py | 12 ++++++++++++ 3 files changed, 41 insertions(+) diff --git a/app/corpora/cqi/api/client.py b/app/corpora/cqi/api/client.py index cbf28f14..9c257203 100644 --- a/app/corpora/cqi/api/client.py +++ b/app/corpora/cqi/api/client.py @@ -15,6 +15,8 @@ class APIClient: >>> client = cqi.APIClient('127.0.0.1') >>> client.ctrl_connect('user', 'password') {'code': 258, 'msg': 'CQI_STATUS_CONNECT_OK'} + >>> client.ctrl_ping() + {'code': 260, 'msg': 'CQI_STATUS_PING_OK'} >>> client.ctrl_bye() {'code': 259, 'msg': 'CQI_STATUS_BYE_OK'} diff --git a/app/corpora/cqi/client.py b/app/corpora/cqi/client.py index b4662c4c..5cc867c1 100644 --- a/app/corpora/cqi/client.py +++ b/app/corpora/cqi/client.py @@ -3,7 +3,31 @@ 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=''): @@ -14,3 +38,6 @@ class CQiClient: def disconnect(self): del self.corpora return self.api.ctrl_bye() + + def ping(self): + return self.api.ctrl_ping() diff --git a/app/corpora/cqi/models/attributes.py b/app/corpora/cqi/models/attributes.py index 152a6f62..20dd359b 100644 --- a/app/corpora/cqi/models/attributes.py +++ b/app/corpora/cqi/models/attributes.py @@ -8,6 +8,18 @@ class AttributeCollection: class Attribute: + """ + This is a class representing an attribute. Attributes denote the general + category of information. A specific occurence is identified by an Id. + + Attributes: + client (CQiClient): A connected client pointing at the server that this + object is on. + corpus (Corpus): The corpus, this attribute belongs to. + name (str): The name of the Attribute. + size (int): The number of occurences of this attribute within the corpus. + """ + def __init__(self, client, corpus, name): self.client = client self.corpus = corpus