HomeHow to Use Mashape APIGetting Started with the Automatic Text Summarization API on Mashape

Automatic Text Summarization is one of popular text processing tasks, according wikipedia, Text Summarization is referred as Automatic Summarization:

Automatic summarization is the process of reducing a text document with a computer program in order to create a summary that retains the most important points of the original document. As the problem of information overload has grown, and as the quantity of data has increased, so has interest in automatic summarization. Technologies that can make a coherent summary take into account variables such as length, writing style and syntax. An example of the use of summarization technology is search engines such as Google. Document summarization is another.

If you remember the Summly App, which created by a 15 years old teenager and finally acquired by Yahoo, based on this text summarization technology. But automatic text summarization is very difficult in academic research, if you have the interest on this field, you can refer the Summarization Website, and there are a lot of text summarization resources, such as Bibliography, Papers and Summarization Systems links on it. We also recommend you to read the classic survey paper “A Survey on Automatic Text Summarization” by Dipanjan Das Andre F.T. Martins, where you can grasp the main summary methods in the text summarization field.

If you just want use the text summarization tools or apis, not want to research this technology, we recommend the Automatic Text Summarization API on Mashape Platform by our Text Analysis Services. Until now, we provide three Text Summarizers based on the open source code and fixed some problems in them for the text summarizer api, which include Simple Text Summarizer, Rotten Text Summarizer, PyTeaser Text Summarizer. And we will provided more professional Text Summarization Services and API based on advanced NLP and Machine Learning technologies. Now you can intuitive test these text summarizers on our Text Analysis Demo website: Text Analysis Online.

Mashape is the Cloud API Marketplace, the problem now is how to use Mashape API or how to use the text summarization API on Mashape? The answer is very simple, all you need to do is the flowing steps:

1. Register a Mashape account;
2. Go to the TextAnalysis API homepage on Mashape and subscribe to it;
3. Start using the Text Summarization API;

Based on the great Mashape Platform, the Text Summarization REST API can by easily used in any environment capable of making HTTP requests, including Java/JVM, Node.js, PHP, Python, Objective-C, Ruby and .NET, and you can test our Text Summarization API by the free plan(limited 1000 requests / day) first. It’s really easy to start using the TextAnalysis API on mashape based by their Unirest project. Unirest is an open source library that does HTTP REST really well, ported to multiple languages, following is the official introduction:

Unirest is a set of lightweight HTTP libraries available in multiple languages, ideal for most applications:

Make GET, POST, PUT, PATCH, DELETE requests
Both syncronous and asynchronous (non-blocking) requests
It supports form parameters, file uploads and custom body entities
Supports gzip
Supports Basic Authentication natively
Customizable timeout
Customizable default headers for every request (DRY)
Automatic JSON parsing into a native object for JSON responses

Unirest

Here we will introduce how to use the Text Summarization API by unirest python client library: Unirest for Python, other programming language that Unirest support is very similar, and you can still learn the by the official guide.

To use Unirest Python Library, first install it by pip:

pip install unirest

then test it by in the Python interpreter:

>>> import unirest

Now it’s time to use the Text Summarization API on Mashpe by calling the endpoint, take the PyTeaser Tex Summarizer as the example, which is part of Text Analysis API. We use the POST request in the TextAnalysis API which take more characters than other HTTP request like GET, and provide in the request body as a JSON blob. In the PyTeaser Text Summarizer, the json request body like this:

{
“url”: “http://en.wikipedia.org/wiki/Automatic_summarization”,
“text”: “”
}

There are two parameters in the request, “url” or “text”, you can insert an url you want to summarize directly or copy and paste some text from some articles to summarized by the PyTeaser Text Summarizer. Here we just test the url parameter, you can test the text parameter your self. Now it’s time to generate the request by Unirest, and luckily the request is given directly by Mashape TextAnalysis API Document, just copy it and pasted in the Python interpreter:

>>> response = unirest.post(“https://textanalysis.p.mashape.com/pyteaser-text-summarizer”,

… headers={
… “X-Mashape-Authorization”: “Mashpae API Key”,
… “Content-Type”: “application/json”
… },
… params=”{\”url\”:\”http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\”,\”text\”:\”\”}”
… );

