2
2
3
3
import java .io .FileFilter ;
4
4
import java .io .PrintStream ;
5
+ import java .util .regex .Pattern ;
5
6
import edu .stanford .nlp .io .NumberRangeFileFilter ;
6
7
import edu .stanford .nlp .io .NumberRangesFileFilter ;
7
8
import edu .stanford .nlp .util .Pair ;
9
+ import edu .stanford .nlp .util .Triple ;
8
10
9
11
/**
10
12
* Utility methods or common blocks of code for dealing with parser
@@ -30,14 +32,28 @@ public static void printArgs(String[] args, PrintStream ps) {
30
32
ps .println ();
31
33
}
32
34
35
+ static final Pattern DOUBLE_PATTERN = Pattern .compile ("[-]?[0-9]+[.][0-9]+" );
36
+
33
37
public static Pair <String , FileFilter > getTreebankDescription (String [] args , int argIndex , String flag ) {
38
+ Triple <String , FileFilter , Double > description = getWeightedTreebankDescription (args , argIndex , flag );
39
+ return Pair .makePair (description .first (), description .second ());
40
+ }
41
+
42
+ public static Triple <String , FileFilter , Double > getWeightedTreebankDescription (String [] args , int argIndex , String flag ) {
34
43
String path = null ;
35
44
FileFilter filter = null ;
45
+ Double weight = 1.0 ;
36
46
// the next arguments are the treebank path and maybe the range for testing
37
47
int numSubArgs = numSubArgs (args , argIndex );
38
- if (numSubArgs > 0 && numSubArgs < 3 ) {
48
+ if (numSubArgs > 0 && numSubArgs < 4 ) {
39
49
argIndex ++;
40
50
path = args [argIndex ++];
51
+ boolean hasWeight = false ;
52
+ if (numSubArgs > 1 && DOUBLE_PATTERN .matcher (args [argIndex + numSubArgs - 2 ]).matches ()) {
53
+ weight = Double .parseDouble (args [argIndex + numSubArgs - 2 ]);
54
+ hasWeight = true ;
55
+ numSubArgs --;
56
+ }
41
57
if (numSubArgs == 2 ) {
42
58
filter = new NumberRangesFileFilter (args [argIndex ++], true );
43
59
} else if (numSubArgs == 3 ) {
@@ -51,9 +67,12 @@ public static Pair<String, FileFilter> getTreebankDescription(String[] args, int
51
67
filter = new NumberRangesFileFilter (args [argIndex ++], true );
52
68
}
53
69
}
70
+ if (hasWeight ) {
71
+ argIndex ++;
72
+ }
54
73
} else {
55
74
throw new IllegalArgumentException ("Bad arguments after " + flag );
56
75
}
57
- return Pair . makePair (path , filter );
76
+ return Triple . makeTriple (path , filter , weight );
58
77
}
59
78
}
0 commit comments