src/textgen/MarkovTextGeneratorLoL.java
/** Train the generator by adding the sourceText */
Train the generator by adding the sourceText
Train the generator by adding the sourceText
@Override
	public void train(String sourceText)
	{
		if(!sourceText.trim().isEmpty()){
		String prevWord=null;
		String [] wordArray = sourceText.split("[\\s]+");
		List <String> wordTokens = new ArrayList<String>();
		wordTokens=Arrays.asList(wordArray);
		/*
		for (String string : tokensList) {
			if(isWord(string)){
				wordTokens.add(string);
			}
		}*/
		starter=wordTokens.get(0);
		prevWord=starter;
		ListNode prevWordNode = null;
		String w=null;
		for(int i=1;i<wordTokens.size();i++){
			w=wordTokens.get(i);
			prevWordNode=new ListNode(prevWord);
			ListNode existingPrevListNode = getExistingNode(prevWord);
			if (null!= existingPrevListNode){			
				existingPrevListNode.addNextWord(w);		
			} else {
				wordList.add(prevWordNode);			
				prevWordNode.addNextWord(w);		
			}
			prevWord=w;
		}
		prevWordNode=new ListNode(prevWord);
		wordList.add(prevWordNode);
		prevWordNode.addNextWord(starter);
		}
	}
@ Override public void train ( String sourceText ) { if ( ! sourceText . trim ( ) . isEmpty ( ) ) { String prevWord = null ; String [ ] wordArray = sourceText . split ( "[\\s]+" ) ; List < String > wordTokens = new ArrayList < String > ( ) ; wordTokens = Arrays . asList ( wordArray ) ; /*
		for (String string : tokensList) {
			if(isWord(string)){
				wordTokens.add(string);
			}
		}*/ starter = wordTokens . get ( 0 ) ; prevWord = starter ; ListNode prevWordNode = null ; String w = null ; for ( int i = 1 ; i < wordTokens . size ( ) ; i ++ ) { w = wordTokens . get ( i ) ; prevWordNode = new ListNode ( prevWord ) ; ListNode existingPrevListNode = getExistingNode ( prevWord ) ; if ( null != existingPrevListNode ) { existingPrevListNode . addNextWord ( w ) ; } else { wordList . add ( prevWordNode ) ; prevWordNode . addNextWord ( w ) ; } prevWord = w ; } prevWordNode = new ListNode ( prevWord ) ; wordList . add ( prevWordNode ) ; prevWordNode . addNextWord ( starter ) ; } }
Train the generator by adding the sourceText
Train the generator by adding the sourceText
//		tokensList=getTokens("[!?.]+|[a-zA-Z]+",sourceText); //check to see if prevWord is already a node in the list //add w as a nextWord to the prevWord node //add a node to the List with "prevWord" as the node's word  //add w as a nextWord to the prevWord node