-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataParser.java
More file actions
64 lines (46 loc) · 1.25 KB
/
DataParser.java
File metadata and controls
64 lines (46 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.scipiogothicus.LanguageTrainer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class DataParser {
File file;
ArrayList<String> dataLines = new ArrayList<String>();
ArrayList<LanguageNode> languageNodes = new ArrayList<LanguageNode>();
public DataParser(String fileName) {
this.file = new File(fileName);
try {
Scanner scan = new Scanner(file);
while(scan.hasNext()) {
dataLines.add(scan.nextLine());
}
scan.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
public void printContents() {
System.out.println(languageNodes.toString());
}
public ArrayList<LanguageNode> convertDataToNodes() {
for(String str: dataLines) {
String[] splitStr;
String word;
String pronun;
String def;
splitStr = str.split("\\s+");
if(splitStr.length == 2) {
word = splitStr[0];
pronun = splitStr[1];
languageNodes.add(new LanguageNode(word, pronun));
} else {
word = splitStr[0];
pronun = splitStr[1];
def = splitStr[2];
languageNodes.add(new LanguageNode(word, pronun, def));
}
}
return languageNodes;
}
}