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();
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations