if no answer can be found, build sentence on empty string
This commit is contained in:
		
							parent
							
								
									5207b0fde0
								
							
						
					
					
						commit
						78056ade35
					
				
					 1 changed files with 6 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -222,7 +222,11 @@ func (c *MarkovChain) Generate(n int, in string) string {
 | 
			
		|||
	for attempt := 0; attempt < 10; attempt++ {
 | 
			
		||||
		p = make(MarkovPrefix, c.prefixLen)
 | 
			
		||||
		inWords := strings.Split(in, " ")
 | 
			
		||||
		if attempt < 9 {
 | 
			
		||||
			start = inWords[rand.Intn(len(inWords))]
 | 
			
		||||
		} else {
 | 
			
		||||
			start = ""
 | 
			
		||||
		}
 | 
			
		||||
		p.Shift(start)
 | 
			
		||||
		xlog.Debug("Looking for answer on [%s]", start)
 | 
			
		||||
		for i := 0; i < n; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -242,13 +246,7 @@ func (c *MarkovChain) Generate(n int, in string) string {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
	start = strings.Trim(start, " ")
 | 
			
		||||
	if len(words) == 0 {
 | 
			
		||||
		xlog.Debug("No answer found")
 | 
			
		||||
		return start + " ... pfrrrz"
 | 
			
		||||
	} else {
 | 
			
		||||
		xlog.Debug("Found words: [%s]", strings.Join(words, " "))
 | 
			
		||||
	return start + " " + strings.Join(words, " ")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Save the chain to a file
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue