Java Code Examples for com.thinkaurelius.titan.core.attribute.Geoshape

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.attribute.Geoshape. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testGeoJsonCircle() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Circle\",\n" +
            "    \"radius\": 30.5, " +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.circle(10.5, 20.5, 30.5), s.convert(json));
}
 
Example 2
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPolygonNotBox1() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 12.5],[22.5, 12.5],[22.5, 10.5],[20.5, 10.6]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);

}
 
Example 3
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPolygonNotBox2() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
     s.convert(json);

}
 
Example 4
Project: titan1withtp3.1   File: GeoToWktConverterTest.java   Source Code and License 6 votes vote down vote up
/**
 * Titan Geoshapes are converted to a string that gets sent to its respective index. Unfortunately, the string format
 * is not compatible with Solr 4. The GeoToWktConverter transforms the Geoshape's string value into a Well-Known Text
 * format understood by Solr.
 */
@Test
public void testConvertGeoshapePointToWktString() throws BackendException {
    Geoshape p1 = Geoshape.point(35.4, 48.9); //no spaces, no negative values
    Geoshape p2 = Geoshape.point(-35.4,48.9); //negative longitude value
    Geoshape p3 = Geoshape.point(35.4, -48.9); //negative latitude value

    String wkt1 = "POINT(48.9 35.4)";
    String actualWkt1 = GeoToWktConverter.convertToWktString(p1);

    String wkt2 = "POINT(48.9 -35.4)";
    String actualWkt2 = GeoToWktConverter.convertToWktString(p2);

    String wkt3 = "POINT(-48.9 35.4)";
    String actualWkt3 = GeoToWktConverter.convertToWktString(p3);

    assertEquals(wkt1, actualWkt1);
    assertEquals(wkt2, actualWkt2);
    assertEquals(wkt3, actualWkt3);

}
 
Example 5
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 6 votes vote down vote up
private List<Geoshape.Point> getPolygonPoints(Geoshape polygon) {
    List<Geoshape.Point> locations = new ArrayList<>();

    int index = 0;
    boolean hasCoordinates = true;
    while (hasCoordinates) {
        try {
            locations.add(polygon.getPoint(index));
        } catch (ArrayIndexOutOfBoundsException ignore) {
            //just means we asked for a point past the size of the list
            //of known coordinates
            hasCoordinates = false;
        }
    }

    return locations;
}
 
Example 6
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testGeoJsonCircle() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Circle\",\n" +
            "    \"radius\": 30.5, " +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.circle(10.5, 20.5, 30.5), s.convert(json));
}
 
Example 7
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPolygonNotBox1() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 12.5],[22.5, 12.5],[22.5, 10.5],[20.5, 10.6]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);

}
 
Example 8
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPolygonNotBox2() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
     s.convert(json);

}
 
Example 9
Project: titan1.0.1.kafka   File: GeoToWktConverterTest.java   Source Code and License 6 votes vote down vote up
/**
 * Titan Geoshapes are converted to a string that gets sent to its respective index. Unfortunately, the string format
 * is not compatible with Solr 4. The GeoToWktConverter transforms the Geoshape's string value into a Well-Known Text
 * format understood by Solr.
 */
@Test
public void testConvertGeoshapePointToWktString() throws BackendException {
    Geoshape p1 = Geoshape.point(35.4, 48.9); //no spaces, no negative values
    Geoshape p2 = Geoshape.point(-35.4,48.9); //negative longitude value
    Geoshape p3 = Geoshape.point(35.4, -48.9); //negative latitude value

    String wkt1 = "POINT(48.9 35.4)";
    String actualWkt1 = GeoToWktConverter.convertToWktString(p1);

    String wkt2 = "POINT(48.9 -35.4)";
    String actualWkt2 = GeoToWktConverter.convertToWktString(p2);

    String wkt3 = "POINT(-48.9 35.4)";
    String actualWkt3 = GeoToWktConverter.convertToWktString(p3);

    assertEquals(wkt1, actualWkt1);
    assertEquals(wkt2, actualWkt2);
    assertEquals(wkt3, actualWkt3);

}
 
Example 10
Project: titan0.5.4-hbase1.1.1-custom   File: GeoToWktConverterTest.java   Source Code and License 6 votes vote down vote up
/**
 * Titan Geoshapes are converted to a string that gets sent to its respective index. Unfortunately, the string format
 * is not compatible with Solr 4. The GeoToWktConverter transforms the Geoshape's string value into a Well-Known Text
 * format understood by Solr.
 */
