Search in sources :

Example 76 with StringField

use of edu.uci.ics.textdb.api.field.StringField in project textdb by TextDB.

the class KeywordConjunctionTest method testSingleWordQueryInTextField.

/**
     * Verifies GetNextTuple of Keyword Matcher and single word queries in Text
     * Field
     * 
     * @throws Exception
     */
@Test
public void testSingleWordQueryInTextField() throws Exception {
    // Prepare the query
    String query = "TaLL";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare the expected result list
    List<Span> list = new ArrayList<>();
    Span span = new Span("description", 0, 4, "tall", "Tall", 0);
    list.add(span);
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
    IField[] fields1 = { new StringField("bruce"), 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 ListField<>(list) };
    IField[] fields2 = { 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 ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    List<Tuple> expectedResultList = new ArrayList<>();
    expectedResultList.add(tuple1);
    expectedResultList.add(tuple2);
    // Perform the query
    List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, conjunction);
    // check the results
    boolean contains = TestUtils.equals(expectedResultList, resultList);
    Assert.assertTrue(contains);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 77 with StringField

use of edu.uci.ics.textdb.api.field.StringField in project textdb by TextDB.

the class KeywordConjunctionTest method testWordInMultipleFieldsQueryChinese.

/**
     * Verifies: data source has multiple attributes, and an entity can appear
     * in all the fields and multiple times.
     * Test for Chinese data.
     * 
     * @throws Exception
     */
@Test
public void testWordInMultipleFieldsQueryChinese() throws Exception {
    // Prepare the query
    String query = "建筑";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstantsChinese.FIRST_NAME);
    attributeNames.add(TestConstantsChinese.LAST_NAME);
    attributeNames.add(TestConstantsChinese.DESCRIPTION);
    // Prepare the expected result list
    List<Span> list = new ArrayList<>();
    Span span1 = new Span("lastName", 0, 2, "建筑", "建筑");
    Span span2 = new Span("description", 3, 5, "建筑", "建筑", 2);
    list.add(span1);
    list.add(span2);
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
    IField[] fields1 = { new StringField("宋江"), new StringField("建筑"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("伟大的建筑是历史的坐标,具有传承的价值。"), new ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    List<Tuple> expectedResultList = new ArrayList<>();
    expectedResultList.add(tuple1);
    // Perform the query
    List<Tuple> resultList = KeywordTestHelper.getQueryResults(CHINESE_TABLE, query, attributeNames, conjunction, Integer.MAX_VALUE, 0);
    // check the results
    boolean contains = TestUtils.equals(expectedResultList, resultList);
    Assert.assertTrue(contains);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 78 with StringField

use of edu.uci.ics.textdb.api.field.StringField in project textdb by TextDB.

the class KeywordConjunctionTest method testMatchingWithLimitOffset.

@Test
public void testMatchingWithLimitOffset() throws TextDBException, ParseException, java.text.ParseException {
    String query = "angry";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.DESCRIPTION);
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
    List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, conjunction, 3, 2);
    List<Tuple> expectedList = new ArrayList<>();
    Span span1 = new Span("description", 5, 10, "angry", "Angry", 1);
    Span span2 = new Span("description", 6, 11, "angry", "Angry", 1);
    Span span3 = new Span("description", 40, 45, "angry", "Angry", 8);
    Span span4 = new Span("description", 6, 11, "angry", "angry", 1);
    List<Span> list1 = new ArrayList<>();
    list1.add(span1);
    IField[] fields1 = { new StringField("bruce"), 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 ListField<>(list1) };
    List<Span> list2 = new ArrayList<>();
    list2.add(span2);
    IField[] fields2 = { 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 ListField<>(list2) };
    List<Span> list3 = new ArrayList<>();
    list3.add(span3);
    IField[] fields3 = { 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("Lin Clooney is Short and lin clooney is Angry"), new ListField<>(list3) };
    List<Span> list4 = new ArrayList<>();
    list4.add(span4);
    IField[] fields4 = { new StringField("Mary brown"), new StringField("Lake Forest"), new IntegerField(42), new DoubleField(5.99), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new TextField("Short angry"), new ListField<>(list4) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    Tuple tuple3 = new Tuple(new Schema(schemaAttributes), fields3);
    Tuple tuple4 = new Tuple(new Schema(schemaAttributes), fields4);
    expectedList.add(tuple1);
    expectedList.add(tuple2);
    expectedList.add(tuple3);
    expectedList.add(tuple4);
    Assert.assertEquals(expectedList.size(), 4);
    Assert.assertEquals(resultList.size(), 2);
    Assert.assertTrue(TestUtils.containsAll(expectedList, resultList));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Test(org.junit.Test)

Example 79 with StringField

use of edu.uci.ics.textdb.api.field.StringField in project textdb by TextDB.

the class KeywordConjunctionTest method testSingleWordQueryInStringField.

/**
     * Verifies GetNextTuple of Keyword Matcher and single word queries in
     * String Field
     * 
     * @throws Exception
     */
@Test
public void testSingleWordQueryInStringField() throws Exception {
    // Prepare the query
    String query = "bruce";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare the expected result list
    List<Span> list = new ArrayList<>();
    Span span = new Span("firstName", 0, 5, "bruce", "bruce");
    list.add(span);
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
    IField[] fields1 = { new StringField("bruce"), 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 ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    List<Tuple> expectedResultList = new ArrayList<>();
    expectedResultList.add(tuple1);
    // Perform the query
    List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, conjunction);
    // check the results
    boolean contains = TestUtils.equals(expectedResultList, resultList);
    Assert.assertTrue(contains);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 80 with StringField

use of edu.uci.ics.textdb.api.field.StringField in project textdb by TextDB.

the class KeywordPhraseTest method testWordInMultipleFieldsQueryWithStopWords4.

/**
     * Verifies: Query with Stop Words match corresponding phrases in the
     * document Used to cause exception if there is a special symbol with the
     * words, ex: big(
     * 
     * @throws Exception
     *             with Medline data
     */
@Test
public void testWordInMultipleFieldsQueryWithStopWords4() throws Exception {
    // Prepare Query
    String query = "x-ray";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(keywordTestConstants.ABSTRACT);
    // Prepare expected result list
    List<Span> list = new ArrayList<>();
    Span span1 = new Span(keywordTestConstants.ABSTRACT, 226, 231, "x-ray", "x-ray");
    list.add(span1);
    Attribute[] schemaAttributes = new Attribute[keywordTestConstants.ATTRIBUTES_MEDLINE.length + 1];
    for (int count = 0; count < schemaAttributes.length - 1; count++) {
        schemaAttributes[count] = keywordTestConstants.ATTRIBUTES_MEDLINE[count];
    }
    schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
    IField[] fields = { new IntegerField(17832788), new TextField(""), new TextField("Cosmic X-ray Sources."), new TextField("S Bowyer, E T Byram, T A Chubb, H Friedman"), new StringField("147-3656 Jan 22, 1965"), new TextField("Science (New York, N.Y.)"), new TextField(""), new TextField(""), new TextField("Eight new sources of cosmic x-rays were detected by two Aerobee surveys in 1964. One source, from Sagittarius, is close to the galactic center, and the other, " + "from Ophiuchus, may coincide with Kepler's 1604 supernova. All the x-ray sources are fairly close to the galactic plane."), new DoubleField(0.667832788), new ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields);
    List<Tuple> expectedResultList = new ArrayList<>();
    expectedResultList.add(tuple1);
    List<Tuple> results = KeywordTestHelper.getQueryResults(MEDLINE_TABLE, query, attributeNames, phrase);
    // Perform Check
    boolean contains = TestUtils.equals(expectedResultList, results);
    Assert.assertTrue(contains);
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Span(edu.uci.ics.textdb.api.span.Span) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

StringField (edu.uci.ics.textdb.api.field.StringField)91 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)85 IField (edu.uci.ics.textdb.api.field.IField)84 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)81 TextField (edu.uci.ics.textdb.api.field.TextField)81 ArrayList (java.util.ArrayList)76 Test (org.junit.Test)75 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)68 DateField (edu.uci.ics.textdb.api.field.DateField)64 Schema (edu.uci.ics.textdb.api.schema.Schema)64 SimpleDateFormat (java.text.SimpleDateFormat)63 Attribute (edu.uci.ics.textdb.api.schema.Attribute)60 Span (edu.uci.ics.textdb.api.span.Span)58 Dictionary (edu.uci.ics.textdb.exp.dictionarymatcher.Dictionary)24 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)9 IDField (edu.uci.ics.textdb.api.field.IDField)5 ParseException (java.text.ParseException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3