Java Code Examples for org.apache.tinkerpop.gremlin.structure.VertexProperty#isPresent()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.VertexProperty#isPresent() . 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: AltNameFacetDescription.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> getValues(Vertex vertex) {
  List<String> values = Lists.newArrayList();
  VertexProperty<String> property = vertex.property(propertyName);
  if (property.isPresent()) {
    String value = property.value();
    try {
      AltNames altNames = objectMapper.readValue(value, AltNames.class);

      altNames.list.forEach(altName -> values.add(altName.getDisplayName()));
    } catch (IOException e) {
      LOG.error("Could not convert '{}'", value);
      LOG.error("Exception throw.", e);
    }
  }

  return values;
}
 
Example 2
Source File: GraphOMRSClassificationMapper.java    From egeria with Apache License 2.0 5 votes vote down vote up
private Object getVertexProperty(Vertex vertex, String propName)
{
    VertexProperty vp = vertex.property(propName);
    if (vp == null || !vp.isPresent())
        return null;
    else
        return vp.value();
}
 
Example 3
Source File: GraphOMRSEntityMapper.java    From egeria with Apache License 2.0 5 votes vote down vote up
private Object getVertexProperty(Vertex vertex, String propName)
{
    VertexProperty vp = vertex.property(propName);
    if (vp == null || !vp.isPresent())
        return null;
    else
        return vp.value();
}
 
Example 4
Source File: PostProcessManager.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void processItem(Object vertexId) {
    batchCounter++;
    counter++;

    try {
        Vertex         vertex           = bulkLoadGraph.traversal().V(vertexId).next();
        boolean        isTypeVertex     = vertex.property(TYPENAME_PROPERTY_KEY).isPresent();
        VertexProperty typeNameProperty = vertex.property(ENTITY_TYPE_PROPERTY_KEY);

        if (!isTypeVertex && typeNameProperty.isPresent()) {
            String typeName = (String) typeNameProperty.value();
            if (!typePropertiesMap.containsKey(typeName)) {
                return;
            }

            Map<String, List<String>> collectionTypeProperties = typePropertiesMap.get(typeName);
            for (String key : nonPrimitiveCategoryKeys) {
                if (!collectionTypeProperties.containsKey(key)) {
                    continue;
                }

                for(String propertyName : collectionTypeProperties.get(key)) {
                    processor.process(vertex, typeName, propertyName);
                }
            }
        }

        commitBatch();
    } catch (Exception ex) {
        LOG.error("processItem: v[{}] error!", vertexId, ex);
    }
}
 
Example 5
Source File: BitsyVertex.java    From bitsy with Apache License 2.0 5 votes vote down vote up
@Override
public <V> Iterator<VertexProperty<V>> properties(String... propertyKeys) {
       ArrayList<VertexProperty<V>> ans = new ArrayList<VertexProperty<V>>();

       if (propertyKeys.length == 0) {
       	if (this.properties == null) return Collections.emptyIterator();
       	propertyKeys = this.properties.getPropertyKeys();
       }

       for (String key : propertyKeys) {
       	VertexProperty<V> prop = property(key);
           if (prop.isPresent()) ans.add(prop);
       }
       return ans.iterator();
}
 
Example 6
Source File: ShortestDistanceVertexProgram.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) {
    if (memory.isInitialIteration()) {
        if (vertex.id().equals(Long.valueOf(seed).longValue())) {
            // The seed sends a single message to start the computation
            log.debug("Sent initial message from {}", vertex.id());
            // The seed's distance to itself is zero
            vertex.property(VertexProperty.Cardinality.single, DISTANCE, 0L);
            messenger.sendMessage(incidentMessageScope, 0L);
        }
    } else {
        Iterator<Long> distances = messenger.receiveMessages();

        // Find minimum distance among all incoming messages, or null if no messages came in
        Long shortestDistanceSeenOnThisIteration =
                IteratorUtils.stream(distances).reduce((a, b) -> Math.min(a, b)).orElse(null);

        if (null == shortestDistanceSeenOnThisIteration)
            return; // no messages to process or forward on this superstep

        VertexProperty<Long> currentShortestVP = vertex.property(DISTANCE);

        if (!currentShortestVP.isPresent() ||
                currentShortestVP.value() > shortestDistanceSeenOnThisIteration) {
            // First/shortest distance seen by this vertex: store it and forward to neighbors
            vertex.property(VertexProperty.Cardinality.single, DISTANCE, shortestDistanceSeenOnThisIteration);
            messenger.sendMessage(incidentMessageScope, shortestDistanceSeenOnThisIteration);
        }
        // else: no new winner, ergo no reason to send message to neighbors
    }
}
 