@Test
public void testConvertGeoshapePointToWktString() throws BackendException {
    Geoshape p1 = Geoshape.point(35.4, 48.9); //no spaces, no negative values
    Geoshape p2 = Geoshape.point(-35.4,48.9); //negative longitude value
    Geoshape p3 = Geoshape.point(35.4, -48.9); //negative latitude value

    String wkt1 = "POINT(48.9 35.4)";
    String actualWkt1 = GeoToWktConverter.convertToWktString(p1);

    String wkt2 = "POINT(48.9 -35.4)";
    String actualWkt2 = GeoToWktConverter.convertToWktString(p2);

    String wkt3 = "POINT(-48.9 35.4)";
    String actualWkt3 = GeoToWktConverter.convertToWktString(p3);

    assertEquals(wkt1, actualWkt1);
    assertEquals(wkt2, actualWkt2);
    assertEquals(wkt3, actualWkt3);

}
 
Example 11
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testDistance() {
    Geoshape p1 = Geoshape.point(37.759, -122.536);
    Geoshape p2 = Geoshape.point(35.714, -105.938);

    double distance = 1496;
    assertEquals(distance,p1.getPoint().distance(p2.getPoint()),5.0);

    p1 = Geoshape.point(0.0,0.0);
    p2 = Geoshape.point(10.0,10.0);
    //System.out.println(p1.getPoint().distance(p2.getPoint()));
}
 
Example 12
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testIntersection() {
    for (int i=0;i<50;i++) {
        Geoshape point = Geoshape.point(i,i);
        Geoshape circle = Geoshape.circle(0.0,0.0,point.getPoint().distance(Geoshape.point(0,0).getPoint())+10);
        assertTrue(circle.intersect(point));
        assertTrue(point.intersect(circle));
        assertTrue(circle.intersect(circle));
    }
}
 
Example 13
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testEquality() {
    Geoshape c = Geoshape.circle(10.0,12.5,100);
    Geoshape b = Geoshape.box(20.0, 22.5, 40.5, 60.5);
    assertEquals(Geoshape.circle(10.0,12.5,100),c);
    assertEquals(Geoshape.box(20.0,22.5,40.5,60.5),b);
    assertEquals(Geoshape.circle(10.0,12.5,100).hashCode(),c.hashCode());
    assertEquals(Geoshape.box(20.0,22.5,40.5,60.5).hashCode(),b.hashCode());
    assertNotSame(c.hashCode(),b.hashCode());
    assertNotSame(c,b);
    System.out.println(c);
    System.out.println(b);
}
 
Example 14
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testParseCollection() {
    Geoshape.GeoshapeSerializer serializer = new Geoshape.GeoshapeSerializer();
    assertEquals(Geoshape.point(10, 20), serializer.convert(Arrays.asList(10, 20)));
    assertEquals(Geoshape.circle(10, 20, 30), serializer.convert(Arrays.asList(10, 20, 30)));
    assertEquals(Geoshape.box(10, 20, 30, 40), serializer.convert(Arrays.asList(10, 20, 30, 40)));
}
 
Example 15
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonPoint() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Point\",\n" +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.point(10.5, 20.5), s.convert(json));
}
 
Example 16
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPointUnparseable() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Point\",\n" +
            "    \"coordinates\": [20.5, \"10.5\"]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);
}
 
Example 17
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonCircleMissingRadius() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Circle\",\n" +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);
}
 
Example 18
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonPolygon() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5],[20.5, 12.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.box(10.5, 20.5, 12.5, 22.5), s.convert(json));

    //Try the reverse order points
    json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 12.5],[22.5, 12.5],[22.5, 10.5],[20.5, 10.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.box(10.5, 20.5, 12.5, 22.5), s.convert(json));
}
 
Example 19
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonGeometry() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "    \"type\": \"Point\",\n" +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.point(10.5, 20.5), s.convert(json));

}
 
