Code Monkey home page Code Monkey logo

monkeylearn-java's Introduction

monkeylearn-java

Official Java client for the MonkeyLearn API. Build and consume machine learning models for language processing from your Java apps.

Install

Using maven:

<dependency>
  <groupId>com.monkeylearn</groupId>
  <artifactId>monkeylearn-java</artifactId>
  <version>0.1.5</version>
  <scope>compile</scope>
</dependency>

Or if you want to compile it yourself:

$ git clone [email protected]:monkeylearn/monkeylearn-java
$ cd monkeylearn-java
$ mvn install       # Requires maven, download from http://maven.apache.org/download.html

You can also download the compiled jar from here.

Usage examples

Here are some examples of how to use the library in order to create and use classifiers:

import com.monkeylearn.MonkeyLearn;
import com.monkeylearn.MonkeyLearnResponse;
import com.monkeylearn.MonkeyLearnException;
import com.monkeylearn.Tuple;

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;

import java.util.ArrayList;

public class App {
    public static void main( String[] args ) throws MonkeyLearnException {

        // Use the API key from your account
        MonkeyLearn ml = new MonkeyLearn("<YOUR API KEY HERE>");

        // Create a new classifier
        MonkeyLearnResponse res = ml.classifiers.create("Test Classifier", "Some description");

        // Get the id of the new module
        String moduleId = (String) ((JSONObject)res.jsonResult.get("classifier")).get("hashed_id");

        // Get the id of the root node
        res = ml.classifiers.detail(moduleId);
        Integer rootId = ((Long) ((JSONObject)((JSONArray)res.jsonResult.get("sandbox_categories")).get(0)).get("id")).intValue();

        // Create two new categories on the root node
        res = ml.classifiers.categories.create(moduleId, "Negative", rootId);
        Integer negativeId = ((Long) ((JSONObject)res.jsonResult.get("category")).get("id")).intValue();
        res = ml.classifiers.categories.create(moduleId, "Positive", rootId);
        Integer positiveId = ((Long) ((JSONObject)res.jsonResult.get("category")).get("id")).intValue();

        // Now let's upload some samples
        ArrayList samples = new ArrayList();
        samples.add(new Tuple<String, Integer>("The movie was terrible, I hated it.", negativeId));
        samples.add(new Tuple<String, Integer>("I love this movie, I want to watch it again!", positiveId));
        res = ml.classifiers.uploadSamples(moduleId, samples);

        // Now let's train the module!
        res = ml.classifiers.train(moduleId);

        // Classify some texts
        String[] textList = {"I love the movie", "I hate the movie"};
        res = ml.classifiers.classify(moduleId, textList, true);

        System.out.println( res.arrayResult );
    }
}

You can also use the sdk with extractors:

import com.monkeylearn.MonkeyLearn;
import com.monkeylearn.MonkeyLearnResponse;
import com.monkeylearn.MonkeyLearnException;
import com.monkeylearn.Tuple;
import com.monkeylearn.ExtraParam;

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;

import java.util.ArrayList;

public class App {
    public static void main( String[] args ) throws MonkeyLearnException {

        // Use the API key from your account
        MonkeyLearn ml = new MonkeyLearn("<YOUR API KEY HERE>");

        // Use the keyword extractor
        String[] textList = {"I love the movie", "I hate the movie"};
        ExtraParam[] extraParams = {new ExtraParam("max_keywords", "30")};
        MonkeyLearnResponse res = ml.extractors.extract("ex_y7BPYzNG", textList, extraParams);
        System.out.println( res.arrayResult );


    }
}

monkeylearn-java's People

Contributors

feliperazeek avatar gonz avatar raulgarreta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monkeylearn-java's Issues

version 3?

When will this client be compatible with api version 3

Ability to supply API parameters

There don't appear to be any way to specify any of the API parameters, specifically for the extractors. For example, I would like to override the settings for max_keywords and lowercase on the Keyword Extractor API, but there's no way to do that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.