aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java')
-rw-r--r--container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java77
1 files changed, 37 insertions, 40 deletions
diff --git a/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java b/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java
index f439db390ee..fcb77851f0f 100644
--- a/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java
@@ -11,12 +11,9 @@ import com.yahoo.text.interpretation.AnnotationClass;
import com.yahoo.text.interpretation.Annotations;
import com.yahoo.text.interpretation.Interpretation;
import com.yahoo.text.interpretation.Span;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
/**
* @author Arne Bergene Fossaa
@@ -24,12 +21,12 @@ import static org.junit.Assert.assertTrue;
public class AnnotationTestCase {
@Test
- public void testSimpleAnnotations() {
- Interpretation i= new Interpretation("new york hotel");
- i.annotate("sentence").put("isValid",true);
- i.annotate(0,3,"token");
- i.annotate(0,8,"place_name").put("^taxonomy:place_category","city");
- i.annotate(0,8,"place_name").put("woeid","12345678");
+ void testSimpleAnnotations() {
+ Interpretation i = new Interpretation("new york hotel");
+ i.annotate("sentence").put("isValid", true);
+ i.annotate(0, 3, "token");
+ i.annotate(0, 8, "place_name").put("^taxonomy:place_category", "city");
+ i.annotate(0, 8, "place_name").put("woeid", "12345678");
//i.getInterpretationAnnotation().put("domain","jaffa");
i.setProbability(0.5);
@@ -37,32 +34,32 @@ public class AnnotationTestCase {
}
@Test
- public void testAnnotationAPI() {
+ void testAnnotationAPI() {
Interpretation a = new Interpretation("new york hotel");
- a.annotate(0,3,"token");
- a.annotate(0,8,"state").put("name","New York");
- a.annotate(0,8,"state").put("country","US");
- a.annotate(0,8,"state").put("coast","east");
- a.annotate(9,14,"business");
- a.annotate(4,8,"token");
- a.annotate(9,14,"token");
+ a.annotate(0, 3, "token");
+ a.annotate(0, 8, "state").put("name", "New York");
+ a.annotate(0, 8, "state").put("country", "US");
+ a.annotate(0, 8, "state").put("coast", "east");
+ a.annotate(9, 14, "business");
+ a.annotate(4, 8, "token");
+ a.annotate(9, 14, "token");
- for(Span span : a.getTokens()) {
+ for (Span span : a.getTokens()) {
assertTrue(span.hasClass(new AnnotationClass("token")));
}
- Set<AnnotationClass> annotationClasses = a.getClasses(0,3);
+ Set<AnnotationClass> annotationClasses = a.getClasses(0, 3);
Set<AnnotationClass> testClass = new HashSet<>(Arrays.asList(
new AnnotationClass("token"), new AnnotationClass("state")));
- assertEquals(testClass,annotationClasses);
+ assertEquals(testClass, annotationClasses);
- assertNull(a.get("state","country"));
- assertEquals("US", a.get(0,8,"state","country"));
+ assertNull(a.get("state", "country"));
+ assertEquals("US", a.get(0, 8, "state", "country"));
assertEquals("new york", a.root().getSubSpans().get(0).getText());
assertEquals("hotel", a.root().getSubSpans().get(1).getText());
- assertEquals(2,a.root().getSubSpans().size());
+ assertEquals(2, a.root().getSubSpans().size());
//Test scoring
@@ -77,37 +74,37 @@ public class AnnotationTestCase {
//This is bad about the API, getTokens may not necessairily return what a user thinks a token is
//But it should still be tested
- a.annotate(0,1,"n");
- Set<String> testSet = new HashSet<>(Arrays.asList("n","york","hotel"));
- for(Span span:a.getTokens()) {
+ a.annotate(0, 1, "n");
+ Set<String> testSet = new HashSet<>(Arrays.asList("n", "york", "hotel"));
+ for (Span span :a.getTokens()) {
assertTrue(testSet.remove(span.getText()));
}
- assertEquals(0,testSet.size());
+ assertEquals(0, testSet.size());
}
//The following testcase is a test with the api on a use_case, no cornercases here
@Test
- public void testUsability() {
+ void testUsability() {
Interpretation interpretation = new Interpretation("new york crab pizza");
- interpretation.annotate(0,8,"place_name").put("^taxonomy:place_category","city");
- interpretation.annotate(0,8,"place_name").put("woe_id",2459115);
- interpretation.annotate(9,13,"food");
- interpretation.annotate(14,19,"food");
+ interpretation.annotate(0, 8, "place_name").put("^taxonomy:place_category", "city");
+ interpretation.annotate(0, 8, "place_name").put("woe_id", 2459115);
+ interpretation.annotate(9, 13, "food");
+ interpretation.annotate(14, 19, "food");
//Here we want to write code that finds out if the interpretation
//matches pizza and toppings.
List<Span> pizzaSpans = interpretation.getTermSpans("pizza");
- if(pizzaSpans.size() > 0) {
+ if (pizzaSpans.size() > 0) {
//We know that we have pizza, now we want to get some topping
//In a perfect world, pizza topping would have its own annotation class
//but for now, we'll just accept terms that have been tokenized with food
List<String> toppings = new ArrayList<>();
- for(Annotations annotations :interpretation.getAll("food")) {
- if(!annotations.getSubString().equalsIgnoreCase("pizza")) {
+ for (Annotations annotations :interpretation.getAll("food")) {
+ if (!annotations.getSubString().equalsIgnoreCase("pizza")) {
toppings.add(annotations.getSubString());
}
}
@@ -116,13 +113,13 @@ public class AnnotationTestCase {
//that all spans that has the annotation "place_name" has a "woe_id".
int woe_id = 0;
- for(Annotations annotations :interpretation.getAll("place_name")) {
+ for (Annotations annotations :interpretation.getAll("place_name")) {
//This will return either 0 or throw a bad exception
//if a number is not found
woe_id = annotations.getInteger("woe_id");
}
- assertEquals(Arrays.asList("crab"),toppings);
- assertEquals(2459115,woe_id);
+ assertEquals(Arrays.asList("crab"), toppings);
+ assertEquals(2459115, woe_id);
}
}