Example 20
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonSerialization() throws IOException {
    SimpleModule module = new SimpleModule();
    module.addSerializer(new Geoshape.GeoshapeGsonSerializer());
    final ObjectMapper om = new ObjectMapper();
    om.registerModule(module);
    assertEquals("{\"type\":\"Point\",\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.point(10.5, 20.5)));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[20.5,10.5],[22.5,10.5],[22.5,12.5],[20.5,12.5]]}", om.writeValueAsString(Geoshape.box(10.5, 20.5, 12.5, 22.5)));
    assertEquals("{\"type\":\"Circle\",\"radius\":30.5,\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.circle(10.5, 20.5, 30.5)));

}
 
Example 21
Project: titan1withtp3.1   File: GeoToWktConverter.java   Source Code and License 5 votes vote down vote up
/**
 * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0].
 * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0)
 */
public static String convertToWktString(Geoshape fieldValue) throws BackendException {
    if (fieldValue.getType() == Geoshape.Type.POINT) {
        Geoshape.Point point = fieldValue.getPoint();
        return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")";
    } else {
        throw new PermanentBackendException("Cannot index " + fieldValue.getType());
    }
}
 
Example 22
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
private Object convertValue(Object value) throws BackendException {
    if (value instanceof Geoshape)
        return GeoToWktConverter.convertToWktString((Geoshape) value);
    // in order to serialize/deserialize properly Solr will have to have an
    // access to Titan source which has Decimal type, so for now we simply convert to
    // double and let Solr do the same thing or fail.
    if (value instanceof AbstractDecimal)
        return ((AbstractDecimal) value).doubleValue();
    if (value instanceof UUID)
        return value.toString();
    return value;
}
 
Example 23
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
    Class<?> dataType = information.getDataType();
    Mapping mapping = getMapping(information);
    if (mapping!= DEFAULT && !AttributeUtil.isString(dataType)) return false;

    if (Number.class.isAssignableFrom(dataType)) {
        return titanPredicate instanceof Cmp;
    } else if (dataType == Geoshape.class) {
        return titanPredicate == Geo.WITHIN;
    } else if (AttributeUtil.isString(dataType)) {
        switch(mapping) {
            case DEFAULT:
            case TEXT:
                return titanPredicate == Text.CONTAINS || titanPredicate == Text.CONTAINS_PREFIX || titanPredicate == Text.CONTAINS_REGEX;
            case STRING:
                return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL || titanPredicate==Text.REGEX || titanPredicate==Text.PREFIX;
            //                case TEXTSTRING:
            //                    return (titanPredicate instanceof Text) || titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL;
        }
    } else if (dataType == Date.class) {
        if (titanPredicate instanceof Cmp) return true;
    } else if (dataType == Boolean.class) {
        return titanPredicate == EQUAL || titanPredicate == NOT_EQUAL;
    } else if (dataType == UUID.class) {
        return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL;
    }
    return false;
}
 
Example 24
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
@Override
public boolean supports(KeyInformation information) {
    Class<?> dataType = information.getDataType();
    Mapping mapping = getMapping(information);
    if (Number.class.isAssignableFrom(dataType) || dataType == Geoshape.class || dataType == Date.class || dataType == Boolean.class || dataType == UUID.class) {
        if (mapping== DEFAULT) return true;
    } else if (AttributeUtil.isString(dataType)) {
        if (mapping== DEFAULT || mapping== TEXT || mapping== STRING) return true;
    }
    return false;
}
 
Example 25
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
@Override
public String mapKey2Field(String key, KeyInformation keyInfo) {
    Preconditions.checkArgument(!StringUtils.containsAny(key, new char[]{' '}),"Invalid key name provided: %s",key);
    if (!dynFields) return key;
    if (ParameterType.MAPPED_NAME.hasParameter(keyInfo.getParameters())) return key;
    String postfix;
    Class datatype = keyInfo.getDataType();
    if (AttributeUtil.isString(datatype)) {
        Mapping map = getStringMapping(keyInfo);
        switch (map) {
            case TEXT: postfix = "_t"; break;
            case STRING: postfix = "_s"; break;
            default: throw new IllegalArgumentException("Unsupported string mapping: " + map);
        }
    } else if (AttributeUtil.isWholeNumber(datatype)) {
        if (datatype.equals(Long.class)) postfix = "_l";
        else postfix = "_i";
    } else if (AttributeUtil.isDecimal(datatype)) {
        if (datatype.equals(Float.class)) postfix = "_f";
        else postfix = "_d";
    } else if (datatype.equals(Geoshape.class)) {
        postfix = "_g";
    } else if (datatype.equals(Date.class)) {
        postfix = "_dt";
    } else if (datatype.equals(Boolean.class)) {
        postfix = "_b";
    } else if (datatype.equals(UUID.class)) {
        postfix = "_uuid";
    } else throw new IllegalArgumentException("Unsupported data type ["+datatype+"] for field: " + key);
    return key+postfix;
}
 
Example 26
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
/**
 * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0].
 * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0)
 */
static String convertToWktString(Geoshape fieldValue) throws BackendException {
    if (fieldValue.getType() == Geoshape.Type.POINT) {
        Geoshape.Point point = fieldValue.getPoint();
        return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")";
    } else {
        throw new PermanentBackendException("Cannot index " + fieldValue.getType());
    }
}
 
Example 27
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testDistance() {
    Geoshape p1 = Geoshape.point(37.759, -122.536);
    Geoshape p2 = Geoshape.point(35.714, -105.938);

    double distance = 1496;
    assertEquals(distance,p1.getPoint().distance(p2.getPoint()),5.0);

    p1 = Geoshape.point(0.0,0.0);
    p2 = Geoshape.point(10.0,10.0);
    //System.out.println(p1.getPoint().distance(p2.getPoint()));
}
 
