Exemplo n.º 1
0
def run(clf, preprocess=False):
    '''Classify data from stdin
    '''
    for line in sys.stdin:
        if not line.strip():
            return
        if preprocess:
            line = twokenize.preprocess(line)
        if not line:
            print(str(default_class))
        else:
            print(clf.predict([line.strip()])[0])
Exemplo n.º 2
0
def run(clf, preprocess=False):
    '''Classify data from stdin
    '''
    for line in sys.stdin:
        if not line.strip():
            return
        if preprocess:
            line = twokenize.preprocess(line)
        if not line:
            print(str(default_class))
        else:
            print(clf.predict([line.strip()])[0])
Exemplo n.º 3
0
def run_zmp(clf, port, preprocess=False, verbose=False):
    '''Classify data coming from a ZMQ socket, reply to each request with the
    result.
    '''
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    address = 'tcp://*:' + str(port)
    socket.bind(address)
    if verbose:
        print('ZMQ Service Running: on %s' % (address,))

    while True:
        #  Wait for next request from client
        message = socket.recv()
        # preprocess
        if preprocess:
            message = twokenize.tokenize(message)
            message = twokenize.preprocess(message)
        # check for empty message
        if not message:
            socket.send(str(default_class))
        # classify and reply
        else:
            socket.send(str(clf.predict([message])[0]))
Exemplo n.º 4
0
def run_zmp(clf, port, preprocess=False, verbose=False):
    '''Classify data coming from a ZMQ socket, reply to each request with the
    result.
    '''
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    address = 'tcp://*:' + str(port)
    socket.bind(address)
    if verbose:
        print('ZMQ Service Running: on %s' % (address, ))

    while True:
        #  Wait for next request from client
        message = socket.recv()
        # preprocess
        if preprocess:
            message = twokenize.tokenize(message)
            message = twokenize.preprocess(message)
        # check for empty message
        if not message:
            socket.send(str(default_class))
        # classify and reply
        else:
            socket.send(str(clf.predict([message])[0]))