package template_sentence_generator;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.atilika.kuromoji.Token;
import org.atilika.kuromoji.Tokenizer;

public class NewSentenceList1 {

	public static List<String> createNewSentenceList(int count) throws FileNotFoundException, IOException{
		Tokenizer tokenizer;
		List<Token> tokens;
		List<Noun> nounlist = NounList1.getNounList("data/comentAll.txt");
		List<String> comment = OriginSentenceList.createOriginSentenceList("data/comentAll.txt");
		List<String> newSentencelist = new ArrayList<String>();
		int i=0;
		String neWsentence="";
		String origin;
		Random rnd = new Random();

		tokenizer = Tokenizer.builder().userDictionary("resources/userdict.txt").build();

		while(i<count){
			origin="";
			neWsentence="";
			boolean hantei=false;


			tokens = tokenizer.tokenize(comment.get(rnd.nextInt(comment.size())));



			for(Token token:tokens){
				if(token.getPartOfSpeech().startsWith("名詞,固有名詞,")&&token.isKnown()){
					hantei=true;
					Collections.shuffle(nounlist);
					for(Noun noun:nounlist){
						if(noun.getPart().equals(token.getPartOfSpeech())){
							neWsentence += noun.getName();
							break;
						}
					}
				}

				else{
					neWsentence += token.getSurfaceForm();
				}
				origin += token.getSurfaceForm();
			}


			if(hantei){
				newSentencelist.add(neWsentence+"\n元の文章：\n"+origin);
				i++;
			}
		}

		return newSentencelist;

	}

}