Here the Mashape API Key you can find in your Mashape account dashboard (If you are a Mashape user, get your key from your dashboard at https://www.mashape.com/login – To create a free Mashape account instead, go to https://www.mashape.com/signup’) , copy it and replace it here, the precondition is you have subscribed our Text Analysis API. After you get the response from our Text Summarization Service, you can check the response content:

>>> dir(response)
[‘__class__’, ‘__delattr__’, ‘__dict__’, ‘__doc__’, ‘__format__’, ‘__getattribute__’, ‘__hash__’, ‘__init__’, ‘__module__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, ‘__weakref__’, ‘_body’, ‘_code’, ‘_headers’, ‘_raw_body’, ‘body’, ‘code’, ‘headers’, ‘raw_body’]
>>> response.body
{u’sentences’: [u’Summarization systems are able to create both query relevant text summaries and generic machine-generated summaries depending on what the user needs.’, u’LexRank 5 is an algorithm essentially identical to TextRank, and both use this approach for document summarization.’, u’Another important distinction is that TextRank was used for single document summarization, while LexRank has been applied to multi-document summarization.’, u’First summarizes that perform adaptive summarization have been created. 4\n\nSupervised text summarization is very much like supervised keyphrase extraction.’, u’Document summarization is another.’]}
>>> response.code
200
>>>

Here you can get the PyTeaser 5 sentences summaries from the response body and the status code by response.code. So is this very easy? Actually, Mashape API can be used with or without the Unirest client library, the simplest way to use the API is by CURL , let’s try to use the Text Summarization API by Text Analysis with CURL in the command line:

curl –include –request POST ‘https://textanalysis.p.mashape.com/pyteaser-text-summarizer’ \
> –header “X-Mashape-Authorization: Mashape API Key” \
> –header “Content-Type: application/json” \
> –data “{\”url\”:\”http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\”,\”text\”:\”\”}”

The response is like this:

HTTP/1.1 200 OK
content-type: application/json
date: Mon, 05 May 2014 06:40:19 GMT
server: nginx
X-Mashape-Proxy-Response: false
X-Mashape-Version: 3.1.11
Content-Length: 672
Connection: keep-alive

{
“sentences”: [
“Summarization systems are able to create both query relevant text summaries and generic machine-generated summaries depending on what the user needs.”,
“LexRank 5 is an algorithm essentially identical to TextRank, and both use this approach for document summarization.”,
“Another important distinction is that TextRank was used for single document summarization, while LexRank has been applied to multi-document summarization.”,
“First summarizes that perform adaptive summarization have been created. 4\n\nSupervised text summarization is very much like supervised keyphrase extraction.”,
“Document summarization is another.”
]
}

For other languages now Unirest support, like Java, PHP, Node and etc, the steps to use it in Mashape like above-mentioned Python example, install the related programming language unirest client library, than make the request provided by the Mashape platform, such as for Java, the mashape api request like this:

HttpResponse request = Unirest.post("https://textanalysis.p.mashape.com/pyteaser-text-summarizer")
.header("X-Mashape-Authorization", "Mashpae API Key")
.header("Content-Type", "application/json")
.body("{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Natural_language_processing\",\"text\":\"\"}")
.asJson();

For Node, the mashape api request like this:

var Request = unirest.post("https://textanalysis.p.mashape.com/pyteaser-text-summarizer")
.headers({
"X-Mashape-Authorization": "Mashpae API Key",
"Content-Type": "application/json"
})
.send("{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\",\"text\":\"\"}")
.end(function (response) {
console.log(response);
});

For PHP, the mashape api request like this:

$response = Unirest::post(
"https://textanalysis.p.mashape.com/pyteaser-text-summarizer",
array(
"X-Mashape-Authorization" => "Mashpae API Key",
"Content-Type" => "application/json"
),
"{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Natural_language_processing\",\"text\":\"\"}"
);

For object-c, the mashape api request like this:

NSDictionary* headers = @{@"X-Mashape-Authorization": @"Mashpae API Key", @"Content-Type": @"application/json"};
NSDictionary* parameters = @{};

UNIHttpJsonResponse* response = [[UNIRest post:^(UNIBodyRequest* request) {
[request setUrl:@"https://textanalysis.p.mashape.com/pyteaser-text-summarizer"];

[request setHeaders:headers];
[request setParameters:parameters];
[request setBody:[@"{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\",\"text\":\"\"}" dataUsingEncoding:NSUTF8StringEncoding]];
}] asJson];

For Ruby, the mashpae api request like this:

response = Unirest::post "https://textanalysis.p.mashape.com/pyteaser-text-summarizer",
headers: {
"X-Mashape-Authorization" => "Mashpae API Key",
"Content-Type" => "application/json"
},
parameters: "{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\",\"text\":\"\"}"

For .Net, the mashape api request like this:

HttpResponse response = Unirest.post("https://textanalysis.p.mashape.com/pyteaser-text-summarizer")
.header("X-Mashape-Authorization", "Mashpae API Key")
.header("Content-Type", "application/json")
.body("{\"url\":\"http:\/\/en.wikipedia.org\/wiki\/Automatic_summarization\",\"text\":\"\"}")
.asJson();

Everything seems very easy based on the Mashape Unirest Library, and just enjoy our Text Analysis API by our Text Analysis Online Services.

Posted by TextMiner


Comments

Getting Started with the Automatic Text Summarization API on Mashape — 3 Comments

  1. Pingback: We have launched the Professional Text Summarization API on Mashape | Text Mining Online | Text Analysis Online | Text Processing Online

  2. excellent work by all.
    some training from fundamentals up to deep programming level is available.
    if yes please mail me details.

Leave a Reply

Your email address will not be published. Required fields are marked *