読者です 読者をやめる 読者になる 読者になる

m_shige1979のささやかな抵抗と欲望の日々

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

なんとなく作ったサイト

http://www.it-check-matome.info/


Github(注意すること)

https://github.com/mshige1979

watsonのNatural Language Classifierを試した

環境

ホスト

mac

開発環境

eclipse

準備

mavenを使えるようにしておく
ibm bluemixを登録しておく

分類器作成

Java
package com.nlc.sample1;

import java.io.File;

import com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier;

/**
 * Hello world!
 *
 */
public class App 
{
	
	final private static String UserName = "資格情報のユーザー名";
	final private static String Password = "資格情報のパスワード";
	
    public static void main( String[] args )
    {
        System.out.println( "Natural Language Classifier createClassifier start" );
        
        // インスタンス生成
        NaturalLanguageClassifier service = new NaturalLanguageClassifier();
        service.setUsernameAndPassword(UserName, Password);
        
        // 分類キー作成
        Classifier classifier = service.createClassifier("My Classifier", "ja", 
        		new File("./nlc/training02.csv")).execute();
        
        // 結果表示
        System.out.println(classifier);
        
        System.out.println( "Natural Language Classifier createClassifier end" );
    }
}

Natural Language Classifier createClassifier start
{
  "classifier_id": "分類器のID",
  "language": "ja",
  "name": "My Classifier",
  "status": "Training",
  "created": "2016-10-10T10:49:02.767",
  "status_description": "The classifier instance is in its training phase, not yet ready to accept classify requests",
  "url": "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/分類器のID"
}
Natural Language Classifier createClassifier end

分類器作成確認

Java
package com.nlc.sample2;

import com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier;

/**
 * Hello world!
 *
 */
public class App 
{
	
	final private static String UserName = "資格情報のユーザー名";
	final private static String Password = "資格情報のパスワード";
	
    public static void main( String[] args )
    {
        System.out.println( "Natural Language Classifier getClassifier start" );
        
        // インスタンス生成
        NaturalLanguageClassifier service = new NaturalLanguageClassifier();
        service.setUsernameAndPassword(UserName, Password);
        
        // 分類キーより取得
        Classifier classifier = service.getClassifier("分類器のID").execute();
        
        // 結果表示
        System.out.println(classifier);
        
        System.out.println( "Natural Language Classifier getClassifier end" );
    }
}

Natural Language Classifier getClassifier start
{
  "classifier_id": "分類器のID",
  "language": "ja",
  "name": "My Classifier",
  "status": "Available",
  "created": "2016-10-10T10:49:02.767",
  "status_description": "The classifier instance is now available and is ready to take classifier requests.",
  "url": "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/分類器のID"
}
Natural Language Classifier getClassifier end

分類処理

Java
package com.nlc.sample3;

import com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification;

/**
 * Hello world!
 *
 */
public class App 
{
	
	final private static String UserName = "資格情報のユーザー名";
	final private static String Password = "資格情報のパスワード";
	
    public static void main( String[] args )
    {
        System.out.println( "Natural Language Classifier classify start" );
        
        // インスタンス生成
        NaturalLanguageClassifier service = new NaturalLanguageClassifier();
        service.setUsernameAndPassword(UserName, Password);
        
        // 分類処理
        Classification classification = service.classify("分類器のID",
        		  "レトリバー").execute();
        
        // 結果表示
        System.out.println(classification);
        
        System.out.println( "Natural Language Classifier classify end" );
    }
}

Natural Language Classifier classify start
{
  "classes": [
    {
      "confidence": 0.9134736500854426,
      "class_name": "dog9"
    },
    {
      "confidence": 0.02781542678029993,
      "class_name": "dog2"
    },
    {
      "confidence": 0.016548178008526607,
      "class_name": "dog1"
    },
    {
      "confidence": 0.012186275707481627,
      "class_name": "dog3"
    },
    {
      "confidence": 0.006295053604774933,
      "class_name": "dog6"
    },
    {
      "confidence": 0.006138443595939543,
      "class_name": "dog5"
    },
    {
      "confidence": 0.005814188944908609,
      "class_name": "dog8"
    },
    {
      "confidence": 0.004186655385592137,
      "class_name": "dog7"
    },
    {
      "confidence": 0.004046516438248506,
      "class_name": "dog4"
    },
    {
      "confidence": 0.00349561144878548,
      "class_name": "dog10"
    }
  ],
  "classifier_id": "分類器のID",
  "text": "レトリバー",
  "top_class": "dog9",
  "url": "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/分類器のID"
}
Natural Language Classifier classify end

分類一覧取得

Java
package com.nlc.sample4;

import com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifiers;

/**
 * Hello world!
 *
 */
public class App 
{
	
	final private static String UserName = "資格情報のユーザー名";
	final private static String Password = "資格情報のパスワード";
	
    public static void main( String[] args )
    {
        System.out.println( "Natural Language Classifier getClassifiers start" );
        
        // インスタンス生成
        NaturalLanguageClassifier service = new NaturalLanguageClassifier();
        service.setUsernameAndPassword(UserName, Password);
        
        // 一覧を取得
        Classifiers classifiers = service.getClassifiers().execute();
        
        // 結果表示
        System.out.println(classifiers);
        
        System.out.println( "Natural Language Classifier getClassifiers end" );
    }
}

Natural Language Classifier getClassifiers start
{
  "classifiers": [
    {
      "classifier_id": "分類器のID",
      "language": "ja",
      "name": "My Classifier",
      "created": "2016-10-10T10:49:02.767",
      "url": "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/分類器のID"
    }
  ]
}
Natural Language Classifier getClassifiers end

分類器削除

Java
package com.nlc.sample5;

import com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifiers;

/**
 * Hello world!
 *
 */
public class App 
{
	
	final private static String UserName = "資格情報のユーザー名";
	final private static String Password = "資格情報のパスワード";
	
    public static void main( String[] args )
    {
        System.out.println( "Natural Language Classifier deleteClassifier start" );
        
        // インスタンス生成
        NaturalLanguageClassifier service = new NaturalLanguageClassifier();
        service.setUsernameAndPassword(UserName, Password);
        
        // 分類器を削除
        service.deleteClassifier("分類器のID").execute();
        
        System.out.println( "Natural Language Classifier deleteClassifier end" );
    }
}

とりあえずこんな感じ
watsonで使えるかわからないけどちょっとずつ調べていく

広告を非表示にする