Add changes from cqiclient repository

This commit is contained in:
Patrick Jentsch 2020-03-20 15:12:19 +01:00
parent 7c9b9f0712
commit 7752e7fb57
2 changed files with 25 additions and 13 deletions

View File

@ -1,16 +1,16 @@
# ########################################################################### #
# IMS CQi specification #
# #
# Version: 0.1a ;o) #
# Author: Stefan Evert (evert@ims.uni-stuttgart.de) #
# Modified by: Patrick Jentsch <p.jentsch@uni-bielefeld.de #
# Modified date: Thurs Oct 10 <Uhrzeit> #
# ########################################################################### #
from time import sleep from time import sleep
import socket import socket
import struct import struct
# ########################################################################### #
# IMS CQi specification #
# #
# Version: 0.1a ;o) #
# Author: Stefan Evert (evert@ims.uni-stuttgart.de) #
# Modified by (codestyle): Patrick Jentsch (p.jentsch@uni-bielefeld.de) #
# Modified date: Thurs Oct 10 #
# ########################################################################### #
""" 1. padding """ """ 1. padding """
PAD = 0x00 PAD = 0x00
@ -409,13 +409,24 @@ lookup = {
} }
class Client: # ########################################################################### #
def __init__(self, host='127.0.0.1', port=4877): # IMS CQi client #
# #
# Version: 0.1a #
# Author: Patrick Jentsch (p.jentsch@uni-bielefeld.de) #
# ########################################################################### #
class APIClient:
def __init__(self, host, port=4877):
self.host = host self.host = host
self.port = port self.port = port
self.socket = socket.socket() self.socket = socket.socket()
def setup(self):
self.socket.connect((self.host, self.port)) self.socket.connect((self.host, self.port))
def teardown(self):
self.socket.close()
def ctrl_connect(self, username, password): def ctrl_connect(self, username, password):
# INPUT: (STRING username, STRING password) # INPUT: (STRING username, STRING password)
# OUTPUT: CQI_STATUS_CONNECT_OK, CQI_ERROR_CONNECT_REFUSED # OUTPUT: CQI_STATUS_CONNECT_OK, CQI_ERROR_CONNECT_REFUSED

View File

@ -3,7 +3,7 @@ from . import CQi
import time import time
class CQiWrapper(CQi.Client): class CQiWrapper(CQi.APIClient):
''' '''
CQIiWrapper object CQIiWrapper object
@ -21,7 +21,7 @@ class CQiWrapper(CQi.Client):
def __init__(self, host='127.0.0.1', port=4877, username='anonymous', def __init__(self, host='127.0.0.1', port=4877, username='anonymous',
password=''): password=''):
super(CQiWrapper, self).__init__(host=host, port=port) super(CQiWrapper, self).__init__(host, port=port)
self.username = username self.username = username
self.password = password self.password = password
@ -32,6 +32,7 @@ class CQiWrapper(CQi.Client):
Connects via socket to the CQP server using the given username and Connects via socket to the CQP server using the given username and
password from class initiation. password from class initiation.
''' '''
super(CQiWrapper, self).setup()
self.ctrl_connect(self.username, self.password) self.ctrl_connect(self.username, self.password)
def __create_attribute_strings(self): def __create_attribute_strings(self):
@ -78,7 +79,7 @@ class CQiWrapper(CQi.Client):
Disconnects from the CQP server. Closes used socket after disconnect. Disconnects from the CQP server. Closes used socket after disconnect.
''' '''
self.ctrl_bye() self.ctrl_bye()
self.connection.close() super(CQiWrapper, self).teardown()
logger.warning('Disconnected from cqp server.') logger.warning('Disconnected from cqp server.')
def query_subcorpus(self, query, result_subcorpus_name='Query-results'): def query_subcorpus(self, query, result_subcorpus_name='Query-results'):