diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-search/src/test/java/com/yahoo/prelude/semantics/parser |
Publish
Diffstat (limited to 'container-search/src/test/java/com/yahoo/prelude/semantics/parser')
3 files changed, 91 insertions, 0 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java new file mode 100644 index 00000000000..eba1dd87c95 --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/SemanticsParserTestCase.java @@ -0,0 +1,59 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.prelude.semantics.parser.test; + +import java.util.Iterator; + +import com.yahoo.javacc.UnicodeUtilities; +import com.yahoo.prelude.semantics.RuleBase; +import com.yahoo.prelude.semantics.RuleImporter; +import com.yahoo.prelude.semantics.parser.ParseException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Tests parsing of semantic rules bases + * + * @author bratseth + */ +public class SemanticsParserTestCase { + + private final static String ROOT = "src/test/java/com/yahoo/prelude/semantics/parser/test/"; + + @Test + public void testRuleReading() throws java.io.IOException, ParseException { + RuleBase rules=new RuleImporter().importFile(ROOT + "rules.sr"); + Iterator<?> i=rules.ruleIterator(); + assertEquals("[listing] [preposition] [place] -> listing:[listing] place:[place]!150", + i.next().toString()); + assertEquals("[listing] [place] +> place:[place]", + i.next().toString()); + assertEquals("[brand] -> brand:[brand]", + i.next().toString()); + assertEquals("[category] -> category:[category]", + i.next().toString()); + assertEquals("digital camera -> digicamera", + i.next().toString()); + assertEquals("(parameter.ranking='cat'), (parameter.ranking='cat0') -> one",i.next().toString()); + assertFalse(i.hasNext()); + + i=rules.conditionIterator(); + assertEquals("[listing] :- restaurant, shop, cafe, hotel", + i.next().toString()); + assertEquals("[preposition] :- in, at, near", + i.next().toString()); + assertEquals("[place] :- geary", + i.next().toString()); + assertEquals("[brand] :- sony, dell", + i.next().toString()); + assertEquals("[category] :- digital camera, camera, phone", + i.next().toString()); + assertFalse(i.hasNext()); + + assertTrue(rules.isDefault()); + assertEquals(ROOT + "semantics.fsa",rules.getAutomataFile()); + } + +} diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/rules.sr b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/rules.sr new file mode 100644 index 00000000000..56433f732a5 --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/rules.sr @@ -0,0 +1,32 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@default +@automata(src/test/java/com/yahoo/prelude/semantics/parser/test/semantics.fsa) + +# Local use case + +[listing] [preposition] [place] -> listing:[listing] place:[place]!150; + +[listing] :- restaurant, shop, cafe, hotel; + +[preposition] :- in, at, near; + +[place] :- geary; + +# Just to see additive rules working +[listing] [place] +> place:[place]; + +# Shopping use case + +[brand] -> brand:[brand]; +[category] -> category:[category]; + +digital camera -> digicamera; + +[brand] :- sony, dell; +[category] :- digital camera, camera, phone; + +# Answers use case + +# why is [noun] ... [adjective] +> ?about:[noun] + +parameter.ranking='cat', parameter.ranking='cat0' -> one; diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/semantics.fsa b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/semantics.fsa Binary files differnew file mode 100644 index 00000000000..0b45cb9784a --- /dev/null +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/parser/test/semantics.fsa |