2323
2424import org .apache .uima .analysis_engine .AnalysisEngine ;
2525import org .apache .uima .fit .testing .factory .TokenBuilder ;
26+ import org .apache .uima .fit .util .JCasUtil ;
2627import org .apache .uima .jcas .JCas ;
2728import org .dkpro .core .testing .DkproTestContext ;
2829import org .junit .Rule ;
2930import org .junit .Test ;
3031
3132import de .tudarmstadt .ukp .dkpro .core .api .anomaly .type .GrammarAnomaly ;
33+ import de .tudarmstadt .ukp .dkpro .core .api .anomaly .type .SuggestedAction ;
3234import de .tudarmstadt .ukp .dkpro .core .api .segmentation .type .Sentence ;
3335import de .tudarmstadt .ukp .dkpro .core .api .segmentation .type .Token ;
3436
3537public class LanguageToolCheckerTest
3638{
3739 @ Test
38- public void grammarCheckerTest ()
39- throws Exception
40+ public void grammarCheckerTest () throws Exception
4041 {
4142 String testDocument = "A sentence with a error in the Hitchhiker's Guide tot he Galaxy ." ;
4243
@@ -54,11 +55,45 @@ public void grammarCheckerTest()
5455 for (GrammarAnomaly ga : select (aJCas , GrammarAnomaly .class )) {
5556 System .out .println ("Error " + (count + 1 ) + " (" + ga .getBegin () + ", " + ga .getEnd ()
5657 + "):" + ga .getDescription ());
58+ for (SuggestedAction action : JCasUtil .select (ga .getSuggestions (),
59+ SuggestedAction .class )) {
60+ System .out .printf ("-> %s (score %f)%n" , action .getReplacement (),
61+ action .getCertainty ());
62+ }
5763 count ++;
5864 }
5965 assertEquals (count , 3 );
6066 }
61-
67+
68+ @ Test
69+ public void grammarCheckerTestFrench () throws Exception
70+ {
71+ String testDocument = "comment modifer un compte" ;
72+
73+ AnalysisEngine engine = createEngine (LanguageToolChecker .class ,
74+ LanguageToolChecker .PARAM_LANGUAGE , "fr" );
75+ JCas aJCas = engine .newJCas ();
76+
77+ TokenBuilder <Token , Sentence > tb = new TokenBuilder <>(Token .class , Sentence .class );
78+ tb .buildTokens (aJCas , testDocument );
79+
80+ engine .process (aJCas );
81+
82+ // copy input match type annotations to an array
83+ int count = 0 ;
84+ for (GrammarAnomaly ga : select (aJCas , GrammarAnomaly .class )) {
85+ System .out .println ("Error " + (count + 1 ) + " (" + ga .getBegin () + ", " + ga .getEnd ()
86+ + "):" + ga .getDescription ());
87+ for (SuggestedAction action : JCasUtil .select (ga .getSuggestions (),
88+ SuggestedAction .class )) {
89+ System .out .printf ("-> %s (score %f)%n" , action .getReplacement (),
90+ action .getCertainty ());
91+ }
92+ count ++;
93+ }
94+ assertEquals (count , 2 );
95+ }
96+
6297 @ Rule
6398 public DkproTestContext testContext = new DkproTestContext ();
6499}
0 commit comments