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++ {
 | 
						for attempt := 0; attempt < 10; attempt++ {
 | 
				
			||||||
		p = make(MarkovPrefix, c.prefixLen)
 | 
							p = make(MarkovPrefix, c.prefixLen)
 | 
				
			||||||
		inWords := strings.Split(in, " ")
 | 
							inWords := strings.Split(in, " ")
 | 
				
			||||||
 | 
							if attempt < 9 {
 | 
				
			||||||
			start = inWords[rand.Intn(len(inWords))]
 | 
								start = inWords[rand.Intn(len(inWords))]
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								start = ""
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		p.Shift(start)
 | 
							p.Shift(start)
 | 
				
			||||||
		xlog.Debug("Looking for answer on [%s]", start)
 | 
							xlog.Debug("Looking for answer on [%s]", start)
 | 
				
			||||||
		for i := 0; i < n; i++ {
 | 
							for i := 0; i < n; i++ {
 | 
				
			||||||
| 
						 | 
					@ -242,14 +246,8 @@ func (c *MarkovChain) Generate(n int, in string) string {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	start = strings.Trim(start, " ")
 | 
						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, " ")
 | 
						return start + " " + strings.Join(words, " ")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Save the chain to a file
 | 
					// Save the chain to a file
 | 
				
			||||||
func (c *MarkovChain) Save(fileName string) error {
 | 
					func (c *MarkovChain) Save(fileName string) error {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue