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

The following examples show how to use com.thinkaurelius.titan.core.attribute.Geoshape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #3
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #4
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #5
Source File: GeoToWktConverterTest.java    From titan1withtp3.1 with Apache License 2.0 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 #6
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #7
Source File: BlurIndex.java    From incubator-retired-blur with Apache License 2.0 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 #8
Source File: BlurIndex.java    From incubator-retired-blur with Apache License 2.0 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 #9
Source File: BlurIndex.java    From incubator-retired-blur with Apache License 2.0 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 #10
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #11
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #12
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #13
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #14
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #15
Source File: GeoToWktConverter.java    From titan1withtp3.1 with Apache License 2.0 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 #16
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #17
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #18
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #19
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #20
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #21
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #22
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #23
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #24
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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 #25
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) {

        //Create Schema
        TitanManagement mgmt = graph.openManagement();
        final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
        TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name);
        if (uniqueNameCompositeIndex)
            nameIndexBuilder.unique();
        TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex();
        mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
        final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName);

        final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
        final PropertyKey reason = mgmt.makePropertyKey("reason").dataType(String.class).make();
        final PropertyKey place = mgmt.makePropertyKey("place").dataType(Geoshape.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName);

        mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
        mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make();
        EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make();
        mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
        mgmt.makeEdgeLabel("lives").signature(reason).make();
        mgmt.makeEdgeLabel("pet").make();
        mgmt.makeEdgeLabel("brother").make();

        mgmt.makeVertexLabel("titan").make();
        mgmt.makeVertexLabel("location").make();
        mgmt.makeVertexLabel("god").make();
        mgmt.makeVertexLabel("demigod").make();
        mgmt.makeVertexLabel("human").make();
        mgmt.makeVertexLabel("monster").make();

        mgmt.commit();

        TitanTransaction tx = graph.newTransaction();
        // vertices

        Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 10000);

        Vertex sky = tx.addVertex(T.label, "location", "name", "sky");

        Vertex sea = tx.addVertex(T.label, "location", "name", "sea");

        Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000);

        Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500);

        Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30);

        Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45);

        Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000);

        Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean");

        Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra");

        Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus");

        Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus");

        // edges

        jupiter.addEdge("father", saturn);
        jupiter.addEdge("lives", sky, "reason", "loves fresh breezes");
        jupiter.addEdge("brother", neptune);
        jupiter.addEdge("brother", pluto);

        neptune.addEdge("lives", sea).property("reason", "loves waves");
        neptune.addEdge("brother", jupiter);
        neptune.addEdge("brother", pluto);

        hercules.addEdge("father", jupiter);
        hercules.addEdge("mother", alcmene);
        hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f));
        hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f));
        hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f));

        pluto.addEdge("brother", jupiter);
        pluto.addEdge("brother", neptune);
        pluto.addEdge("lives", tartarus, "reason", "no fear of death");
        pluto.addEdge("pet", cerberus);

        cerberus.addEdge("lives", tartarus);

        // commit the transaction to disk
        tx.commit();
    }
 
Example #26
Source File: TitanGraphSONModule.java    From titan1withtp3.1 with Apache License 2.0 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 #27
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #28
Source File: SolrIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #29
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 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"));
}