Example 28
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testIntersection() {
    for (int i=0;i<50;i++) {
        Geoshape point = Geoshape.point(i,i);
        Geoshape circle = Geoshape.circle(0.0,0.0,point.getPoint().distance(Geoshape.point(0,0).getPoint())+10);
        assertTrue(circle.intersect(point));
        assertTrue(point.intersect(circle));
        assertTrue(circle.intersect(circle));
    }
}
 
Example 29
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testEquality() {
    Geoshape c = Geoshape.circle(10.0,12.5,100);
    Geoshape b = Geoshape.box(20.0, 22.5, 40.5, 60.5);
    assertEquals(Geoshape.circle(10.0,12.5,100),c);
    assertEquals(Geoshape.box(20.0,22.5,40.5,60.5),b);
    assertEquals(Geoshape.circle(10.0,12.5,100).hashCode(),c.hashCode());
    assertEquals(Geoshape.box(20.0,22.5,40.5,60.5).hashCode(),b.hashCode());
    assertNotSame(c.hashCode(),b.hashCode());
    assertNotSame(c,b);
    System.out.println(c);
    System.out.println(b);
}
 
Example 30
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testParseCollection() {
    Geoshape.GeoshapeSerializer serializer = new Geoshape.GeoshapeSerializer();
    assertEquals(Geoshape.point(10, 20), serializer.convert(Arrays.asList(10, 20)));
    assertEquals(Geoshape.circle(10, 20, 30), serializer.convert(Arrays.asList(10, 20, 30)));
    assertEquals(Geoshape.box(10, 20, 30, 40), serializer.convert(Arrays.asList(10, 20, 30, 40)));
}
 
Example 31
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonPoint() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Point\",\n" +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.point(10.5, 20.5), s.convert(json));
}
 
Example 32
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPointUnparseable() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Point\",\n" +
            "    \"coordinates\": [20.5, \"10.5\"]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);
}
 
Example 33
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonCircleMissingRadius() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Circle\",\n" +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);
}
 
Example 34
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonPolygon() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5],[20.5, 12.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.box(10.5, 20.5, 12.5, 22.5), s.convert(json));

    //Try the reverse order points
    json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 12.5],[22.5, 12.5],[22.5, 10.5],[20.5, 10.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.box(10.5, 20.5, 12.5, 22.5), s.convert(json));
}
 
Example 35
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonGeometry() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "    \"type\": \"Point\",\n" +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.point(10.5, 20.5), s.convert(json));

}
 
