|
80 | 80 |
|
81 | 81 | public class StanfordCoreNLP extends AnnotationPipeline {
|
82 | 82 |
|
83 |
| - enum OutputFormat { TEXT, XML, JSON, CONLL, SERIALIZED } |
| 83 | + enum OutputFormat { TEXT, XML, JSON, CONLL, TAGGED, SERIALIZED } |
84 | 84 |
|
85 | 85 | // other constants
|
86 | 86 | public static final String CUSTOM_ANNOTATOR_PREFIX = "customAnnotatorClass.";
|
@@ -742,6 +742,7 @@ public void processFiles(String base, final Collection<File> files, int numThrea
|
742 | 742 | case CONLL: defaultExtension = ".conll"; break;
|
743 | 743 | case TEXT: defaultExtension = ".out"; break;
|
744 | 744 | case SERIALIZED: defaultExtension = ".ser.gz"; break;
|
| 745 | + case TAGGED: defaultExtension = ".tag"; break; |
745 | 746 | default: throw new IllegalArgumentException("Unknown output format " + outputFormat);
|
746 | 747 | }
|
747 | 748 | final String serializerClass = properties.getProperty("serializer", GenericAnnotationSerializer.class.getName());
|
@@ -885,42 +886,48 @@ public void processFiles(String base, final Collection<File> files, int numThrea
|
885 | 886 | if (annotationOkay) {
|
886 | 887 | //--Output File
|
887 | 888 | switch (outputFormat) {
|
888 |
| - case XML: { |
889 |
| - OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
890 |
| - xmlPrint(annotation, fos); |
891 |
| - fos.close(); |
892 |
| - break; |
893 |
| - } |
894 |
| - case JSON: { |
895 |
| - OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
896 |
| - new JSONOutputter().print(annotation, fos); |
897 |
| - fos.close(); |
898 |
| - break; |
899 |
| - } |
900 |
| - case CONLL: { |
901 |
| - OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
902 |
| - new CoNLLOutputter().print(annotation, fos); |
903 |
| - fos.close(); |
904 |
| - break; |
905 |
| - } |
906 |
| - case TEXT: { |
907 |
| - OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
908 |
| - prettyPrint(annotation, fos); |
909 |
| - fos.close(); |
910 |
| - break; |
911 |
| - } |
912 |
| - case SERIALIZED: { |
913 |
| - if (outputSerializerClass != null) { |
914 |
| - AnnotationSerializer outputSerializer = loadSerializer(outputSerializerClass, outputSerializerName, properties); |
| 889 | + case XML: { |
915 | 890 | OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename));
|
916 |
| - outputSerializer.write(annotation, fos).close(); |
917 |
| - } else { |
918 |
| - IOUtils.writeObjectToFile(annotation, finalOutputFilename); |
| 891 | + xmlPrint(annotation, fos); |
| 892 | + fos.close(); |
| 893 | + break; |
919 | 894 | }
|
920 |
| - break; |
921 |
| - } |
922 |
| - default: |
923 |
| - throw new IllegalArgumentException("Unknown output format " + outputFormat); |
| 895 | + case JSON: { |
| 896 | + OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
| 897 | + new JSONOutputter().print(annotation, fos); |
| 898 | + fos.close(); |
| 899 | + break; |
| 900 | + } |
| 901 | + case CONLL: { |
| 902 | + OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
| 903 | + new CoNLLOutputter().print(annotation, fos); |
| 904 | + fos.close(); |
| 905 | + break; |
| 906 | + } |
| 907 | + case TEXT: { |
| 908 | + OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
| 909 | + prettyPrint(annotation, fos); |
| 910 | + fos.close(); |
| 911 | + break; |
| 912 | + } |
| 913 | + case SERIALIZED: { |
| 914 | + if (outputSerializerClass != null) { |
| 915 | + AnnotationSerializer outputSerializer = loadSerializer(outputSerializerClass, outputSerializerName, properties); |
| 916 | + OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
| 917 | + outputSerializer.write(annotation, fos).close(); |
| 918 | + } else { |
| 919 | + IOUtils.writeObjectToFile(annotation, finalOutputFilename); |
| 920 | + } |
| 921 | + break; |
| 922 | + } |
| 923 | + case TAGGED: { |
| 924 | + OutputStream fos = new BufferedOutputStream(new FileOutputStream(finalOutputFilename)); |
| 925 | + TaggedTextOutputter.prettyPrint(annotation, fos, this); |
| 926 | + fos.close(); |
| 927 | + break; |
| 928 | + } |
| 929 | + default: |
| 930 | + throw new IllegalArgumentException("Unknown output format " + outputFormat); |
924 | 931 | }
|
925 | 932 | synchronized (totalProcessed) {
|
926 | 933 | totalProcessed.incValue(1);
|
|
0 commit comments