1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Correct errors in beer names before using data from the DB
17 # Reads corrections from the file at `DB::corrections_path` which must be formatted like so:
20 # Wrong name -> Correct name
21 # Name with typo -> Clean name
28 # Path to file with the corrections
29 private var corrections_path
= "benitlux_corrections.txt"
31 # Corrections of beer name: wrong name to corrected name
32 private var corrections
: Map[String, String] is lazy
do
33 var map
= new HashMap[String, String]
36 if corrections_path
.file_exists
then
37 var lines
= corrections_path
.to_path
.read_lines
39 var parts
= line
.split
("->")
40 assert parts
.length
== 2 else print_error
"Error: wrong format in '{corrections_path}'"
41 map
[parts
[0].trim
] = parts
[1].trim
51 if beers
== null then return null
53 # Skip corrected beers
54 for beer
in beers
.reverse_iterator
do
55 if corrections
.keys
.has
(beer
.name
) then
65 var days
= super(beer
)
66 if beer
== null or days
== null then return days
68 # Merge days of `corrections` to `beer`
69 for from
, to
in corrections
do
70 if to
== beer
.name
then
71 var missing_days
= super(new Beer(from
, ""))
72 if missing_days
!= null then days
.add_all missing_days