Example 36
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGeoJsonSerialization() throws IOException {
    SimpleModule module = new SimpleModule();
    module.addSerializer(new Geoshape.GeoshapeGsonSerializer());
    final ObjectMapper om = new ObjectMapper();
    om.registerModule(module);
    assertEquals("{\"type\":\"Point\",\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.point(10.5, 20.5)));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[20.5,10.5],[22.5,10.5],[22.5,12.5],[20.5,12.5]]}", om.writeValueAsString(Geoshape.box(10.5, 20.5, 12.5, 22.5)));
    assertEquals("{\"type\":\"Circle\",\"radius\":30.5,\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.circle(10.5, 20.5, 30.5)));

}
 
Example 37
Project: titan1.0.1.kafka   File: GeoToWktConverter.java   Source Code and License 5 votes vote down vote up
/**
 * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0].
 * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0)
 */
public static String convertToWktString(Geoshape fieldValue) throws BackendException {
    if (fieldValue.getType() == Geoshape.Type.POINT) {
        Geoshape.Point point = fieldValue.getPoint();
        return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")";
    } else {
        throw new PermanentBackendException("Cannot index " + fieldValue.getType());
    }
}
 
Example 38
Project: titan0.5.4-hbase1.1.1-custom   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testDistance() {
    Geoshape p1 = Geoshape.point(37.759,-122.536);
    Geoshape p2 = Geoshape.point(35.714,-105.938);

    double distance = 1496;
    assertEquals(distance,p1.getPoint().distance(p2.getPoint()),5.0);

    p1 = Geoshape.point(0.0,0.0);
    p2 = Geoshape.point(10.0,10.0);
    //System.out.println(p1.getPoint().distance(p2.getPoint()));
}
 
Example 39
Project: titan0.5.4-hbase1.1.1-custom   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testIntersection() {
    for (int i=0;i<50;i++) {
        Geoshape point = Geoshape.point(i,i);
        Geoshape circle = Geoshape.circle(0.0,0.0,point.getPoint().distance(Geoshape.point(0,0).getPoint())+10);
        assertTrue(circle.intersect(point));
        assertTrue(point.intersect(circle));
        assertTrue(circle.intersect(circle));
    }
}
 
Example 40
Project: titan0.5.4-hbase1.1.1-custom   File: GeoshapeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testEquality() {
    Geoshape c = Geoshape.circle(10.0,12.5,100);
    Geoshape b = Geoshape.box(20.0, 22.5, 40.5, 60.5);
    assertEquals(Geoshape.circle(10.0,12.5,100),c);
    assertEquals(Geoshape.box(20.0,22.5,40.5,60.5),b);
    assertEquals(Geoshape.circle(10.0,12.5,100).hashCode(),c.hashCode());
    assertEquals(Geoshape.box(20.0,22.5,40.5,60.5).hashCode(),b.hashCode());
    assertNotSame(c.hashCode(),b.hashCode());
    assertNotSame(c,b);
    System.out.println(c);
    System.out.println(b);
}
 
Example 41
Project: titan0.5.4-hbase1.1.1-custom   File: GeoToWktConverter.java   Source Code and License 5 votes vote down vote up
/**
 * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0].
 * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0)
 */
public static String convertToWktString(Geoshape fieldValue) throws BackendException {
    if (fieldValue.getType() == Geoshape.Type.POINT) {
        Geoshape.Point point = fieldValue.getPoint();
        return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")";
    } else {
        throw new PermanentBackendException("Cannot index " + fieldValue.getType());
    }
}
 
Example 42
Project: incubator-blur   File: BlurIndex.java   Source Code and License 5 votes vote down vote up
@Override
public boolean supports(Class<?> dataType, Relation relation) {
  if (Number.class.isAssignableFrom(dataType)) {
    if (relation instanceof Cmp) {
      return true;
    }
  } else if (dataType == Geoshape.class) {
    return relation == Geo.INTERSECT;
  } else if (dataType == String.class) {
    return relation == Text.CONTAINS;
  }
  return false;
}
 
Example 43
Project: incubator-blur   File: BlurIndex.java   Source Code and License 5 votes vote down vote up
@Override
public boolean supports(Class<?> dataType) {
  if (Number.class.isAssignableFrom(dataType) || dataType == Geoshape.class || dataType == String.class) {
    return true;
  } else {
    return false;
  }
}
 
Example 44
Project: incubator-blur   File: BlurIndex.java   Source Code and License 5 votes vote down vote up
private String getValue(Object value) {
  if (value instanceof Number) {
    return value.toString();
  } else if (value instanceof String) {
    return (String) value;
  } else if (value instanceof Geoshape) {
    Shape shape = ((Geoshape) value).convert2Spatial4j();
    return shape.toString();
  }
  throw new IllegalArgumentException("Unsupported type: " + value);
}
 
Example 45
Project: titan1withtp3.1   File: LuceneExample.java   Source Code and License 4 votes vote down vote up
@Test
    public void example1() throws Exception {
        Directory dir = FSDirectory.open(path);
        Analyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_4, analyzer);

        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        IndexWriter writer = new IndexWriter(dir, iwc);

        indexDocs(writer, "doc1", ImmutableMap.of("name","The laborious work of John Doe as we know it",
                                                  "city","Blumenkamp",
                                                  "location",Geoshape.point(51.687882,6.612053),
                                                  "time",1000342034
                ));

        indexDocs(writer, "doc2", ImmutableMap.of("name","Life as we know it or not",
                "city","Essen",
                "location",Geoshape.point(51.787882,6.712053),
                "time",1000342034-500
        ));

        indexDocs(writer, "doc3", ImmutableMap.of("name","Berlin - poor but sexy and a display of the extraordinary",
                "city","Berlin",
                "location",Geoshape.circle(52.509535, 13.425293, 50),
                "time",1000342034+2000
        ));
        writer.close();

        //Search
        IndexReader reader = DirectoryReader.open(FSDirectory.open(path));
        IndexSearcher searcher = new IndexSearcher(reader);
        analyzer = new StandardAnalyzer();

        //Auesee
        BooleanFilter filter = new BooleanFilter();
        //filter.add(new TermsFilter(new Term("name_txt","know")), BooleanClause.Occur.MUST);

        SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,Geoshape.circle(51.666167,6.58905,450).convert2Spatial4j());
        //filter.add(getSpatialStrategy("location").makeFilter(args), BooleanClause.Occur.MUST);

        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034,(long)1000342034,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034-100,Long.MAX_VALUE,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",Long.MIN_VALUE,(long)1000342034+300,true,true), BooleanClause.Occur.MUST);


        filter.add(new PrefixFilter(new Term("city_str","B")), BooleanClause.Occur.MUST);


        TopDocs docs = searcher.search(new MatchAllDocsQuery(), filter, MAX_RESULT);
        if (docs.totalHits>=MAX_RESULT) throw new RuntimeException("Max results exceeded: " + MAX_RESULT);

        Set<String> result = getResults(searcher,docs);
        System.out.println(result);

    }
 
