Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
44583ff
Merge pull request #74 from TextDB/master
ss3n Apr 25, 2016
0e6aa59
Added QueryRewriter and QueryParser classes
kishore-narendran Apr 25, 2016
a44d90b
Added new attribute to test constants
kishore-narendran Apr 25, 2016
3faaedd
Class name refactoring, and input changed to search query string
kishore-narendran Apr 25, 2016
4b34848
Added FuzzyTokenizer class'
kishore-narendran Apr 25, 2016
b40bbbc
Editing fields in SpanTupleTest.java to fix build
kishore-narendran Apr 25, 2016
d592dd6
Reverted changes to TestConstant and SpanTupleTest'
kishore-narendran Apr 26, 2016
2180702
Added StringListField
kishore-narendran Apr 26, 2016
352ca56
Updated interface to QueryRewriter class
kishore-narendran Apr 26, 2016
dcab94d
Added initial test for Query rewriter
Apr 26, 2016
f3d43ee
Attempting fix for Travis for Query Rewriter
Apr 26, 2016
b893b5c
Fixing the build failure, minor refactors
kishore-narendran Apr 26, 2016
b999cd9
Minor change to stubbed getParsedQueries function
kishore-narendran Apr 26, 2016
701e744
Removed static type for wordDictionary; refactored wordDict to wordDi…
Apr 26, 2016
94f273d
Commented some tests to pass Travis build
Apr 26, 2016
964dd01
Merge branch 'master' into yoda-query-rewriter
kishore-narendran Apr 27, 2016
7f35e04
Added some high level comments
kishore-narendran Apr 27, 2016
8ddcda8
Minor refactors
kishore-narendran Apr 27, 2016
05ce438
Merge branch 'master' into yoda-query-rewriter
kishore-narendran Apr 27, 2016
1d7dd0f
Changed StringListField to generic ListField
kishore-narendran Apr 27, 2016
fd2b5e4
Added some high level comments in the QueryRewriterTest class
kishore-narendran Apr 27, 2016
9c275a6
Merged branch 'master' into yoda-query-rewriter and fixed conflicts
kishore-narendran Apr 27, 2016
9e39101
Minor changes and removed implementation classes
kishore-narendran Apr 28, 2016
c2ea67a
Added a few comments
kishore-narendran Apr 28, 2016
5c76c68
Removed all mentions of FuzzyTokenizer.java
kishore-narendran Apr 29, 2016
9bd7d7a
Removed mention of FuzzyTokenizer.java
kishore-narendran Apr 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
public enum FieldType {
// A field that is indexed but not tokenized: the entire String
// value is indexed as a single token
STRING,
INTEGER,
DOUBLE,
STRING,
INTEGER,
DOUBLE,
DATE,
// A field that is indexed and tokenized,without term vectors
TEXT,
//A field that is the list of values
LIST;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
*/
package edu.uci.ics.textdb.common.constants;

import edu.uci.ics.textdb.api.common.*;
import edu.uci.ics.textdb.common.field.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import edu.uci.ics.textdb.api.common.Attribute;
import edu.uci.ics.textdb.api.common.FieldType;
import edu.uci.ics.textdb.api.common.IField;
import edu.uci.ics.textdb.api.common.ITuple;
import edu.uci.ics.textdb.api.common.Schema;
import edu.uci.ics.textdb.common.field.DataTuple;
import edu.uci.ics.textdb.common.field.DateField;
import edu.uci.ics.textdb.common.field.DoubleField;
import edu.uci.ics.textdb.common.field.IntegerField;
import edu.uci.ics.textdb.common.field.StringField;
import edu.uci.ics.textdb.common.field.TextField;

/**
* @author sandeepreddy602 Including this class in src/main/java since it is
* required by other projects Keeping it in src/test/java doesn't make
Expand Down Expand Up @@ -50,19 +41,19 @@ public static List<ITuple> getSamplePeopleTuples() throws ParseException {

IField[] fields1 = { new StringField("bruce banner"), new StringField("john Lee"), new IntegerField(46),
new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")),
new TextField("Tall Angry") };
new TextField("Tall Angry")};
IField[] fields2 = { new StringField("tom hanks"), new StringField("cruise"), new IntegerField(45),
new DoubleField(5.95), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1971")),
new TextField("Short Brown") };
new TextField("Short Brown")};
IField[] fields3 = { new StringField("brad lie angelina"), new StringField("pitt"), new IntegerField(44),
new DoubleField(6.10), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-12-1972")),
new TextField("White Angry") };
new TextField("White Angry")};
IField[] fields4 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43),
new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")),
new TextField("Short Angry") };
new TextField("Short Angry")};
IField[] fields5 = { new StringField("christian john wayne"), new StringField("rock bale"),
new IntegerField(42), new DoubleField(5.99),
new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Tall Fair") };
new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Tall Fair")};

ITuple tuple1 = new DataTuple(SCHEMA_PEOPLE, fields1);
ITuple tuple2 = new DataTuple(SCHEMA_PEOPLE, fields2);
Expand Down
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 {

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be used, to return an ITuple that has a list of strings, that is the list of rewritten query strings that our operator sends.

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
@@ -1,22 +1,20 @@
package edu.uci.ics.textdb.common.field;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import edu.uci.ics.textdb.api.common.Attribute;
import edu.uci.ics.textdb.api.common.IField;
import edu.uci.ics.textdb.api.common.ITuple;
import edu.uci.ics.textdb.api.common.Schema;
import edu.uci.ics.textdb.common.constants.SchemaConstants;
import edu.uci.ics.textdb.common.constants.TestConstants;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SpanTupleTest {

Expand Down
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{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of QueryRewriter sounds too big. It actually a fuzzy query rewriter, right? Maybe we can choose a more concrete name for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

@kishore-narendran kishore-narendran Apr 29, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenlica I went through the source code for containsAllResults(). It will work fine. Would you like for us to change it to that?

The only concern is that we will have to construct an ITuple of the expected results and feed it to the `containsAllResults()' function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenlica That sounds good professor. Are we good to merge?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

@kishore-narendran kishore-narendran Apr 29, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenlica 5c76c68 addressed the removal of all mentions of the implementation class FuzzyTokenizer.java. And I also corrected the typos you pointed out.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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! :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
}
}