자바(Java)/스크래핑, 크롤링
네이버 파파고 papago api 최대 5000자. 자바 substring 문장단위로 끊기
xemaker
2020. 9. 1. 14:46
네이버 파파고 papago api를 사용하다가 한번에 최대 5000자 까지만 된다는 것을 알게되었다. 이런..
int len = (int) Math.ceil((double) cont.length() / 5000);
System.out.println("len="+len);
String newCont="";
String newContTemp="";
int last1=0;
int last2=5000;
for(int i=0;i<len;i++) {
if(i==len-1) {
cont1=cont.substring(last1);
newContTemp=cont1;
newContTemp=getHangul(newContTemp);
newCont=newCont+newContTemp;
}else {
cont1=cont.substring(last1, last2);
last2=cont1.lastIndexOf(".")+1;
newContTemp=cont.substring(last1,last1+last2);
newContTemp=getHangul(newContTemp);
newCont=newCont+newContTemp;
last1=last1+last2;
last2=last1+5000;
}
}
이런식으로 자바 substring 을 사용하여 문장 중간에 끊기지 않고 마침표에서 끊어서 매끄럽게 번역할 수 있게 작업을 했다.