@@ -530,12 +530,17 @@ public static void main(String[] args) throws IOException {
530
530
Map <String , String []> argsMap = StringUtils .argsToMap (args , flagMap );
531
531
// args = argsMap.get(null);
532
532
533
- // TODO: allow patterns to be extracted from a file
534
533
if (!(argsMap .containsKey (PATTERN )) || argsMap .get (PATTERN ).length == 0 ) {
535
534
help ();
536
535
System .exit (2 );
537
536
}
538
- SemgrexPattern semgrex = SemgrexPattern .compile (argsMap .get (PATTERN )[0 ]);
537
+ SemgrexPattern semgrex ;
538
+ try {
539
+ String pattern = IOUtils .slurpFile (argsMap .get (PATTERN )[0 ]);
540
+ semgrex = SemgrexPattern .compile (pattern );
541
+ } catch (IOException e ) {
542
+ semgrex = SemgrexPattern .compile (argsMap .get (PATTERN )[0 ]);
543
+ }
539
544
540
545
String modeString = DEFAULT_MODE ;
541
546
if (argsMap .containsKey (MODE ) && argsMap .get (MODE ).length > 0 ) {
@@ -576,11 +581,20 @@ public static void main(String[] args) throws IOException {
576
581
if (argsMap .containsKey (CONLLU_FILE ) && argsMap .get (CONLLU_FILE ).length > 0 ) {
577
582
try {
578
583
CoNLLUReader reader = new CoNLLUReader ();
579
- for (String conlluFile : argsMap .get (CONLLU_FILE )) {
580
- log .info ("Loading file " + conlluFile );
581
- List <Annotation > docs = reader .readCoNLLUFile (conlluFile );
582
- for (Annotation doc : docs ) {
583
- sentences .addAll (doc .get (CoreAnnotations .SentencesAnnotation .class ));
584
+ for (String conlluPath : argsMap .get (CONLLU_FILE )) {
585
+ File file = new File (conlluPath );
586
+ List <File > filenames ;
587
+ if (file .isFile ()) {
588
+ filenames = Collections .singletonList (file );
589
+ } else {
590
+ filenames = Arrays .asList (file .listFiles ());
591
+ }
592
+ for (File conlluFile : filenames ) {
593
+ log .info ("Loading file " + conlluFile );
594
+ List <Annotation > docs = reader .readCoNLLUFile (conlluFile .toString ());
595
+ for (Annotation doc : docs ) {
596
+ sentences .addAll (doc .get (CoreAnnotations .SentencesAnnotation .class ));
597
+ }
584
598
}
585
599
}
586
600
} catch (ClassNotFoundException e ) {
0 commit comments