Ejemplo n.º 1
0
def test_analyze():
    """
    Test Sentiment Analysis
    :return:
    """

    servicer = analysis.SentimentAnalysisServicer()
    request = Message()
    request.value = b64_sentences.senteces()
    context = object()
    response = servicer.Analyze(request, context)
    decoded_result = base64.b64decode(response.value).decode('utf-8')
    logger.debug(decoded_result)
    assert "pos" in str(decoded_result) or "neg" in str(
        decoded_result), "Generated result is not valid!"
Ejemplo n.º 2
0
def test_recognize():
    """
    Test Named Entity Recognition
    :return:
    """

    servicer = ner.RecognizeMessageServicer()
    request = Request()
    request.value = b64_sentences.senteces()
    context = object()
    response = servicer.Recognize(request, context)
    decoded_result = base64.b64decode(response.value).decode('utf-8')

    if "PERSON" in str(decoded_result) or "ORGANIZATION" in str(decoded_result) or "LOCATION" in str(decoded_result):
        logger.debug("test_recognize() - OK")
        assert True
    else:
        assert False, "Generated result is not valid"
Ejemplo n.º 3
0
if __name__ == '__main__':

    try:
        logger.debug('call => __name == __main__')
        # Service ONE - Sentiment Analysis
        endpoint = 'localhost:{}'.format(registry['sentiment_analysis']['grpc'])
        # Open a gRPC channel
        channel = grpc.insecure_channel('{}'.format(endpoint))

    except KeyError as e:
        print(e)

    try:

        logger.debug("call => SentimentAnalysis() Service Test Starting... ")
        # SentimentAnalysis() Method Test
        # create a stub (client)
        stub = grpc_services.SentimentAnalysisStub(channel)
        # create a valid request message
        test_data = b64_sentences.senteces()
        message = rpc.InputMessage(value=test_data)
        # make the call
        response = stub.Analyze(message)
        logger.debug("call => Analyze() Method Test Passed => " + response.value)
        print()

    except KeyError as e:
        print(e)

path_setup.clean_paths()