Twinreader API 사용하기 3

작성자 이호영 수정일 2023-01-06 11:28

#Twinreader2.0, #template, #API, #Detection, #결과 추출

아티클 관련 제품: Twinreader2.0

들어가며


API 사용 방법

  • 각 요청에 맞는 URL과 data를 넣어서 curl 명령어를 사용하여 호출합니다.
Curl 명령어 전송하기

curl [Server IP]:port [API URL]  \
-- header "Content-Type: application/json" \
--data {
     [요청 구조에서 필수 / 선택으로 정의되어 있는 Parameter]
}



Template 결과 추출 요청

  • 지정한 template로 분석한 결과를 추출하는 API 입니다.


API 형식


Protocol전송방식HeaderURL
httpPost {"Content-Type": "application/json"}/twinreader-mgr-service/api/v1/template/extract/path
요청 코드

curl http://Server_IP_주소/twinreader-mgr-service/api/v1/template/extract/path \

--request POST \

--header "Content-Type: application/json" \

--data '{"imagePath": ["/Image_Sample.jpg"], "templateName": "공통"}'



요청 구조


필수 / 선택Parameter타입설명
필수imagePathString분석 이미지 경로
선택templateNameString분석 데이터에 적용할 template 이름
선택templateListArray다중 페이지를 위한 복수 template 이름
페이지 수보다 template의 수가 적다면 첫 번째 선언된 template가
적용되어 추출


요청 json 예시
{
    "imagePath": "/dir/testImage.png",
    "templateList": ["세부산정서"]
			or
    "templateName": "세부산정서"
}


결과 구조

Parameter타입설명
resultPathString생성된 결과 파일 경로
successBoolean요청 성공 여부( true / false )
messageString | nullerror message


결과 json 예시
{
    "resultPath": "dir/testImage_png/templateJson/testImage_png_template_result.json",
    "success": true,
    "message": ""
}


결과 message 종류


Error Message설명

Classification JSON Read Fail    

Classification 파일을 읽을 수 없습니다.
TemplateName is not defined in Classification.json   Classification 파일에 templateName이 정의되지 않았습니다.
Template Error - Object Create Fail   Template error - 객체 생성에 실패했습니다.


Detection 결과 요청

  • 단일 건에 대한 detection 결과를 요청하는 API입니다.


API 형식


Protocol전송방식HeaderURL
httpGet {"Content-Type": "application/json"}/twinreader-mgr-service/api/v1/template/rawDataResult 
요청 코드

curl http://Server_IP_주소/twinreader-mgr-service/api/v1/template/rawDataResult \

--data-urlencode "image=sample_image_1.jpg"



요청 구조


필수 / 선택Parameter타입설명
필수imageString요청 할 대상 이미지
선택dirString대상 이미지의 디렉토리


요청 Query 예시
/twinreader-mgr-service/api/v1/template/rawDataResult?dir=dir/&image=sample_image_1.png


결과 구조


Parameter타입설명
resultObject결과 데이터
messageString결과 실패 message


결과 json 예시
{
    result: {
        "Page1": {
            "fileNm": "sample_image_png-1.png",
            "category": "처방전",
            "imageWidth": "1195",
            "imageHeight": "1686",
            "contents": […]
        }
    },
    message: ""
}


결과 message 종류


Message설명
Allow only one or none parameter "dir"query에 dir를 list로 조회한 경우(없거나 하나의 값만 허용)
Allow only one parameter "image"query에 image를 list로 조회한 경우(오로지 하나의 값만 허용)
Not find directorydir를 잘못 입력하거나 없는 경우
Not find directory or image fileimage명을 잘못 입력했거나 확장자가 없는 경우
Not find file

    

분석파일을 못 찾은 경우




기준 정보 갱신 요청

  • twinreader 분석에 필수적으로 필요한 정보(classification, detailClassification, template, plugin, postPlugin)가 변경 되었을 때 갱신을 요청하는 API입니다.


API 형식


Protocol전송방식HeaderURL
httpGet {"Content-Type": "application/json"}/twinreader-mgr-service/api/v1/admin/reload
요청 코드

curl http://Server_IP_주소/twinreader-mgr-service/api/v1/admin/reload \

--header "Content-Type: application/json" \

--data '{"template":true}'


요청 Query 구조


필수 / 선택Parameter타입설명
선택classificationBooleanclassification의 변경 내용 갱신 요청
선택detailClassificationBooleandetailClassification의 변경 내용 갱신 요청
선택templateBooleantemplate의 변경 내용 갱신 요청
선택pluginBooleanplugin의 변경 내용 갱신 요청
선택postPluginBooleanpostPlugin의 변경 내용 갱신 요청


요청 Query 예시
{
    "classification": true,
    "detailClassification": false,
    "template": false,
    "plugin": false,
    "postPlugin": true
}
결과 구조


Parameter타입설명
successBoolean요청성공 여부(true/false)
codeString요청에 대한 상태코드
dataString요청 실패 시 실패 코드에 대한 설명 / 성공 시 "" 빈 문자열 반환


결과 json 예시
{
    "success": true,
    "code": "AD04",
    "data": "template, classification, plugin reload fail."
}
결과 message 종류


Error Message설명

AD04: template, classification, plugin reload fail. 

갱신 시간을 DB에 저장을 실패했을 경우 메시지



마무리

  • API를 사용하여 분석 결과를 받는 방법에 대해 알아보았습니다.

아티클이 유용했나요?

훌륭합니다!

피드백을 제공해 주셔서 감사합니다.

도움이 되지 못해 죄송합니다!

피드백을 제공해 주셔서 감사합니다.

아티클을 개선할 수 있는 방법을 알려주세요!

최소 하나의 이유를 선택하세요
CAPTCHA 확인이 필요합니다.

피드백 전송

소중한 의견을 수렴하여 아티클을 개선하도록 노력하겠습니다.

02-558-8300