Example 46
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 4 votes vote down vote up
private void testCollection(Cardinality cardinality, String property, Object value1, Object value2) {
    clopen();

    Vertex v1 = graph.addVertex();

    //Adding properties one at a time
    v1.property(property, value1);
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));

    v1 = getV(graph, v1.id());
    v1.property(property, value2);

    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //Remove the properties
    v1 = getV(graph, v1.id());
    v1.properties(property).forEachRemaining(p -> {
        if (p.value().equals(value1)) {
            p.remove();
        }
    });

    assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext());
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext());

    //Re add the properties
    v1 = getV(graph, v1.id());
    v1.property(property, value1);
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //Add a duplicate property
    v1 = getV(graph, v1.id());
    v1.property(property, value1);


    assertEquals(Cardinality.SET.equals(cardinality) ? 2 : 3, Iterators.size(getOnlyVertex(graph.query().has(property, value1)).properties(property)));
    clopen();//Flush the index
    assertEquals(Cardinality.SET.equals(cardinality) ? 2 : 3, Iterators.size(getOnlyVertex(graph.query().has(property, value1)).properties(property)));


    //Add two properties at once to a fresh vertex
    graph.vertices().forEachRemaining(v -> v.remove());
    v1 = graph.addVertex();
    v1.property(property, value1);
    v1.property(property, value2);

    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //If this is a geo test then try a within query
    if (value1 instanceof Geoshape) {
        assertEquals(v1, getOnlyElement(graph.query().has(property, Geo.WITHIN, Geoshape.circle(1.0, 1.0, 0.1)).vertices()));
        assertEquals(v1, getOnlyElement(graph.query().has(property, Geo.WITHIN, Geoshape.circle(2.0, 2.0, 0.1)).vertices()));
    }


}
 
Example 47
Project: titan1withtp3.1   File: GeoshapeTest.java   Source Code and License 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testFailParseCollection() {
    Geoshape.GeoshapeSerializer serializer = new Geoshape.GeoshapeSerializer();
    serializer.convert(Arrays.asList(10, "Foo"));
}
 
Example 48
Project: titan1withtp3.1   File: TitanGraphSONModule.java   Source Code and License 4 votes vote down vote up
private TitanGraphSONModule() {
    addSerializer(RelationIdentifier.class, new RelationIdentifierSerializer());
    addSerializer(Geoshape.class, new Geoshape.GeoshapeGsonSerializer());

    addDeserializer(RelationIdentifier.class, new RelationIdentifierDeserializer());
}
 
Example 49
Project: titan1withtp3.1   File: SolrIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testSupport() {
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT))));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING))));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING))));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT))));

    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT))));
    assertTrue(index.supports(of(Integer.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Short.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Byte.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Float.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Object.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Exception.class, Cardinality.SINGLE)));

    assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.CONTAINS_PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXTSTRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Text.CONTAINS));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING)), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)), Cmp.LESS_THAN));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.WITHIN));

    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE), Geo.INTERSECT));
    assertFalse(index.supports(of(Long.class, Cardinality.SINGLE), Text.CONTAINS));
    assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.DISJOINT));

    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
}
 
Example 50
Project: titan1.0.1.kafka   File: LuceneExample.java   Source Code and License 4 votes vote down vote up
@Test
    public void example1() throws Exception {
        Directory dir = FSDirectory.open(path);
        Analyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_4, analyzer);

        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        IndexWriter writer = new IndexWriter(dir, iwc);

        indexDocs(writer, "doc1", ImmutableMap.of("name","The laborious work of John Doe as we know it",
                                                  "city","Blumenkamp",
                                                  "location",Geoshape.point(51.687882,6.612053),
                                                  "time",1000342034
                ));

        indexDocs(writer, "doc2", ImmutableMap.of("name","Life as we know it or not",
                "city","Essen",
                "location",Geoshape.point(51.787882,6.712053),
                "time",1000342034-500
        ));

        indexDocs(writer, "doc3", ImmutableMap.of("name","Berlin - poor but sexy and a display of the extraordinary",
                "city","Berlin",
                "location",Geoshape.circle(52.509535, 13.425293, 50),
                "time",1000342034+2000
        ));
        writer.close();

        //Search
        IndexReader reader = DirectoryReader.open(FSDirectory.open(path));
        IndexSearcher searcher = new IndexSearcher(reader);
        analyzer = new StandardAnalyzer();

        //Auesee
        BooleanFilter filter = new BooleanFilter();
        //filter.add(new TermsFilter(new Term("name_txt","know")), BooleanClause.Occur.MUST);

        SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,Geoshape.circle(51.666167,6.58905,450).convert2Spatial4j());
        //filter.add(getSpatialStrategy("location").makeFilter(args), BooleanClause.Occur.MUST);

        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034,(long)1000342034,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034-100,Long.MAX_VALUE,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",Long.MIN_VALUE,(long)1000342034+300,true,true), BooleanClause.Occur.MUST);


        filter.add(new PrefixFilter(new Term("city_str","B")), BooleanClause.Occur.MUST);


        TopDocs docs = searcher.search(new MatchAllDocsQuery(), filter, MAX_RESULT);
        if (docs.totalHits>=MAX_RESULT) throw new RuntimeException("Max results exceeded: " + MAX_RESULT);

        Set<String> result = getResults(searcher,docs);
        System.out.println(result);

    }
 
