Source:
<code>public RelationType findOrCreateRelationType(Node predicate) { final GraphTraversal<Vertex, Vertex> relationTypeT = graphWrapper.getGraph().traversal().V().hasLabel("relationtype").has(RDF_URI_PROP, predicate.getURI()); if (relationTypeT.hasNext()) { return new RelationType(relationTypeT.next()); } else { <START> final GraphTraversal<Vertex, Vertex> inverseTypes = graphWrapper <END> .getGraph().traversal().V() .hasLabel("relationtype") .has(RDF_SYNONYM_PROP); while (inverseTypes.hasNext()) { final Vertex relationTypeV = inverseTypes.next(); final ArrayList<String> synonyms = Lists.newArrayList( relationTypeV.<String[]>property(RDF_SYNONYM_PROP).value()); if (synonyms.contains(predicate.getURI())) { return new RelationType(relationTypeV, true); } } } final String relationTypePrefix = "relationtype_"; final Vertex relationTypeVertex = graphWrapper.getGraph().addVertex("relationtype"); relationTypeVertex.property(RDF_URI_PROP, predicate.getURI()); relationTypeVertex.property("types", "[\"relationtype\"]"); relationTypeVertex.property(relationTypePrefix + "targetTypeName", "concept"); relationTypeVertex.property(relationTypePrefix + "sourceTypeName", "concept"); relationTypeVertex.property(relationTypePrefix + "symmetric", false); relationTypeVertex.property(relationTypePrefix + "reflexive", false); relationTypeVertex.property(relationTypePrefix + "derived", false); relationTypeVertex.property(relationTypePrefix + "regularName", predicate.getLocalName()); relationTypeVertex.property(relationTypePrefix + "inverseName", "inverse:" + predicate.getLocalName()); systemPropertyModifier.setTimId(relationTypeVertex); systemPropertyModifier.setCreated(relationTypeVertex, "rdf-importer"); systemPropertyModifier.setModified(relationTypeVertex, "rdf-importer"); systemPropertyModifier.setIsLatest(relationTypeVertex, true); systemPropertyModifier.setRev(relationTypeVertex, 1); return new RelationType(relationTypeVertex); }</code><technical_language>rdfuri index for this, this is slow I guess happen a lot</technical_language>

Target:
public RelationType findOrCreateRelationType(Node predicate) { final Optional<Vertex> relationTypeV = findVertexInRdfIndex(RelationTypeService.RELATIONTYPE_INDEX_NAME, predicate.getURI()); if (relationTypeV.isPresent()) { final Vertex relationTypeVertex = relationTypeV.get(); boolean isInverse = relationTypeVertex.<String>property("relationtype_inverseName") .value().equals(predicate.getLocalName()); return new RelationType(relationTypeVertex, isInverse); } final String relationTypePrefix = "relationtype_"; final Vertex relationTypeVertex = graphWrapper.getGraph().addVertex("relationtype"); relationTypeVertex.property(RDF_URI_PROP, predicate.getURI()); relationTypeVertex.property("types", "[\"relationtype\"]"); relationTypeVertex.property(relationTypePrefix + "targetTypeName", "concept"); relationTypeVertex.property(relationTypePrefix + "sourceTypeName", "concept"); relationTypeVertex.property(relationTypePrefix + "symmetric", false); relationTypeVertex.property(relationTypePrefix + "reflexive", false); relationTypeVertex.property(relationTypePrefix + "derived", false); relationTypeVertex.property(relationTypePrefix + "regularName", predicate.getLocalName()); relationTypeVertex.property(relationTypePrefix + "inverseName", "inverse:" + predicate.getLocalName()); systemPropertyModifier.setTimId(relationTypeVertex); systemPropertyModifier.setCreated(relationTypeVertex, "rdf-importer"); systemPropertyModifier.setModified(relationTypeVertex, "rdf-importer"); systemPropertyModifier.setIsLatest(relationTypeVertex, true); systemPropertyModifier.setRev(relationTypeVertex, 1); return new RelationType(relationTypeVertex); }