use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.
the class AggregatorTest method testMinDOBMaxAgeAggregation.
// TEST 8: Find min in DOB and max in age column
@Test
public void testMinDOBMaxAgeAggregation() throws Exception {
Attribute attribute1 = TestConstants.DATE_OF_BIRTH_ATTR;
String attributeName1 = attribute1.getName();
AggregationType aggType1 = AggregationType.MIN;
Attribute attribute2 = TestConstants.AGE_ATTR;
String attributeName2 = attribute2.getName();
AggregationType aggType2 = AggregationType.MAX;
String resultAttributeName1 = AggregatorTestConstants.MIN_DATE_RESULT_ATTR_NAME;
String resultAttributeName2 = AggregatorTestConstants.MAX_AGE_RESULT_ATTR_NAME;
AggregationAttributeAndResult aggEntity1 = new AggregationAttributeAndResult(attributeName1, aggType1, resultAttributeName1);
AggregationAttributeAndResult aggEntity2 = new AggregationAttributeAndResult(attributeName2, aggType2, resultAttributeName2);
List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>();
aggEntitiesList.add(aggEntity1);
aggEntitiesList.add(aggEntity2);
IField[] row1 = { new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new IntegerField(46) };
Schema schema = new Schema(new Attribute(resultAttributeName1, AttributeType.DATE), new Attribute(resultAttributeName2, AttributeType.INTEGER));
List<Tuple> expectedResults = new ArrayList<>();
expectedResults.add(new Tuple(schema, row1));
List<Tuple> returnedResults = getQueryResults(aggEntitiesList);
Assert.assertEquals(1, returnedResults.size());
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.
the class TwitterJsonConverter method generateFieldsFromJson.
/**
* Generates Fields from the raw JSON tweet.
* Returns Optional.Empty() if something goes wrong while parsing this tweet.
*/
private Optional<List<IField>> generateFieldsFromJson(String rawJsonData) {
try {
// read the JSON string into a JSON object
JsonNode tweet = new ObjectMapper().readTree(rawJsonData);
// extract fields from the JSON object
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()));
String isRetweet = tweet.get("is_retweet").asText();
return Optional.of(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()), new StringField(isRetweet)));
} catch (Exception e) {
return Optional.empty();
}
}
use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.
the class TwitterFeedOperator method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED || resultCursor >= limit - 1 || resultCursor >= predicate.getTweetNum() - 1) {
return null;
}
if (twitterConnector.getClient().isDone()) {
System.out.println("Client connection closed unexpectedly: " + twitterConnector.getClient().getExitEvent().getMessage());
return null;
}
try {
msg = twitterConnector.getMsgQueue().poll(timeout, TimeUnit.SECONDS);
if (msg == null || msg.length() == 0) {
System.out.println("Did not receive a message in " + timeout + " seconds");
return null;
}
JsonNode tweet = new ObjectMapper().readValue(msg, JsonNode.class);
sourceTuple = new Tuple(outputSchema, IDField.newRandomID(), new TextField(TwitterUtils.getText(tweet)), new StringField(TwitterUtils.getMediaLink(tweet)), new StringField(TwitterUtils.getTweetLink(tweet)), new StringField(TwitterUtils.getUserLink(tweet)), new TextField(TwitterUtils.getUserScreenName(tweet)), new TextField(TwitterUtils.getUserName(tweet)), new TextField(TwitterUtils.getUserDescription(tweet)), new IntegerField(TwitterUtils.getUserFollowerCnt(tweet)), new IntegerField(TwitterUtils.getUserFriendsCnt(tweet)), new TextField(TwitterUtils.getUserLocation(tweet)), new StringField(TwitterUtils.getCreateTime(tweet)), new TextField(TwitterUtils.getPlaceName(tweet)), new StringField(TwitterUtils.getCoordinates(tweet)), new StringField(TwitterUtils.getLanguage(tweet)));
resultCursor++;
return sourceTuple;
} catch (InterruptedException e) {
System.out.println(e);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.
the class KeywordPhraseTest method testPhraseSearchForStringField.
/**
* Verifies List<ITuple> returned by Phrase Matcher on multiple word query
* on a String Field
*
* @throws Exception
*/
@Test
public void testPhraseSearchForStringField() throws Exception {
// Prepare Query
String query = "george lin lin";
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>();
Span span1 = new Span("firstName", 0, 14, "george lin lin", "george lin lin");
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);
}
use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.
the class KeywordPhraseTest method testWordInMultipleFieldsQueryWithStopWords5.
/**
* Verifies: Query with Stop Words match corresponding phrases in the
* document Used to cause exception sometimes if there is a space between
* words
*
* @throws Exception
* with Medline data
*/
@Test
public void testWordInMultipleFieldsQueryWithStopWords5() throws Exception {
// Prepare Query
String query = "gain weight";
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(keywordTestConstants.ABSTRACT);
// Prepare expected result list
List<Span> list = new ArrayList<>();
Span span1 = new Span(keywordTestConstants.ABSTRACT, 26, 37, "gain weight", "gain weight");
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(4566015), new TextField(""), new TextField("Significance of milk pH in newborn infants."), new TextField("V C Harrison, G Peat"), new StringField("4-5839 Dec 2, 1972"), new TextField("British medical journal"), new TextField(""), new TextField("Infant Nutritional Physiological Phenomena, Infant, Newborn, Milk"), new TextField("Bottle-fed infants do not gain weight as rapidly as breast-fed babies during the first week of life. This " + "weight lag can be corrected by the addition of a small amount of alkali (sodium bicarbonate or trometamol) to " + "the feeds. The alkali corrects the acidity of cow's milk which now assumes some of the properties of human breast " + "milk. It has a bacteriostatic effect on specific Escherichia coli in vitro, and in infants it produces a stool with" + " a preponderance of lactobacilli over E. coli organisms. When alkali is removed from the milk there is a decrease in" + " the weight of an infant and the stools contain excessive numbers of E. coli bacteria.A pH-corrected milk appears to" + " be more physiological than unaltered cow's milk and may provide some protection against gastroenteritis in early " + "life. Its bacteriostatic effect on specific E. coli may be of practical significance in feed preparations where " + "terminal sterilization and refrigeration are not available. The study was conducted during the week after birth, and " + "no conclusions are derived for older infants. The long-term effects of trometamol are unknown. No recommendation can " + "be given for the addition of sodium bicarbonate to milks containing a higher content of sodium."), 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);
}
Aggregations