Skip to content

Commit d09307b

Browse files
committed
Add a toString() to CRFClassifier which tries to show where the classifier came from and the labels it has
1 parent 4bd3394 commit d09307b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ public abstract void loadClassifier(ObjectInputStream in, Properties props) thro
14991499
*/
15001500
public void loadClassifier(String loadPath) throws ClassCastException, IOException, ClassNotFoundException {
15011501
loadClassifier(loadPath, null);
1502+
flags.loadClassifier = loadPath;
15021503
}
15031504

15041505
/**
@@ -1509,6 +1510,7 @@ public void loadClassifier(String loadPath, Properties props) throws ClassCastEx
15091510
try (InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(loadPath)) {
15101511
Timing t = new Timing();
15111512
loadClassifier(is, props);
1513+
flags.loadClassifier = loadPath;
15121514
t.done(log, "Loading classifier from " + loadPath);
15131515
}
15141516
}
@@ -1529,6 +1531,7 @@ public void loadClassifierNoExceptions(String loadPath, Properties props) {
15291531

15301532
public void loadClassifier(File file) throws ClassCastException, IOException, ClassNotFoundException {
15311533
loadClassifier(file, null);
1534+
flags.loadClassifier = file.toString();
15321535
}
15331536

15341537
/**
@@ -1555,6 +1558,7 @@ public void loadClassifier(File file, Properties props) throws ClassCastExceptio
15551558
}
15561559
try {
15571560
loadClassifier(bis, props);
1561+
flags.loadClassifier = file.toString();
15581562
t.done(log, "Loading classifier from " + file.getAbsolutePath());
15591563
} finally {
15601564
bis.close();

src/edu/stanford/nlp/ie/crf/CRFClassifier.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,20 @@ private static CRFClassifier<CoreLabel> chooseCRFClassifier(SeqClassifierFlags f
29212921
return crf;
29222922
}
29232923

2924+
public String toString() {
2925+
String name = flags.loadClassifier;
2926+
if (name == null) {
2927+
name = flags.serializeTo;
2928+
}
2929+
if (name == null) {
2930+
name = flags.trainFile;
2931+
}
2932+
if (name == null) {
2933+
name = super.toString();
2934+
}
2935+
return name + classIndex.toString();
2936+
}
2937+
29242938
/** The main method. See the class documentation. */
29252939
public static void main(String[] args) throws Exception {
29262940
StringUtils.logInvocationString(log, args);

0 commit comments

Comments
 (0)