Example 51
Project: titan1.0.1.kafka   File: TitanIndexTest.java   Source Code and License 4 votes vote down vote up
private void testCollection(Cardinality cardinality, String property, Object value1, Object value2) {
    clopen();

    Vertex v1 = graph.addVertex();

    //Adding properties one at a time
    v1.property(property, value1);
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));

    v1 = getV(graph, v1.id());
    v1.property(property, value2);

    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //Remove the properties
    v1 = getV(graph, v1.id());
    v1.properties(property).forEachRemaining(p -> {
        if (p.value().equals(value1)) {
            p.remove();
        }
    });

    assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext());
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext());

    //Re add the properties
    v1 = getV(graph, v1.id());
    v1.property(property, value1);
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //Add a duplicate property
    v1 = getV(graph, v1.id());
    v1.property(property, value1);


    assertEquals(Cardinality.SET.equals(cardinality) ? 2 : 3, Iterators.size(getOnlyVertex(graph.query().has(property, value1)).properties(property)));
    clopen();//Flush the index
    assertEquals(Cardinality.SET.equals(cardinality) ? 2 : 3, Iterators.size(getOnlyVertex(graph.query().has(property, value1)).properties(property)));


    //Add two properties at once to a fresh vertex
    graph.vertices().forEachRemaining(v -> v.remove());
    v1 = graph.addVertex();
    v1.property(property, value1);
    v1.property(property, value2);

    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));
    clopen();//Flush the index
    assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
    assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices()));

    //If this is a geo test then try a within query
    if (value1 instanceof Geoshape) {
        assertEquals(v1, getOnlyElement(graph.query().has(property, Geo.WITHIN, Geoshape.circle(1.0, 1.0, 0.1)).vertices()));
        assertEquals(v1, getOnlyElement(graph.query().has(property, Geo.WITHIN, Geoshape.circle(2.0, 2.0, 0.1)).vertices()));
    }


}
 
Example 52
Project: titan1.0.1.kafka   File: GeoshapeTest.java   Source Code and License 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testFailParseCollection() {
    Geoshape.GeoshapeSerializer serializer = new Geoshape.GeoshapeSerializer();
    serializer.convert(Arrays.asList(10, "Foo"));
}
 
Example 53
Project: titan1.0.1.kafka   File: TitanGraphSONModule.java   Source Code and License 4 votes vote down vote up
private TitanGraphSONModule() {
    addSerializer(RelationIdentifier.class, new RelationIdentifierSerializer());
    addSerializer(Geoshape.class, new Geoshape.GeoshapeGsonSerializer());

    addDeserializer(RelationIdentifier.class, new RelationIdentifierDeserializer());
}
 
Example 54
Project: titan1.0.1.kafka   File: SolrIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testSupport() {
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT))));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING))));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING))));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT))));

    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT))));
    assertTrue(index.supports(of(Integer.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Short.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Byte.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Float.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Object.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Exception.class, Cardinality.SINGLE)));

    assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.CONTAINS_PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXTSTRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Text.CONTAINS));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING)), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)), Cmp.LESS_THAN));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.WITHIN));

    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE), Geo.INTERSECT));
    assertFalse(index.supports(of(Long.class, Cardinality.SINGLE), Text.CONTAINS));
    assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.DISJOINT));

    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
}
 
