Skip to content

Commit 56b0c7b

Browse files
authored
Update README.md
1 parent a77def1 commit 56b0c7b

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Add this to the dependencies section of your `pom.xml`:
2727
<dependency>
2828
<groupId>com.github.manzurola</groupId>
2929
<artifactId>errgent</artifactId>
30-
<version>0.1.0</version>
30+
<version>0.2.0</version>
3131
</dependency>
3232
```
3333

@@ -36,23 +36,31 @@ Add this to the dependencies section of your `pom.xml`:
3636
To use Errgent in code, follow these steps:
3737

3838
```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+
);
5664
}
5765
```
5866

0 commit comments

Comments
 (0)