Browse Source

Fixed the guaranteed-dictionary-update bug

It wasn't actually guaranteed, it turns out.  I was iterating over
dictionary keys, which is done in arbitrary order.  The result was that
in different executions of the program, the corpus was generated
differently, so the hashes differed, and the language had to be updated.
Sorting the keys before adding them to the list of number-words fixed
the problem.
Clara Hobbs 8 years ago
parent
commit
557f0b60cb
1 changed files with 7 additions and 7 deletions
  1. 7
    7
      numberparser.py

+ 7
- 7
numberparser.py View File

@@ -65,20 +65,20 @@ class NumberParser:
65 65
 
66 66
     def __init__(self):
67 67
         self.number_words = []
68
-        for word in self.zero:
68
+        for word in sorted(self.zero.keys()):
69 69
             self.number_words.append(word)
70
-        for word in self.ones:
70
+        for word in sorted(self.ones.keys()):
71 71
             self.number_words.append(word)
72
-        for word in self.special_ones:
72
+        for word in sorted(self.special_ones.keys()):
73 73
             self.number_words.append(word)
74
-        for word in self.tens:
74
+        for word in sorted(self.tens.keys()):
75 75
             self.number_words.append(word)
76
-        for word in self.hundred:
76
+        for word in sorted(self.hundred.keys()):
77 77
             self.number_words.append(word)
78
-        for word in self.exp:
78
+        for word in sorted(self.exp.keys()):
79 79
             self.number_words.append(word)
80 80
         self.mandatory_number_words = self.number_words.copy()
81
-        for word in self.allowed:
81
+        for word in sorted(self.allowed):
82 82
             self.number_words.append(word)
83 83
 
84 84
     def parse_number(self, text_line):

Loading…
Cancel
Save