Search in sources :

Example 1 with Location

use of com.twitter.hbc.core.endpoint.Location in project textdb by TextDB.

the class TwitterFeedTestHelper method inLocation.

public static boolean inLocation(List<Tuple> tupleList, String location) {
    List<String> boundingCoordinate = Arrays.asList(location.trim().split(","));
    List<Double> boundingBox = new ArrayList<>();
    boundingCoordinate.stream().forEach(s -> boundingBox.add(Double.parseDouble(s.trim())));
    Location geoBox = new Location(new Location.Coordinate(boundingBox.get(1), boundingBox.get(0)), new Location.Coordinate(boundingBox.get(3), boundingBox.get(2)));
    Location.Coordinate southwestCoordinate = geoBox.southwestCoordinate();
    Location.Coordinate northeastCoordinate = geoBox.northeastCoordinate();
    for (Tuple tuple : tupleList) {
        if (!tuple.getField(TWEET_COORDINATES).getValue().toString().equals("n/a") && !tuple.getField(TWEET_LOCATION).getValue().toString().equals("n/a")) {
            List<String> coordString = Arrays.asList(tuple.getField(TWEET_COORDINATES).getValue().toString().split(","));
            Location.Coordinate coordinate = new Location.Coordinate(Double.parseDouble(coordString.get(0)), Double.parseDouble(coordString.get(1)));
            if (!(coordinate.latitude() >= southwestCoordinate.latitude() && coordinate.longitude() >= southwestCoordinate.longitude() && coordinate.latitude() <= northeastCoordinate.latitude() && coordinate.longitude() <= northeastCoordinate.longitude())) {
                if (!tuple.getField(TWEET_LOCATION).getValue().toString().contains("United States")) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Location(com.twitter.hbc.core.endpoint.Location)

Example 2 with Location

use of com.twitter.hbc.core.endpoint.Location in project textdb by TextDB.

the class TwitterUtils method getPlaceLocation.

/**
 * To track tweets inside a geoBox defined by a List</Location>.
 * The string defines the coordinates in the order of "latitude_SW, longitude_SW, latitude_NE, longitude_NE".
 *
 * @param inputLocation
 * @return
 * @throws TexeraException
 */
public static List<Location> getPlaceLocation(String inputLocation) throws TexeraException {
    List<Location> locationList = new ArrayList<>();
    if (inputLocation == null || inputLocation.isEmpty()) {
        return locationList;
    }
    List<String> boudingCoordinate = Arrays.asList(inputLocation.trim().split(","));
    if (boudingCoordinate.size() != 4 || boudingCoordinate.stream().anyMatch(s -> s.trim().isEmpty())) {
        throw new DataflowException("Please provide valid location coordinates");
    }
    List<Double> boundingBox = new ArrayList<>();
    boudingCoordinate.stream().forEach(s -> boundingBox.add(Double.parseDouble(s.trim())));
    locationList.add(new Location(new Coordinate(boundingBox.get(1), boundingBox.get(0)), new Coordinate(boundingBox.get(3), boundingBox.get(2))));
    return locationList;
}
Also used : Arrays(java.util.Arrays) Coordinate(com.twitter.hbc.core.endpoint.Location.Coordinate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) IOException(java.io.IOException) Location(com.twitter.hbc.core.endpoint.Location) ArrayList(java.util.ArrayList) List(java.util.List) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode) Attribute(edu.uci.ics.texera.api.schema.Attribute) Coordinate(com.twitter.hbc.core.endpoint.Location.Coordinate) ArrayList(java.util.ArrayList) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) Location(com.twitter.hbc.core.endpoint.Location)

Aggregations

Location (com.twitter.hbc.core.endpoint.Location)2 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Coordinate (com.twitter.hbc.core.endpoint.Location.Coordinate)1 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)1 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 Attribute (edu.uci.ics.texera.api.schema.Attribute)1 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)1 Schema (edu.uci.ics.texera.api.schema.Schema)1 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1