Example 55
Project: titan0.5.4-hbase1.1.1-custom   File: LuceneExample.java   Source Code and License 4 votes vote down vote up
@Test
    public void example1() throws Exception {
        Directory dir = FSDirectory.open(path);
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_41, analyzer);

        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        IndexWriter writer = new IndexWriter(dir, iwc);

        indexDocs(writer, "doc1", ImmutableMap.of("name","The laborious work of John Doe as we know it",
                                                  "city","Blumenkamp",
                                                  "location",Geoshape.point(51.687882,6.612053),
                                                  "time",1000342034
                ));

        indexDocs(writer, "doc2", ImmutableMap.of("name","Life as we know it or not",
                "city","Essen",
                "location",Geoshape.point(51.787882,6.712053),
                "time",1000342034-500
        ));

        indexDocs(writer, "doc3", ImmutableMap.of("name","Berlin - poor but sexy and a display of the extraordinary",
                "city","Berlin",
                "location",Geoshape.circle(52.509535, 13.425293, 50),
                "time",1000342034+2000
        ));
        writer.close();

        //Search
        IndexReader reader = DirectoryReader.open(FSDirectory.open(path));
        IndexSearcher searcher = new IndexSearcher(reader);
        analyzer = new StandardAnalyzer(Version.LUCENE_41);

        //Auesee
        BooleanFilter filter = new BooleanFilter();
        //filter.add(new TermsFilter(new Term("name_txt","know")), BooleanClause.Occur.MUST);

        SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,Geoshape.circle(51.666167,6.58905,450).convert2Spatial4j());
        //filter.add(getSpatialStrategy("location").makeFilter(args), BooleanClause.Occur.MUST);

        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034,(long)1000342034,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034-100,Long.MAX_VALUE,true,true), BooleanClause.Occur.MUST);
//        filter.add(NumericRangeFilter.newLongRange("time",Long.MIN_VALUE,(long)1000342034+300,true,true), BooleanClause.Occur.MUST);


        filter.add(new PrefixFilter(new Term("city_str","B")), BooleanClause.Occur.MUST);


        TopDocs docs = searcher.search(new MatchAllDocsQuery(), filter, MAX_RESULT);
        if (docs.totalHits>=MAX_RESULT) throw new RuntimeException("Max results exceeded: " + MAX_RESULT);

        Set<String> result = getResults(searcher,docs);
        System.out.println(result);

    }
 
Example 56
Project: titan0.5.4-hbase1.1.1-custom   File: SolrIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testSupport() {
    assertTrue(index.supports(of(String.class)));
    assertTrue(index.supports(of(String.class, new Parameter("mapping", Mapping.TEXT))));
    assertTrue(index.supports(of(String.class, new Parameter("mapping",Mapping.STRING))));
    assertFalse(index.supports(of(String.class, new Parameter("mapping",Mapping.TEXTSTRING))));

    assertTrue(index.supports(of(Double.class)));
    assertFalse(index.supports(of(Double.class, new Parameter("mapping",Mapping.TEXT))));

    assertTrue(index.supports(of(Long.class)));
    assertTrue(index.supports(of(Long.class, new Parameter("mapping",Mapping.DEFAULT))));
    assertTrue(index.supports(of(Integer.class)));
    assertTrue(index.supports(of(Short.class)));
    assertTrue(index.supports(of(Byte.class)));
    assertTrue(index.supports(of(Float.class)));
    assertTrue(index.supports(of(Geoshape.class)));
    assertFalse(index.supports(of(Object.class)));
    assertFalse(index.supports(of(Exception.class)));

    assertTrue(index.supports(of(String.class), Text.CONTAINS));
    assertTrue(index.supports(of(String.class, new Parameter("mapping", Mapping.DEFAULT)), Text.CONTAINS_PREFIX));
    assertTrue(index.supports(of(String.class, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX));
    assertFalse(index.supports(of(String.class, new Parameter("mapping", Mapping.TEXTSTRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, new Parameter("mapping",Mapping.TEXT)), Text.CONTAINS));
    assertFalse(index.supports(of(String.class, new Parameter("mapping", Mapping.DEFAULT)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, new Parameter("mapping", Mapping.STRING)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, new Parameter("mapping", Mapping.STRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL));
    assertTrue(index.supports(of(String.class, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL));
    assertFalse(index.supports(of(String.class, new Parameter("mapping",Mapping.TEXTSTRING)), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Double.class), Cmp.EQUAL));
    assertTrue(index.supports(of(Double.class), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Double.class), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Double.class, new Parameter("mapping",Mapping.DEFAULT)), Cmp.LESS_THAN));
    assertFalse(index.supports(of(Double.class, new Parameter("mapping",Mapping.TEXT)), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Geoshape.class), Geo.WITHIN));

    assertFalse(index.supports(of(Double.class), Geo.INTERSECT));
    assertFalse(index.supports(of(Long.class), Text.CONTAINS));
    assertFalse(index.supports(of(Geoshape.class), Geo.DISJOINT));
}