@@ -27,7 +27,7 @@ Add this to the dependencies section of your `pom.xml`:
27
27
<dependency >
28
28
<groupId >com.github.manzurola</groupId >
29
29
<artifactId >errgent</artifactId >
30
- <version >0.1 .0</version >
30
+ <version >0.2 .0</version >
31
31
</dependency >
32
32
```
33
33
@@ -36,23 +36,31 @@ Add this to the dependencies section of your `pom.xml`:
36
36
To use Errgent in code, follow these steps:
37
37
38
38
``` java
39
- // Get a spaCy instance
40
- SpaCy spacy = SpaCy . create(CoreNLPAdapter . create());
41
-
42
- // Create an English error annotator
43
- Annotator annotator = Errant . newAnnotator(" en" , spacy);
44
-
45
- // Create an English error generator
46
- Generator generator = Errgent . newGenerator(" en" , annotator);
47
-
48
- // parse the doc (a utilty method)
49
- Doc target = generator. parse(" My friends like to have fun." );
50
-
51
- // Generate all documents that contain the specified error
52
- // (will contain "My friends like to has fun.")
53
- List<Doc > inflections = generator. generate(target, REPLACEMENT_SUBJECT_VERB_AGREEMENT );
54
- for (Doc inflection : inflections) {
55
- System . out. println(inflection. text());
39
+ // Create a spacy instance (from spaCy4j)
40
+ SpaCy spacy = SpaCy . create(CoreNLPAdapter . forEnglish());
41
+
42
+ // Instantiate a new Errgent for English
43
+ Generator errgent = Errgent . forEnglish(spacy);
44
+
45
+ // Generate a specific grammatical error in the target doc. Since a
46
+ // sentence can contain multiple errors at once, all such possible
47
+ // errors are returned.
48
+ List<GeneratedError > generatedErrors = errgent. generateErrors(
49
+ " If I were you, I would go home." ,
50
+ GrammaticalError . REPLACEMENT_SUBJECT_VERB_AGREEMENT
51
+ );
52
+
53
+ // Print out the results. The markedText() method retrieves the
54
+ // erroneous text with the error marked by an asterisk on both sides.
55
+ // We can also access the char offsets of the error using charStart
56
+ // and charEnd methods of GeneratedError.
57
+ for (GeneratedError generatedError : generatedErrors) {
58
+ String text = generatedError. markedText();
59
+ System . out. printf(
60
+ " %s, %s%n" ,
61
+ text,
62
+ generatedError. error()
63
+ );
56
64
}
57
65
```
58
66
0 commit comments