Skip to content

Commit

Permalink
Merge branch '1.12.x'
Browse files Browse the repository at this point in the history
* 1.12.x:
  #1410 - LanguageToolChecker does not fill in suggestions
  • Loading branch information
reckart committed Sep 4, 2019
2 parents 24cfaf5 + 09065ee commit e74006b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
package org.dkpro.core.languagetool;

import static org.apache.uima.fit.util.FSCollectionFactory.createFSArray;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

Expand All @@ -40,6 +43,7 @@
import org.languagetool.rules.RuleMatch;

import de.tudarmstadt.ukp.dkpro.core.api.anomaly.type.GrammarAnomaly;
import de.tudarmstadt.ukp.dkpro.core.api.anomaly.type.SuggestedAction;
import eu.openminted.share.annotations.api.Component;
import eu.openminted.share.annotations.api.DocumentationResource;
import eu.openminted.share.annotations.api.constants.OperationType;
Expand Down Expand Up @@ -120,6 +124,14 @@ public void process(JCas aJCas) throws AnalysisEngineProcessException
annotation.setBegin(match.getFromPos());
annotation.setEnd(match.getToPos());
annotation.setDescription(match.getMessage());
List<SuggestedAction> suggestions = new ArrayList<>();
for (String replacement : match.getSuggestedReplacements()) {
SuggestedAction action = new SuggestedAction(aJCas, annotation.getBegin(),
annotation.getEnd());
action.setReplacement(replacement);
suggestions.add(action);
}
annotation.setSuggestions(createFSArray(aJCas, suggestions));
annotation.addToIndexes();
getContext().getLogger().log(Level.FINEST, "Found: " + annotation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@

import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.fit.testing.factory.TokenBuilder;
import org.apache.uima.fit.util.JCasUtil;
import org.apache.uima.jcas.JCas;
import org.dkpro.core.testing.DkproTestContext;
import org.junit.Rule;
import org.junit.Test;

import de.tudarmstadt.ukp.dkpro.core.api.anomaly.type.GrammarAnomaly;
import de.tudarmstadt.ukp.dkpro.core.api.anomaly.type.SuggestedAction;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token;

public class LanguageToolCheckerTest
{
@Test
public void grammarCheckerTest()
throws Exception
public void grammarCheckerTest() throws Exception
{
String testDocument = "A sentence with a error in the Hitchhiker's Guide tot he Galaxy .";

Expand All @@ -54,11 +55,45 @@ public void grammarCheckerTest()
for (GrammarAnomaly ga : select(aJCas, GrammarAnomaly.class)) {
System.out.println("Error " + (count + 1) + " (" + ga.getBegin() + ", " + ga.getEnd()
+ "):" + ga.getDescription());
for (SuggestedAction action : JCasUtil.select(ga.getSuggestions(),
SuggestedAction.class)) {
System.out.printf("-> %s (score %f)%n", action.getReplacement(),
action.getCertainty());
}
count++;
}
assertEquals(count, 3);
}


@Test
public void grammarCheckerTestFrench() throws Exception
{
String testDocument = "comment modifer un compte";

AnalysisEngine engine = createEngine(LanguageToolChecker.class,
LanguageToolChecker.PARAM_LANGUAGE, "fr");
JCas aJCas = engine.newJCas();

TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class, Sentence.class);
tb.buildTokens(aJCas, testDocument);

engine.process(aJCas);

// copy input match type annotations to an array
int count = 0;
for (GrammarAnomaly ga : select(aJCas, GrammarAnomaly.class)) {
System.out.println("Error " + (count + 1) + " (" + ga.getBegin() + ", " + ga.getEnd()
+ "):" + ga.getDescription());
for (SuggestedAction action : JCasUtil.select(ga.getSuggestions(),
SuggestedAction.class)) {
System.out.printf("-> %s (score %f)%n", action.getReplacement(),
action.getCertainty());
}
count++;
}
assertEquals(count, 2);
}

@Rule
public DkproTestContext testContext = new DkproTestContext();
}

0 comments on commit e74006b

Please sign in to comment.