Skip to content

Instantly share code, notes, and snippets.

@Linusstrom
Created August 13, 2012 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Linusstrom/3342846 to your computer and use it in GitHub Desktop.
Save Linusstrom/3342846 to your computer and use it in GitHub Desktop.
class WordNgram{
private int size;
private String[] words ={};
public WordNgram(int size){
this.size = size;
}
public WordNgram(int size, String words){
this.size = size;
this.words = words.split(" ");
}
public String getWord(int size){
String result = this.words[size - 1];
if (result == null) {
System.out.println("index out of bounds");
return "";
}
return result;
}
public String toString(){
if (words.length == 0){
String value = "";
for ( int n=0; n<size; n++) {
value = value + ",";
}
return value;
}
if (size > this.words.length) {
String value = "";
for ( int n=0; n<size; n++) {
value = value + " " + words[n % words.length];
}
return value;
}
while(true){
words[n] + " " + words[size + n - 1];
for (int n=0; n<size; n++) {
value = value + " " + words[n % words.length];
}
}
public static void main(String[] args) {
WordNgram w1 = new WordNgram(7, "pelle kalle");
System.out.println(w1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment