@@ -217,13 +217,13 @@ class UntilNode(BinaryOperatorNode):
217217 def __init__ (self , left , right ):
218218 super ().__init__ (UntilNode .symbol , left , right )
219219
220- def __to_english__ (self ):
221- x = ltltoeng .apply_special_pattern_if_possible (self )
222- if x is not None :
223- return x
224- lhs = self .left .__to_english__ ().rstrip ('.' )
225- rhs = self .right .__to_english__ ().rstrip ('.' )
226- return ltltoeng . capitalize_sentence ( f"{ lhs } until { rhs } " )
220+ def __to_english__ (self ):
221+ x = ltltoeng .apply_special_pattern_if_possible (self )
222+ if x is not None :
223+ return x
224+ lhs = self .left .__to_english__ ().rstrip ('.' )
225+ rhs = self .right .__to_english__ ().rstrip ('.' )
226+ return f"{ lhs } until { rhs } "
227227
228228 def __forge__ (self ):
229229 return f"({ self .left .__forge__ ()} UNTIL { self .right .__forge__ ()} )"
@@ -237,12 +237,12 @@ class NextNode(UnaryOperatorNode):
237237 def __init__ (self , operand ):
238238 super ().__init__ (NextNode .symbol , operand )
239239
240- def __to_english__ (self ):
241- x = ltltoeng .apply_special_pattern_if_possible (self )
242- if x is not None :
243- return x
244- op = self .operand .__to_english__ ().rstrip ('.' )
245- return ltltoeng . capitalize_sentence ( f"in the next step, { op } " )
240+ def __to_english__ (self ):
241+ x = ltltoeng .apply_special_pattern_if_possible (self )
242+ if x is not None :
243+ return x
244+ op = self .operand .__to_english__ ().rstrip ('.' )
245+ return f"in the next step, { op } "
246246
247247 def __forge__ (self ):
248248 return f"(NEXT_STATE { self .operand .__forge__ ()} )"
@@ -256,20 +256,20 @@ class GloballyNode(UnaryOperatorNode):
256256 def __init__ (self , operand ):
257257 super ().__init__ (GloballyNode .symbol , operand )
258258
259- def __to_english__ (self ):
260- x = ltltoeng .apply_special_pattern_if_possible (self )
261- if x is not None :
262- return x
263-
264- op = self .operand .__to_english__ ().rstrip ('.' )
265- patterns = [
266- f"it is always the case that { op } " ,
267- f"at all times, { op } " ,
268- f"{ op } is always true"
269- ]
270-
271- english = random . choice (patterns )
272- return ltltoeng . capitalize_sentence ( english )
259+ def __to_english__ (self ):
260+ x = ltltoeng .apply_special_pattern_if_possible (self )
261+ if x is not None :
262+ return x
263+
264+ op = self .operand .__to_english__ ().rstrip ('.' )
265+ patterns = [
266+ f"it is always the case that { op } " ,
267+ f"at all times, { op } " ,
268+ f"{ op } is always true"
269+ ]
270+
271+ english = ltltoeng . choose_best_sentence (patterns )
272+ return english
273273
274274 def __forge__ (self ):
275275 return f"(ALWAYS { self .operand .__forge__ ()} )"
@@ -287,10 +287,10 @@ def __to_english__(self):
287287 x = ltltoeng .apply_special_pattern_if_possible (self )
288288 if x is not None :
289289 return x
290- op = self .operand .__to_english__ ().rstrip ('.' )
291-
292- english = f"eventually, { op } "
293- return ltltoeng . capitalize_sentence ( english )
290+ op = self .operand .__to_english__ ().rstrip ('.' )
291+
292+ english = f"eventually, { op } "
293+ return english
294294
295295 def __forge__ (self ):
296296 return f"(EVENTUALLY { self .operand .__forge__ ()} )"
@@ -306,13 +306,13 @@ class OrNode(BinaryOperatorNode):
306306 def __init__ (self , left , right ):
307307 super ().__init__ (OrNode .symbol , left , right )
308308
309- def __to_english__ (self ):
310- x = ltltoeng .apply_special_pattern_if_possible (self )
311- if x is not None :
312- return x
313- lhs = self .left .__to_english__ ().rstrip ('.' )
314- rhs = self .right .__to_english__ ().rstrip ('.' )
315- return ltltoeng . capitalize_sentence ( f"either { lhs } or { rhs } " )
309+ def __to_english__ (self ):
310+ x = ltltoeng .apply_special_pattern_if_possible (self )
311+ if x is not None :
312+ return x
313+ lhs = self .left .__to_english__ ().rstrip ('.' )
314+ rhs = self .right .__to_english__ ().rstrip ('.' )
315+ return f"either { lhs } or { rhs } "
316316
317317
318318
@@ -322,13 +322,13 @@ class AndNode(BinaryOperatorNode):
322322 def __init__ (self , left , right ):
323323 super ().__init__ (AndNode .symbol , left , right )
324324
325- def __to_english__ (self ):
326- x = ltltoeng .apply_special_pattern_if_possible (self )
327- if x is not None :
328- return x
329- lhs = self .left .__to_english__ ().rstrip ('.' )
330- rhs = self .right .__to_english__ ().rstrip ('.' )
331- return ltltoeng . capitalize_sentence ( f"both { lhs } and { rhs } " )
325+ def __to_english__ (self ):
326+ x = ltltoeng .apply_special_pattern_if_possible (self )
327+ if x is not None :
328+ return x
329+ lhs = self .left .__to_english__ ().rstrip ('.' )
330+ rhs = self .right .__to_english__ ().rstrip ('.' )
331+ return f"both { lhs } and { rhs } "
332332
333333
334334class NotNode (UnaryOperatorNode ):
@@ -338,64 +338,70 @@ def __init__(self, operand):
338338
339339 def __to_english__ (self ):
340340 x = ltltoeng .apply_special_pattern_if_possible (self )
341- if x is not None :
342- return x
343-
344- op = self .operand .__to_english__ ().rstrip ('.' )
345-
346- ## If the operand is a literal, we can just negate it
347- if isinstance (self .operand , LiteralNode ):
348- return ltltoeng . capitalize_sentence ( f"not { op } " )
349- else :
350- return ltltoeng . capitalize_sentence ( f"it is not the case that { op } " )
341+ if x is not None :
342+ return x
343+
344+ op = self .operand .__to_english__ ().rstrip ('.' )
345+
346+ ## If the operand is a literal, we can just negate it
347+ if isinstance (self .operand , LiteralNode ):
348+ return f"not { op } "
349+ else :
350+ return f"it is not the case that { op } "
351351
352352class ImpliesNode (BinaryOperatorNode ):
353353 symbol = IMPLIES_SYMBOL
354354 def __init__ (self , left , right ):
355355 super ().__init__ (ImpliesNode .symbol , left , right )
356356
357- def __to_english__ (self ):
358- x = ltltoeng .apply_special_pattern_if_possible (self )
359- if x is not None :
360- return x
361-
362- lhs = self .left .__to_english__ ().rstrip ('.' )
363- rhs = self .right .__to_english__ ().rstrip ('.' )
364-
365- # Potential patterns:
366- patterns = [
367- f"if { lhs } , then { rhs } " ,
368- f"{ lhs } implies { rhs } " ,
357+ def __to_english__ (self ):
358+ x = ltltoeng .apply_special_pattern_if_possible (self )
359+ if x is not None :
360+ return x
361+
362+ lhs = self .left .__to_english__ ().rstrip ('.' )
363+ rhs = self .right .__to_english__ ().rstrip ('.' )
364+
365+ lhs = ltltoeng .normalize_embedded_clause (lhs )
366+ rhs = ltltoeng .normalize_embedded_clause (rhs )
367+
368+ # Potential patterns:
369+ patterns = [
370+ f"if { lhs } , then { rhs } " ,
371+ f"{ lhs } implies { rhs } " ,
369372 f"whenever { lhs } , then { rhs } "
370- ]
371-
372- # Choose a pattern randomly, and then return the corrected sentence
373- english = random . choice (patterns )
374- return ltltoeng . capitalize_sentence ( english )
373+ ]
374+
375+ # Choose the most fluent pattern rather than picking randomly
376+ english = ltltoeng . choose_best_sentence (patterns )
377+ return english
375378
376379
377380class EquivalenceNode (BinaryOperatorNode ):
378381 symbol = EQUIVALENCE_SYMBOL
379382 def __init__ (self , left , right ):
380383 super ().__init__ (EquivalenceNode .symbol , left , right )
381384
382- def __to_english__ (self ):
383- x = ltltoeng .apply_special_pattern_if_possible (self )
384- if x is not None :
385- return x
386- lhs = self .left .__to_english__ ().rstrip ('.' )
387- rhs = self .right .__to_english__ ().rstrip ('.' )
388-
389- # Potential patterns:
390- patterns = [
391- f"{ lhs } if and only if { rhs } " ,
392- f"{ lhs } exactly when { rhs } " ,
385+ def __to_english__ (self ):
386+ x = ltltoeng .apply_special_pattern_if_possible (self )
387+ if x is not None :
388+ return x
389+ lhs = self .left .__to_english__ ().rstrip ('.' )
390+ rhs = self .right .__to_english__ ().rstrip ('.' )
391+
392+ lhs = ltltoeng .normalize_embedded_clause (lhs )
393+ rhs = ltltoeng .normalize_embedded_clause (rhs )
394+
395+ # Potential patterns:
396+ patterns = [
397+ f"{ lhs } if and only if { rhs } " ,
398+ f"{ lhs } exactly when { rhs } " ,
393399 f"{ lhs } is equivalent to { rhs } "
394- ]
395-
396- # Choose a pattern randomly, and then return the corrected sentence
397- english = random . choice (patterns )
398- return ltltoeng . capitalize_sentence ( english )
400+ ]
401+
402+ # Choose the most fluent pattern rather than picking randomly
403+ english = ltltoeng . choose_best_sentence (patterns )
404+ return english
399405
400406
401407
0 commit comments