Skip to main content

Official Python SDK for MeaningCloud APIs

Project description

MeaningCloud for Python

This is MeaningCloud's official Python client, designed to enable you to use MeaningCloud's services easily from your own applications.

MeaningCloud

MeaningCloud is a cloud-based text analytics service that through APIs allows you extract meaning from all kind of unstructured content: social conversation, articles, documents... You can check our demos here: https://www.meaningcloud.com/demos

The different APIs provide easy access to many NLP tasks such as automatic classification, sentiment analysis, topic extraction, etc. To be able to use the service you just have to log into MeaningCloud (by registering or using other services to log in: https://www.meaningcloud.com/developer/login), and you will receive a license key associated to a basic Free plan.

You can read more about the plans and the features available here: https://www.meaningcloud.com/products/pricing

SDK versions

Starting from version 2.0 the classification API class-1.1 is deprecated. Please refer to the class-1.1 to class-2.0 Model Migration Guide to upgrade your classification models.

v1.2 v2.0
Class class-1.1 class-2.0
Deep Categorization deepcategorization-1.0 deepcategorization-1.0
Language Detection lang-2.0 lang-2.0
Parser parser-2.0 parser-2.0
Sentiment Analysis sentiment-2.1 sentiment-2.1
Topics Extraction topics-2.0 topics-2.0

Getting started

Installation

You can load meaningcloud-python into your project by using:

pip install MeaningCloud-python

You can also clone the code and type the following on your shell:

python setup.py install

Configuration

The only thing you need to start using MeaningCloud's APIs is to log into MeaningCloud (by registering or using other services to log in). Once you've done that, you will be given a license key (https://www.meaningcloud.com/developer/account/subscription). Copy it and paste it in the corresponding place in the code, select the API you want to use and the parameters you want to use, and that's it.

You can find all the technical documentation about the APIs in the API section of the website: https://www.meaningcloud.com/developer/apis

And we are always available at support@meaningcloud.com

Functionality

This SDK currently contains the following:

  • Request: manages requests to any of MeaningCloud's APIS. It can also be used to directly generate requests without using specific classes .
    • ClassRequest: models a request to MeaningCloud Text Classification API.
    • ClusteringRequest: models a request to MeaningCloud Text Clustering API.
    • DeepCategorizationRequest: models a request to MeaningCloud Deep Categorization API.
    • LanguageRequest: models a request to MeaningCloud Language Identification API.
    • ParserRequest: models a request to Meaningcloud Lemmatization, PoS and Parsing API.
    • SentimentRequest: models a request to MeaningCloud Sentiment Analysis API.
    • SummarizationRequest: models a request to Meaningcloud Summarization API.
    • TopicsRequest: models a request to MeaningCloud TopicsExtraction API.
  • Response: models a generic response from the MeaningCloud API.
    • ClassResponse: models a response from the Text Classification API, providing auxiliary functions to work with the response and extract the different fields in each category.
    • ClusteringResponse: models a response from the Text Clustering API, providing auxiliary functions to work with the response and extract the different fields in each cluster.
    • DeepCategorizationResponse: models a response from the Deep Categorization API, providing auxiliary functions to work with the response and extract the different fields in each category.
    • LanguageResponse: models a response from the Language Identification API, providing auxiliary functions to work with the response and extract the sentiment detected at different levels and for different elements.
    • ParserResponse: models a response from the Lemmatization, PoS and Parsing API, providing auxiliary functions to work with the response and extract the lemmatization and PoS tagging of the text provided.
    • SentimentResponse: models a response from the Sentiment Analysis API, providing auxiliary functions to work with the response and extract the sentiment detected at different levels and for different elements.
    • SummarizationResponse: models a response from the Summarization API, providing auxiliary functions to work with the response and obtain the summary extracted.
    • TopicsResponse: models a response from the Topic Extraction API, providing auxiliary functions to work with the response, extracting the different types of topics and some of the most used fields in them.

Usage

In the example folder, there are two examples:

  • Client.py, which contains a simple example on how to use the SDK.

  • mc_rapidminer.py, which contains a script you can run from RapidMiner using the Python scripting extension

  • mc_showcase.py, which implements a pipeline where plain text files are read from a folder, and two CSV files result as output: one with several types of analyses done over each text, and the results from running Text Clustering over the complete collection. The analyses done are:

This is what Client.py looks like:

#! /usr/bin/env python

# Created by MeaningCloud Support Team
# Date: 26/02/18

import sys
import meaningcloud

# @param model str - Name of the model to use. Example: "IAB_en" by default = "IPTC_en"
model = 'IAB_en'

# @param license_key - Your license key (found in the subscription section in https://www.meaningcloud.com/developer/)
license_key = '<<<<< your license key >>>>>'

# @param text - Text to use for different API calls
text = 'London is a very nice city but I also love Madrid.'


try:
    # We are going to make a request to the Topics Extraction API
    topics_response = meaningcloud.TopicsResponse(meaningcloud.TopicsRequest(license_key, txt=text, lang='en',
                                                                             topicType='e').sendReq())

    # If there are no errors in the request, we print the output
    if topics_response.isSuccessful():
        print("\nThe request to 'Topics Extraction' finished successfully!\n")

        entities = topics_response.getEntities()
        if entities:
            print("\tEntities detected (" + str(len(entities)) + "):\n")
            for entity in entities:
                print("\t\t" + topics_response.getTopicForm(entity) + ' --> ' +
                      topics_response.getTypeLastNode(topics_response.getOntoType(entity)) + "\n")

        else:
            print("\tNo entities detected!\n")
    else:
        if topics_response.getResponse() is None:
            print("\nOh no! The request sent did not return a Json\n")
        else:
            print("\nOh no! There was the following error: " + topics_response.getStatusMsg() + "\n")

    # CLASS API CALL
    # class_response = meaningcloud.ClassResponse(
    #   meaningcloud.ClassRequest(license_key, txt=text, model=model).sendReq())

    # SENTIMENT API CALL
    # sentiment_response = meaningcloud.SentimentResponse(
    #   meaningcloud.SentimentRequest(license_key, lang='en', txt=text, txtf='plain').sendReq())

    # GENERIC API CALL
    # generic = meaningcloud.Request(url="url_of_specific_API",key=key)
    # generic.addParam('parameter','value')
    # generic_result = generic.sendRequest()
    # generic_response = meaningcloud.Response(generic_result)

    # We are going to make a request to the Language Identification API
    lang_response = meaningcloud.LanguageResponse(meaningcloud.LanguageRequest(license_key, txt=text).sendReq())

    # If there are no errors in the request, we will use the language detected to make a request to Sentiment and Topics
    if lang_response.isSuccessful():
        print("\nThe request to 'Language Identification' finished successfully!\n")
        first_lang = lang_response.getFirstLanguage()
        if first_lang:
            language = lang_response.getLanguageCode(first_lang)
            print("\tLanguage detected: " + lang_response.getLanguageName(first_lang) + ' (' + language + ")\n")
        else:
            print("\tNo language detected!\n")

    # We are going to make a request to the Lemmatization, PoS and Parsing API
    parser_response = meaningcloud.ParserResponse(
        meaningcloud.ParserRequest(license_key, txt=text, lang='en').sendReq())

    # If there are no errors in the request, print tokenization and lemmatization
    if parser_response.isSuccessful():
        print("\nThe request to 'Lemmatization, PoS and Parsing' finished successfully!\n")
        lemmatization = parser_response.getLemmatization(True)
        print("\tLemmatization and PoS Tagging:\n")
        for token, analyses in lemmatization.items():
            print("\t\tToken -->", token)
            for analysis in analyses:
                print("\t\t\tLemma -->", analysis['lemma'])
                print("\t\t\tPoS Tag -->", analysis['pos'], "\n")


except ValueError:
    e = sys.exc_info()[0]
    print("\nException: " + str(e))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MeaningCloud-python-2.0.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

MeaningCloud_python-2.0.0-py2.py3-none-any.whl (21.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file MeaningCloud-python-2.0.0.tar.gz.

File metadata

  • Download URL: MeaningCloud-python-2.0.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for MeaningCloud-python-2.0.0.tar.gz
Algorithm Hash digest
SHA256 3134abc3be97a8bc37405f4da856f3ccfd3bf8c999395d64d6ffe2b00eb4b566
MD5 1fe98157180d680f216237d3816e755e
BLAKE2b-256 5364cfc57dbe8c9321c370ffcc9518c2b3b5fd1a55952c8dadc0b6a114ba0335

See more details on using hashes here.

File details

Details for the file MeaningCloud_python-2.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: MeaningCloud_python-2.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for MeaningCloud_python-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aa4eae91319a87ffa50d8e6a9b7ff5422883f23036ce3aca199e010d9f9e5a03
MD5 bad4a0b3b59a7b5fa5bd09c965b9b9b9
BLAKE2b-256 d8cbf06467d7e9abf8b1aa5b9a224184428bc1e72a948ccf0f5b1bcc82ac1441

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page