package genbook;

import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.util.regex.*;
import java.io.IOException;
public class WordInSentence {
	
	private String input;
	private String toSearchWord;
	private StringBuffer sentences = new StringBuffer();
	private String lregex;
	
	public WordInSentence(String input, String toSearchWord){
		this.input = input;
		this.toSearchWord = toSearchWord;
		lregex ="[^.!?]*"+toSearchWord+"[^!?.]*[!?.]?";
	}
	
	public StringBuffer getSentences(){
	
		Pattern p = Pattern.compile(lregex, Pattern.CASE_INSENSITIVE);
		Matcher m = p.matcher(input);

		//picks the first sentence that it finds
		//bring some logic here to pick a sentence that's not just the first one
		
		if (m.find()) {
			//System.out.println("---Found something!!--- "+ m.group());
			//here is where you can write to a log file
			sentences.append(m.group());
			
		}
		//System.out.println("SENTENCES: "+sentences);
		
		return sentences;
	}
		
	
	 
}