Example 7
Source File: HadoopVertex.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public <V> VertexProperty<V> property(final String key) {
    final VertexProperty<V> vertexProperty = getBaseVertex().<V>property(key);
    return vertexProperty.isPresent() ?
            new HadoopVertexProperty<>((VertexProperty<V>) ((Vertex) this.baseElement).property(key), this) :
            VertexProperty.<V>empty();
}
 
Example 8
Source File: ShortestPathVertexProgram.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Move any valid path into the VP's memory.
 * @param vertex The current vertex.
 * @param memory The VertexProgram's memory.
 */
private void collectShortestPaths(final Vertex vertex, final Memory memory) {

    final VertexProperty<Map<Vertex, Pair<Number, Set<Path>>>> pathProperty = vertex.property(PATHS);

    if (pathProperty.isPresent()) {

        final Map<Vertex, Pair<Number, Set<Path>>> paths = pathProperty.value();
        final List<Path> result = new ArrayList<>();

        for (final Pair<Number, Set<Path>> pair : paths.values()) {
            for (final Path path : pair.getValue1()) {
                if (isEndVertex(vertex)) {
                    if (this.distanceEqualsNumberOfHops ||
                            this.maxDistance == null ||
                            NumberHelper.compare(pair.getValue0(), this.maxDistance) <= 0) {
                        result.add(path);
                    }
                }
            }
        }

        pathProperty.remove();

        memory.add(SHORTEST_PATHS, result);
    }
}
 
Example 9
Source File: AbstractLabel.java    From sqlg with MIT License 5 votes vote down vote up
Partition addPartition(Vertex partitionVertex) {
    Preconditions.checkState(this.getSchema().getTopology().isSqlWriteLockHeldByCurrentThread());
    VertexProperty<String> from = partitionVertex.property(SQLG_SCHEMA_PARTITION_FROM);
    VertexProperty<String> to = partitionVertex.property(SQLG_SCHEMA_PARTITION_TO);
    VertexProperty<String> in = partitionVertex.property(SQLG_SCHEMA_PARTITION_IN);
    VertexProperty<String> partitionType = partitionVertex.property(SQLG_SCHEMA_PARTITION_PARTITION_TYPE);
    VertexProperty<String> partitionExpression = partitionVertex.property(SQLG_SCHEMA_PARTITION_PARTITION_EXPRESSION);
    Partition partition;
    if (from.isPresent()) {
        Preconditions.checkState(to.isPresent());
        Preconditions.checkState(!in.isPresent());
        partition = new Partition(
                this.sqlgGraph,
                this,
                partitionVertex.value(SQLG_SCHEMA_PARTITION_NAME),
                from.value(),
                to.value(),
                PartitionType.from(partitionType.<String>value()),
                partitionExpression.isPresent() ? partitionExpression.<String>value() : null);
    } else {
        Preconditions.checkState(in.isPresent());
        Preconditions.checkState(!to.isPresent());
        partition = new Partition(
                this.sqlgGraph,
                this,
                partitionVertex.value(SQLG_SCHEMA_PARTITION_NAME),
                in.value(),
                PartitionType.from(partitionType.<String>value()),
                partitionExpression.isPresent() ? partitionExpression.<String>value() : null);
    }
    this.partitions.put(partitionVertex.value(SQLG_SCHEMA_PARTITION_NAME), partition);
    return partition;
}
 
Example 10
Source File: CharterPortaalFondsFacetDescription.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> getValues(Vertex vertex) {
  VertexProperty<String> fondsNaamProp = vertex.property(FONDS_NAAM);
  String fondsNaam = fondsNaamProp.isPresent() ? fondsNaamProp.value() : "";

  VertexProperty<String> fondsProp = vertex.property(FONDS);
  String fonds = fondsNaamProp.isPresent() ? fondsProp.value() : "";

  return Lists.newArrayList(createFacetValue(fondsNaam, fonds));

}
 
Example 11
Source File: SourceFileModel.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Contains a boolean indicating that the reporting system should generate a source report for this {@link SourceFileModel}.
 */
default boolean isGenerateSourceReport()
{
    VertexProperty result = getElement().property(GENERATE_SOURCE_REPORT);
    if (!result.isPresent())
        return false;
    return (Boolean)result.value();
}
 
Example 12
Source File: HaltedTraversersCountTraversal.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void addStart(final Traverser.Admin<Vertex> start) {
    final VertexProperty<TraverserSet<Object>> property = start.get().<TraverserSet<Object>>property(TraversalVertexProgram.HALTED_TRAVERSERS);
    this.count = property.isPresent() ? property.value().bulkSize() : 0l;
}
 
Example 13
Source File: TinkerPopToEntityMapper.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
private UUID getIdOrDefault(Vertex entityVertex) {
  VertexProperty<String> idProperty = entityVertex.property("tim_id");
  return idProperty.isPresent() ? UUID.fromString(entityVertex.value("tim_id")) : DEFAULT_ID;
}