Repository navigation
Issue #29: Query Rewriter Interface and Tests #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
44583ff
0e6aa59
a44d90b
3faaedd
4b34848
b40bbbc
d592dd6
2180702
352ca56
dcab94d
f3d43ee
b893b5c
b999cd9
701e744
94f273d
964dd01
7f35e04
8ddcda8
05ce438
1d7dd0f
fd2b5e4
9c275a6
9e39101
c2ea67a
5c76c68
9bd7d7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,33 @@ | ||
| package edu.uci.ics.textdb.common.field; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import edu.uci.ics.textdb.api.common.IField; | ||
|
|
||
| public class ListField<T> implements IField{ | ||
|
|
||
| private List<T> list; | ||
|
|
||
| public ListField(List<T> list){ | ||
| this.list = list; | ||
| } | ||
|
|
||
| @Override | ||
| public List<T> getValue() { | ||
| return list; | ||
| } | ||
|
|
||
| } | ||
| package edu.uci.ics.textdb.common.field; | ||
|
|
||
| import edu.uci.ics.textdb.api.common.IField; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ListField<T> implements IField { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remind me the reason to have this class of list of fields?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be used, to return an |
||
| private final List<T> value; | ||
|
|
||
| public ListField(List<T> value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| @Override | ||
| public List<T> getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return value != null ? value.hashCode() : 0; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| String getStringResult = new String(); | ||
| for(T val: value) { | ||
| getStringResult = getStringResult.concat(val.toString().concat(" ")); | ||
| } | ||
| getStringResult = getStringResult.trim(); | ||
| return "ListField [value=" + getStringResult + "]"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package edu.uci.ics.textdb.dataflow.queryrewriter; | ||
|
|
||
| import edu.uci.ics.textdb.api.common.*; | ||
| import edu.uci.ics.textdb.api.dataflow.IOperator; | ||
| import edu.uci.ics.textdb.common.field.DataTuple; | ||
| import edu.uci.ics.textdb.common.field.ListField; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by kishorenarendran on 25/04/16. | ||
| * QueryRewriter is an operator that converts a query search string which | ||
| * has faults in space placement to a list of meaningful search queries | ||
| * | ||
| * An example - "newyork city" - > "new york city" | ||
| * "christmasday" - > "christmas day" | ||
| * | ||
| * Like other Operators it returns an ITuple which contains a list of strings | ||
| * which are the modified queries. | ||
| * | ||
| */ | ||
| public class QueryRewriter implements IOperator{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure of what else, it could be called, after a discussion with @chenlica, we had settled on this. What do you think could be a better alternative?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JavierJia : let's first call it "QueryRewriter", even though the first implementation is based on "injecting missing space." In the future we can add more ways to do rewriting. |
||
|
|
||
| private String searchQuery; | ||
|
|
||
| public static final String QUERYLIST = "querylist"; | ||
| public static final Attribute QUERYLIST_ATTR = new Attribute(QUERYLIST, FieldType.LIST); | ||
| public static final List<Attribute> ATTRIBUTES_QUERY_LIST = Arrays.asList(QUERYLIST_ATTR); | ||
| public static final Schema SCHEMA_QUERY_LIST = new Schema(ATTRIBUTES_QUERY_LIST); | ||
|
|
||
| private ITuple itupleResult; | ||
|
|
||
| /** | ||
| * Parameterized constructor that requires a Search Query String that | ||
| * is to be rewritten | ||
| * @param searchQuery | ||
| */ | ||
| public QueryRewriter(String searchQuery) { | ||
| this.searchQuery = searchQuery; | ||
| } | ||
|
|
||
| /** | ||
| * Overridden Open method of the IOperator interface | ||
| * Query parser object will be created here | ||
| * @throws Exception | ||
| */ | ||
| @Override | ||
| public void open() throws Exception { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Calls appropriate implementation methods to populate the list | ||
| * of rewritten search queries, and constructing a tuple from it. | ||
| * @return - Tuple with the rewritten queries as a comma separated string | ||
| * @throws Exception | ||
| */ | ||
| @Override | ||
| public ITuple getNextTuple() throws Exception { | ||
| List<String> queryStrings = Arrays.asList(searchQuery); | ||
| IField[] iFieldResult = {new ListField(queryStrings)}; | ||
| itupleResult = new DataTuple(SCHEMA_QUERY_LIST, iFieldResult); | ||
| return itupleResult; | ||
| } | ||
|
|
||
| /** | ||
| * Closing the query Parser object | ||
| * @throws Exception | ||
| */ | ||
| @Override | ||
| public void close() throws Exception { | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| package edu.uci.ics.textdb.dataflow.queryrewriter; | ||
|
|
||
| import edu.uci.ics.textdb.api.common.ITuple; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by kishorenarendran on 25/04/16. | ||
| * Testing QueryRewriter | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add high-level comments to explain the main logic behind the test case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added some high level comments professor. In the latest commit. |
||
| * This test class tests the functionality of the QueryRewrite operator | ||
| * this is done by feeding the class with different kinds of strings to | ||
| * try the query rewriting. | ||
| * | ||
| * This includes query strings like - "newyorkcity", "horseshoe" and other | ||
| * strings which stem from misspelled, missing spaces in search queries | ||
| */ | ||
| public class QueryRewriterTest { | ||
|
|
||
| /** | ||
| * Tests the QueryRewriter operator with the string "horseshoe" | ||
| * @throws Exception | ||
| */ | ||
| @Test | ||
| public void testHorseShoeString() throws Exception { | ||
| String query = "horseshoe"; | ||
|
|
||
| QueryRewriter queryRewriter = new QueryRewriter(query); | ||
| queryRewriter.open(); | ||
| ITuple iTuple = queryRewriter.getNextTuple(); | ||
| queryRewriter.close(); | ||
|
|
||
| Assert.assertNotNull(iTuple); | ||
|
|
||
| List<String> fuzzySet = (List<String>) iTuple.getField(0).getValue(); | ||
| Assert.assertNotNull(fuzzySet); | ||
|
|
||
| List<String> correctSet = Arrays.asList("hor se shoe", | ||
| "hors es hoe", | ||
| "horse shoe", | ||
| "horses hoe", | ||
| "horseshoe"); | ||
| Collections.sort(correctSet); | ||
| Collections.sort(fuzzySet); | ||
|
|
||
| Assert.assertEquals(1,1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use "TestUtils.containsAllResults()" for all the asserts? We want to follow the same logic. @rajesh9625 : please check if your helper function can be used here, and in this PR in general.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chenlica I went through the source code for The only concern is that we will have to construct an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kishore-narendran : in your current test case, the computed set "fuzzySet()" is not really computed yet since the operator is not implemented. If you agree, you may not use containsAllResults() in this PR. In other words, your test case is not "complete" yet. In the next PR with the operator implementation, you should complete the test case and use containsAllResults(). Agreed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chenlica That sounds good professor. Are we good to merge?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. You need to first take care of the new comments. Then we will review again.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chenlica I have already pushed a commit, reflecting what you have mentioned. Please have a look.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still see my comments not addressed. Did you really take care of them and push a new commit? Please check.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chenlica @kishore-narendran for your purpose I've another containsAllResults() in the same TestUtils file, which takes in expectedStrings, returnedStrings and compares them (no need to construct an ITuple). Hope this makes your job easy! :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @rajesh9625 . @kishore-narendran : in your next PR, please use this containsAllResults() function to replace yours. |
||
|
|
||
| //Assert.assertEquals(correctSet.size(), fuzzySet.size()); | ||
| //Assert.assertEquals(correctSet, fuzzySet); | ||
| } | ||
|
|
||
| /** | ||
| * Tests the QueryRewriter operator with the string "horse shoe" | ||
| * @throws Exception | ||
| */ | ||
| @Test | ||
| public void testHorseSpaceShoeString() throws Exception { | ||
| String query = "horse shoe"; | ||
|
|
||
| QueryRewriter queryRewriter = new QueryRewriter(query); | ||
| queryRewriter.open(); | ||
| ITuple iTuple = queryRewriter.getNextTuple(); | ||
| queryRewriter.close(); | ||
|
|
||
| Assert.assertNotNull(iTuple); | ||
|
|
||
| List<String> fuzzySet = (List<String>) iTuple.getField(0).getValue(); | ||
| Assert.assertNotNull(fuzzySet); | ||
|
|
||
| List<String> correctSet = Arrays.asList("horse shoe"); | ||
|
|
||
| Collections.sort(correctSet); | ||
| Collections.sort(fuzzySet); | ||
|
|
||
| Assert.assertEquals(1,1); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to add "Assert.assertEquals(1, 1)"? |
||
| //Assert.assertEquals(correctSet.size(), fuzzySet.size()); | ||
| //Assert.assertEquals(correctSet, fuzzySet); | ||
| } | ||
|
|
||
| /** | ||
| * Tests the QueryRewriter operator with the string "newyork city" | ||
| * @throws Exception | ||
| */ | ||
| @Test | ||
| public void testNewYorkCityString() throws Exception { | ||
| String query = "newyork city"; | ||
|
|
||
| QueryRewriter queryRewriter = new QueryRewriter(query); | ||
| queryRewriter.open(); | ||
| ITuple iTuple = queryRewriter.getNextTuple(); | ||
| queryRewriter.close(); | ||
|
|
||
| Assert.assertNotNull(iTuple); | ||
|
|
||
| List<String> fuzzySet = (List<String>) iTuple.getField(0).getValue(); | ||
| Assert.assertNotNull(fuzzySet); | ||
|
|
||
| List<String> correctSet = Arrays.asList("new york city", | ||
| "newyork city"); | ||
| Collections.sort(correctSet); | ||
| Collections.sort(fuzzySet); | ||
|
|
||
| Assert.assertEquals(1,1); | ||
|
|
||
| //Assert.assertEquals(correctSet.size(), fuzzySet.size()); | ||
| //Assert.assertEquals(correctSet, fuzzySet); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kishore-narendran .. Sorry if I am not clear before. I didn't want you to create this class. I wanted you to use ListField once the pull request #77 is merged into master. But for now, the old approach is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I ended up implementing it anyway! 😛 I'll wait for you to merge into master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for the merge of #77 (soon) before merging this PR.