You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (! lines.hasNext) thrownewException("empty file")
53
-
lines.next // skip first line (headers)
54
-
55
-
for (line <- lines)
56
-
if (line.nonEmpty)
57
-
fromLine(line) match{
58
-
caseSome(x) => info += x
59
-
caseNone=>
49
+
50
+
if (!lines.hasNext) {
51
+
logger.warning("wikipedias.csv is empty")
52
+
return info
53
+
}
54
+
55
+
lines.next() // skip header
56
+
57
+
for (line <- lines) {
58
+
if (line.nonEmpty) {
59
+
fromLine(line) match {
60
+
caseSome(wikiInfo) => info += wikiInfo
61
+
caseNone=>// skip malformed line
60
62
}
61
-
63
+
}
64
+
}
65
+
62
66
info
63
67
}
64
-
68
+
65
69
/**
66
70
* Reads a WikiInfo object from a single CSV line.
71
+
* Malformed lines are logged and skipped.
67
72
*/
68
73
deffromLine(line: String):Option[WikiInfo] = {
69
-
valfields= line.split(",", -1)
70
-
71
-
if (fields.length <15) thrownewException("expected [15] fields, found ["+fields.length+"] in line ["+line+"]")
72
-
73
-
valpages=try fields(4).toInt
74
-
catch { casenfe: NumberFormatException=>0 }
75
-
76
-
valwikiCode= fields(2)
77
-
if (!ConfigUtils.LanguageRegex.pattern.matcher(fields(2)).matches) thrownewException("expected language code in field with index [2], found line ["+line+"]")
78
-
79
-
//if(Language.map.keySet.contains(wikiCode))
80
-
Option(newWikiInfo(wikiCode, pages))
81
-
//else
82
-
//{
83
-
// logger.log(Level.WARNING, "Language: " + wikiCode + " will be ignored. Add this language to the addonlangs.json file to extract it.")
0 commit comments