/
분석요청 및 결과 데이터

문서 최신화를 위해서 변경된 부분 또는 수정할 부분이 발견되면 발견자가 꼭! 수정해주시기 바랍니다. !!!

분석요청 및 결과 데이터

  • 분석결과를 요청하면 분석결과가 메시지 Q에 저장되고 메시지 Q에서 데이터를 가져가 쓰는 형태

  • Rest API (post)

  • Request (json object)

Key

Description

필수여부

Type

Child Type

start_ymd

시작 년월일

Y

String

 

end_ymd

끝 년월일

Y

String

 

media

미디어 배열

Y

JsonArray

String

keywords

키워드 배열

Y

JsonArray

String

modules

모듈 배열

N

JsonArray

String

stopwords

불용어

N

JsonArray

String

  • 필수여부가 N 인 항목들은 json 데이터를 만들때 만들지 않아도 됩니다.

  • sample

{ "start_ymd":"20200201", "end_ymd":"20200228", "media":[ "001", "002", "003", "004", "005" ], "keywords":[ "환경부", "먼지" ], "modules":[ "TF_WORD", "TFIDF", "TF_CLASSIFY", "TF_CONTENTS", "SNA", "LDA" ], "stopwords":[ "기자", "지원" ] }
  • detail sample (필요한 옵션만 추가 기입, 불필요한 옵션은 기입하지 않아도 됨)

{ "end_ymd":"20200630", "keywords":[ { "start_time":1591801200000, "in_filters":[ "보건" ], "out_filters":[ "키트" ], "end_time":1592492400000, "keyword":"코로나" }, "환경" ], "start_ymd":"20200611", "media":[ 11, 13, 16, 276, 274, 268, 282, 266 ], "modules":[ { "module":"SNA", "count":100 } ], "stopwords":[ "기자", "지원" ] }
  • java sample code

package org.moara.keyword.test; import org.json.JSONArray; import org.json.JSONObject; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class TestAnalysis { public static String call( String value, String method){ try { // URL url = new URL("http://127.0.0.1:33377/keyword/" + method); URL url = new URL("http://moara.org:10035/keyword/" + method); // URL url = new URL("http://demo.moara.org:10335/keyword/" + method); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); conn.setInstanceFollowRedirects(false); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Accept", "application/json"); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setUseCaches(false); OutputStream stream = conn.getOutputStream(); stream.write(value.getBytes()); stream.flush(); stream.close(); String charSet = "UTF-8"; StringBuilder messageBuilder = new StringBuilder(); BufferedReader br; if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { br = new BufferedReader( new InputStreamReader(conn.getInputStream(), charSet)); for (;;) { String line = br.readLine(); if (line == null) break; messageBuilder.append('\n').append(line); } br.close(); }else{ throw new RuntimeException("http response fail: " + conn.getResponseCode()); } String message ; if(messageBuilder.length() > 0){ message = messageBuilder.substring(1); }else{ message = ""; } return message; }catch(Exception e){ throw new RuntimeException(e); } } public static void main(String[] args) { JSONObject param = new JSONObject(); param.put("start_ymd", "20200228"); param.put("end_ymd", "20200228"); JSONArray media = new JSONArray(); media.put("001"); // media.put("002"); // media.put("003"); // media.put("004"); // media.put("005"); JSONArray keywords = new JSONArray(); keywords.put("미세먼지"); // keywords.put("#제외"); param.put("keywords", keywords); param.put("media", media); System.out.println(param.toString()); //모듈을 설정하여 보낼때 //설정하지 않으면 기본설정을 따름 //인삭할 수 있는 모듈 //TF_WORD, TF_CLASSIFY, TF_CONTENTS, SNA, LDA JSONArray modules = new JSONArray(); modules.put("TF_WORD"); modules.put("TFIDF"); // modules.put("TF_CLASSIFY"); // modules.put("TF_CONTENTS"); // modules.put("SNA"); // modules.put("LDA"); //모듈을 따로설정하지 않고 기본설정을 따르는 경우 추가하지 않아도 됨 param.put("modules", modules); //분석 아이디 얻기 String analysisId = call(param.toString(),"analysis"); System.out.println("analysis id: " + analysisId); //분석 아이디를 얻은후 관련 메시지 얻기 boolean isEnd = false; for (int i = 0; i <5000 ; i++) { String jsonValue = TestAnalysis.call(analysisId,"message"); // System.out.println("response:\n" + jsonValue); JSONObject jsonObject = new JSONObject(jsonValue); JSONArray messageArray = jsonObject.getJSONArray("messages"); for (int j = 0; j <messageArray.length() ; j++) { String message = messageArray.getString(j); System.out.println("============================================== message ==============================================\n"); System.out.println(message); } if(jsonObject.getBoolean("is_end")){ isEnd = true; break; } try{ Thread.sleep(1000); }catch (Exception e){ e.printStackTrace(); } } if(!isEnd){ System.out.println("error time out"); } } }

 

  • Response (string)

    • analysis message id (string)

    • ample response message : 13771

  • Response message id 를 활용하여 결과 데이터는 polling 으로 요청

  • Rest API (post)

  • Request (string)

    • address/wigomon/analysis 에서 response 받은 message id 전달 post))

    • sample: 13771

Key

Description

Type

Child Type

is_end

종료여부

Bolean

 

messages

메시지 배열

JsonArray

String

  • messages 에서는 트랜드, 의미네트워크, 토픽결과에 따라 다른메시지 값을 가지고 있게되고 관련된 상세내용은 아래 목록에서 설명합니다.

  • 관련 이벤트를 호출할떄마다 새로운 메시지만 받을 수 있으며 이전에 보낸 메시지는 소멸됩니다.

  • is_end = true 이면 관련 메시지는 더 이상 생성되지 않아서 polling 을 중단해야 합니다.

  • message sample

    • {"is_end":false,"messages":["{"type":"term_frequency_word","message":{"times":[1577286000000,1577307600000,1577329200000,1577350800000,1577372400000,1577394000000,1577415600000,1577437200000,1577458800000,1577480400000,1577502000000,1577523600000,1577545200000,1577566800000,1577588400000,1577610000000,1577631600000, …..

Related content

Copyright(c) WIGO Corp. All rights reserved.