@@ -516,12 +516,17 @@ public static void main(String[] args) throws IOException {
516
516
Map <String , String []> argsMap = StringUtils .argsToMap (args , flagMap );
517
517
// args = argsMap.get(null);
518
518
519
- // TODO: allow patterns to be extracted from a file
520
519
if (!(argsMap .containsKey (PATTERN )) || argsMap .get (PATTERN ).length == 0 ) {
521
520
help ();
522
521
System .exit (2 );
523
522
}
524
- SemgrexPattern semgrex = SemgrexPattern .compile (argsMap .get (PATTERN )[0 ]);
523
+ SemgrexPattern semgrex ;
524
+ try {
525
+ String pattern = IOUtils .slurpFile (argsMap .get (PATTERN )[0 ]);
526
+ semgrex = SemgrexPattern .compile (pattern );
527
+ } catch (IOException e ) {
528
+ semgrex = SemgrexPattern .compile (argsMap .get (PATTERN )[0 ]);
529
+ }
525
530
526
531
String modeString = DEFAULT_MODE ;
527
532
if (argsMap .containsKey (MODE ) && argsMap .get (MODE ).length > 0 ) {
@@ -562,11 +567,20 @@ public static void main(String[] args) throws IOException {
562
567
if (argsMap .containsKey (CONLLU_FILE ) && argsMap .get (CONLLU_FILE ).length > 0 ) {
563
568
try {
564
569
CoNLLUReader reader = new CoNLLUReader ();
565
- for (String conlluFile : argsMap .get (CONLLU_FILE )) {
566
- log .info ("Loading file " + conlluFile );
567
- List <Annotation > docs = reader .readCoNLLUFile (conlluFile );
568
- for (Annotation doc : docs ) {
569
- sentences .addAll (doc .get (CoreAnnotations .SentencesAnnotation .class ));
570
+ for (String conlluPath : argsMap .get (CONLLU_FILE )) {
571
+ File file = new File (conlluPath );
572
+ List <File > filenames ;
573
+ if (file .isFile ()) {
574
+ filenames = Collections .singletonList (file );
575
+ } else {
576
+ filenames = Arrays .asList (file .listFiles ());
577
+ }
578
+ for (File conlluFile : filenames ) {
579
+ log .info ("Loading file " + conlluFile );
580
+ List <Annotation > docs = reader .readCoNLLUFile (conlluFile .toString ());
581
+ for (Annotation doc : docs ) {
582
+ sentences .addAll (doc .get (CoreAnnotations .SentencesAnnotation .class ));
583
+ }
570
584
}
571
585
}
572
586
} catch (ClassNotFoundException e ) {
0 commit comments