package com.lahodiuk.postagger;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Sentence {

	public static void main(String[] args) {
		Sentence sentence = new Sentence("В истории программы это уже не первый «ребрендинг».");
		System.out.println(sentence.getSentence());
		for (String s : sentence.getTokens()) {
			System.out.println(s);
		}
	}

	private String sentence;

	private List<String> tokens;

	public Sentence(String sentence) {
		this.sentence = sentence;

		this.tokens = new ArrayList<>();
		Pattern pattern = Pattern.compile("(\\d+|\\p{L}+|[^\\s])");
		Matcher matcher = pattern.matcher(sentence);
		while (matcher.find()) {
			this.tokens.add(matcher.group());
		}
	}

	public List<String> getTokens() {
		return this.tokens;
	}

	public String getSentence() {
		return this.sentence;
	}
}

@@ -52,35 +52,115 @@
 rray
-List;%0Aimport java.util.List
+Deque;%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.Queue
 ;%0Aim
@@ -494,24 +494,113 @@
 tln(s);%0A%09%09%7D%0A
+%09%09for (WordWindow ww : sentence.getWordWindows(2, %22_%22)) %7B%0A%09%09%09System.out.println(ww);%0A%09%09%7D%0A
 %09%7D%0A%0A%09private
@@ -1048,11 +1048,1217 @@
 ence;%0A%09%7D
+%0A%0A%09public List%3CWordWindow%3E getWordWindows(int neighboursCount, String margin) %7B%0A%09%09List%3CWordWindow%3E wordWindows = new ArrayList%3C%3E();%0A%0A%09%09Queue%3CString%3E previousTokens = new ArrayDeque%3C%3E(neighboursCount);%0A%09%09for (int i = 0; i %3C neighboursCount; i++) %7B%0A%09%09%09previousTokens.add(margin);%0A%09%09%7D%0A%0A%09%09Queue%3CString%3E followingTokens = new ArrayDeque%3C%3E(neighboursCount);%0A%09%09Iterator%3CString%3E followingTokensIterator = this.tokens.iterator();%0A%09%09if (followingTokensIterator.hasNext()) %7B%0A%09%09%09// skip first token%0A%09%09%09followingTokensIterator.next();%0A%09%09%7D%0A%09%09for (int i = 0; i %3C neighboursCount; i++) %7B%0A%09%09%09if (followingTokensIterator.hasNext()) %7B%0A%09%09%09%09followingTokens.add(followingTokensIterator.next());%0A%09%09%09%7D else %7B%0A%09%09%09%09followingTokens.add(margin);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09for (String token : this.tokens) %7B%0A%09%09%09WordWindow ww = new WordWindow();%0A%09%09%09ww.setPreviousTokens(previousTokens);%0A%09%09%09ww.setCurrentToken(token);%0A%09%09%09ww.setFollowingTokens(followingTokens);%0A%0A%09%09%09wordWindows.add(ww);%0A%0A%09%09%09previousTokens.poll();%0A%09%09%09previousTokens.add(token);%0A%0A%09%09%09followingTokens.poll();%0A%09%09%09if (followingTokensIterator.hasNext()) %7B%0A%09%09%09%09followingTokens.add(followingTokensIterator.next());%0A%09%09%09%7D else %7B%0A%09%09%09%09followingTokens.add(margin);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return wordWindows;%0A%09%7D
 %0A%7D%0A

Generating word windows from tokens of the sentence