Skip to content

Commit

Permalink
[Terry N.] use try w/ resources for better resource mgmt. syserr for
Browse files Browse the repository at this point in the history
errors
  • Loading branch information
git committed Feb 8, 2025
1 parent 4705a72 commit 12eb83f
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions src/java/com/articulate/sigma/VerbNet/VerbNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,28 @@ public static void initOnce() {
/** *************************************************************
*/
public static void readVerbFiles() {

try {
String dirStr = KBmanager.getMgr().getPref("verbnet");
System.out.println("VerbNet.readVerbFiles(): loading files from: " + dirStr);
File dir = new File(dirStr);
if (!dir.exists()) {
System.out.println("VerbNet.readVerbFiles(): no such dir: " + dirStr);
return;
}
try {
File folder = new File(dirStr);
BufferedReader br;
SimpleDOMParser sdp;
for (File fileEntry : folder.listFiles()) {
if (!fileEntry.toString().endsWith(".xml"))
continue;
br = new BufferedReader(new FileReader(fileEntry.toString()));
sdp = new SimpleDOMParser();
VERB_FILES.put(fileEntry.toString(), sdp.parse(br));
}
String dirStr = KBmanager.getMgr().getPref("verbnet");
System.out.println("VerbNet.readVerbFiles(): loading files from: " + dirStr);
File dir = new File(dirStr);
if (!dir.exists()) {
System.err.println("VerbNet.readVerbFiles(): no such dir: " + dirStr);
return;
}
File folder = new File(dirStr);
SimpleDOMParser sdp;
for (File fileEntry : folder.listFiles()) {
if (!fileEntry.toString().endsWith(".xml")) {
continue;
}
catch (FileNotFoundException e) {

try (Reader br = new BufferedReader(new FileReader(fileEntry.toString()))) {
sdp = new SimpleDOMParser();
VERB_FILES.put(fileEntry.toString(), sdp.parse(br));
} catch (IOException e) {
System.err.println("Error in VerbNet.readVerbFiles(): " + e.getMessage());
e.printStackTrace();
}
}
catch (IOException e) {
System.err.println("Error in VerbNet.readVerbFiles(): " + e.getMessage());
e.printStackTrace();
}
}

/** *************************************************************
Expand Down

0 comments on commit 12eb83f

Please sign in to comment.