Search in sources :

Example 1 with StringField

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

the class TwitterConverter method generateFieldsFromJson.

private List<IField> generateFieldsFromJson(String rawJsonData) {
    try {
        JsonNode tweet = new ObjectMapper().readTree(rawJsonData);
        String text = tweet.get("text").asText();
        Long id = tweet.get("id").asLong();
        String tweetLink = "https://twitter.com/statuses/" + id;
        JsonNode userNode = tweet.get("user");
        String userScreenName = userNode.get("screen_name").asText();
        String userLink = "https://twitter.com/" + userScreenName;
        String userName = userNode.get("name").asText();
        String userDescription = userNode.get("description").asText();
        Integer userFollowersCount = userNode.get("followers_count").asInt();
        Integer userFriendsCount = userNode.get("friends_count").asInt();
        JsonNode geoTagNode = tweet.get("geo_tag");
        String state = geoTagNode.get("stateName").asText();
        String county = geoTagNode.get("countyName").asText();
        String city = geoTagNode.get("cityName").asText();
        String createAt = tweet.get("create_at").asText();
        ZonedDateTime zonedCreateAt = ZonedDateTime.parse(createAt, DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
        return Arrays.asList(new StringField(id.toString()), new TextField(text), new StringField(tweetLink), new StringField(userLink), new TextField(userScreenName), new TextField(userName), new TextField(userDescription), new IntegerField(userFollowersCount), new IntegerField(userFriendsCount), new TextField(state), new TextField(county), new TextField(city), new DateTimeField(zonedCreateAt.toLocalDateTime()));
    } catch (Exception e) {
        return Arrays.asList();
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerField(edu.uci.ics.texera.api.field.IntegerField) DateTimeField(edu.uci.ics.texera.api.field.DateTimeField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 2 with StringField

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

the class SpanTupleTest method testGetters.

@Test
public void testGetters() throws ParseException {
    // create data tuple first
    Attribute[] attributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
    for (int count = 0; count < attributes.length - 1; count++) {
        attributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    attributes[attributes.length - 1] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
    List<IField> fields = new ArrayList<IField>(Arrays.asList(new IField[] { new StringField("bruce"), new StringField("lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("bruce was born in new york city and was grown up in los angeles") }));
    IField spanField = createSpanListField();
    fields.add(spanField);
    spanTuple = new Tuple(new Schema(attributes), fields.toArray(new IField[fields.size()]));
    IField spanFieldRetrieved = spanTuple.getField(SchemaConstants.SPAN_LIST);
    Assert.assertTrue(spanFieldRetrieved instanceof ListField);
    Assert.assertSame(spanField, spanFieldRetrieved);
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) ListField(edu.uci.ics.texera.api.field.ListField) IField(edu.uci.ics.texera.api.field.IField) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 3 with StringField

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

the class PieChartSinkTestConstants method getTuples.

public static List<Tuple> getTuples() {
    IField[] fields1 = { new IntegerField(1), new StringField("Tom"), new IntegerField(10000), new StringField("M") };
    IField[] fields2 = { new IntegerField(2), new StringField("Jerry"), new IntegerField(80), new StringField("M") };
    IField[] fields3 = { new IntegerField(3), new StringField("Trump"), new IntegerField(80), new StringField("M") };
    IField[] fields4 = { new IntegerField(4), new StringField("Bob"), new IntegerField(70), new StringField("M") };
    Tuple tuple1 = new Tuple(PIE_SCHEMA, fields1);
    Tuple tuple2 = new Tuple(PIE_SCHEMA, fields2);
    Tuple tuple3 = new Tuple(PIE_SCHEMA, fields3);
    Tuple tuple4 = new Tuple(PIE_SCHEMA, fields4);
    return Arrays.asList(tuple1, tuple2, tuple3, tuple4);
}
Also used : StringField(edu.uci.ics.texera.api.field.StringField) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 4 with StringField

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

the class PieChartSinkTestConstants method getResultTuples.

public static List<Tuple> getResultTuples() {
    IField[] fields1 = { new StringField("Tom"), new IntegerField(1000) };
    IField[] fields2 = { new StringField("Other"), new IntegerField(230) };
    Tuple tuple1 = new Tuple(PIE_RESULT_SCHEMA, fields1);
    Tuple tuple2 = new Tuple(PIE_RESULT_SCHEMA, fields2);
    return Arrays.asList(tuple1, tuple2);
}
Also used : StringField(edu.uci.ics.texera.api.field.StringField) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 5 with StringField

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

the class KeywordPhraseTest method testWordInMultipleFieldsQueryWithStopWords1.

/**
 * Verifies: Query with Stop Words match corresponding phrases in the
 * document
 *
 * @throws Exception
 */
@Test
public void testWordInMultipleFieldsQueryWithStopWords1() throws Exception {
    // Prepare Query
    String query = "lin and and angry";
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare expected result list
    List<Span> list = new ArrayList<>();
    Span span1 = new Span("description", 25, 45, "lin and and angry", "lin clooney is Angry");
    list.add(span1);
    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("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<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    List<Tuple> expectedResultList = new ArrayList<>();
    expectedResultList.add(tuple1);
    // Perform Query
    List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, phrase);
    // Perform Check
    boolean contains = TestUtils.equals(expectedResultList, resultList);
    Assert.assertTrue(contains);
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

StringField (edu.uci.ics.texera.api.field.StringField)103 Tuple (edu.uci.ics.texera.api.tuple.Tuple)94 IField (edu.uci.ics.texera.api.field.IField)87 IntegerField (edu.uci.ics.texera.api.field.IntegerField)87 TextField (edu.uci.ics.texera.api.field.TextField)79 Schema (edu.uci.ics.texera.api.schema.Schema)75 ArrayList (java.util.ArrayList)74 Test (org.junit.Test)70 Span (edu.uci.ics.texera.api.span.Span)64 DoubleField (edu.uci.ics.texera.api.field.DoubleField)63 DateField (edu.uci.ics.texera.api.field.DateField)60 Attribute (edu.uci.ics.texera.api.schema.Attribute)60 SimpleDateFormat (java.text.SimpleDateFormat)58 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)29 JoinDistancePredicate (edu.uci.ics.texera.dataflow.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 IDField (edu.uci.ics.texera.api.field.IDField)5 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)4