use of org.neo4j.driver.v1.Value in project neo4j-apoc-procedures by neo4j-contrib.
the class Bolt method toRelationship.
private Object toRelationship(Object value, boolean virtual, Map<Long, Object> nodesCache) {
Value internalValue = ((InternalEntity) value).asValue();
Relationship relationship = internalValue.asRelationship();
if (virtual) {
VirtualNode start = (VirtualNode) nodesCache.getOrDefault(relationship.startNodeId(), new VirtualNode(relationship.startNodeId(), db));
VirtualNode end = (VirtualNode) nodesCache.getOrDefault(relationship.endNodeId(), new VirtualNode(relationship.endNodeId(), db));
VirtualRelationship virtualRelationship = new VirtualRelationship(relationship.id(), start, end, RelationshipType.withName(relationship.type()), relationship.asMap());
return virtualRelationship;
} else
return Util.map("entityType", internalValue.type().name(), "type", relationship.type(), "id", relationship.id(), "start", relationship.startNodeId(), "end", relationship.endNodeId(), "properties", relationship.asMap());
}
use of org.neo4j.driver.v1.Value in project structr by structr.
the class SessionTransaction method getStrings.
public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
final long t0 = System.currentTimeMillis();
try {
final StatementResult result = tx.run(statement, map);
final Record record = result.next();
final Value value = record.get(0);
return new QueryResult<String>() {
@Override
public void close() {
result.consume();
}
@Override
public Iterator<String> iterator() {
return value.asList(Values.ofString()).iterator();
}
};
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} finally {
logQuery(statement, map, t0);
}
}
use of org.neo4j.driver.v1.Value in project xtext-core by eclipse.
the class ActionTestLanguage2SemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == ActionLang2Package.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case ActionLang2Package.ORING:
sequence_ORing(context, (ORing) semanticObject);
return;
case ActionLang2Package.VALUE:
sequence_Value(context, (Value) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.neo4j.driver.v1.Value in project java-docs-samples by GoogleCloudPlatform.
the class RiskAnalysis method numericalStatsAnalysis.
// [START dlp_numerical_stats]
/**
* Calculate numerical statistics for a column in a BigQuery table using the DLP API.
*
* @param projectId The Google Cloud Platform project ID to run the API call under.
* @param datasetId The BigQuery dataset to analyze.
* @param tableId The BigQuery table to analyze.
* @param columnName The name of the column to analyze, which must contain only numerical data.
* @param topicId The name of the Pub/Sub topic to notify once the job completes
* @param subscriptionId The name of the Pub/Sub subscription to use when listening for job
* completion status.
*/
private static void numericalStatsAnalysis(String projectId, String datasetId, String tableId, String columnName, String topicId, String subscriptionId) throws Exception {
// Instantiates a client
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
BigQueryTable bigQueryTable = BigQueryTable.newBuilder().setTableId(tableId).setDatasetId(datasetId).setProjectId(projectId).build();
FieldId fieldId = FieldId.newBuilder().setName(columnName).build();
NumericalStatsConfig numericalStatsConfig = NumericalStatsConfig.newBuilder().setField(fieldId).build();
PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().setNumericalStatsConfig(numericalStatsConfig).build();
String topicName = String.format("projects/%s/topics/%s", projectId, topicId);
PublishToPubSub publishToPubSub = PublishToPubSub.newBuilder().setTopic(topicName).build();
// Create action to publish job status notifications over Google Cloud Pub/Sub
Action action = Action.newBuilder().setPubSub(publishToPubSub).build();
RiskAnalysisJobConfig riskAnalysisJobConfig = RiskAnalysisJobConfig.newBuilder().setSourceTable(bigQueryTable).setPrivacyMetric(privacyMetric).addActions(action).build();
CreateDlpJobRequest createDlpJobRequest = CreateDlpJobRequest.newBuilder().setParent(ProjectName.of(projectId).toString()).setRiskJob(riskAnalysisJobConfig).build();
DlpJob dlpJob = dlpServiceClient.createDlpJob(createDlpJobRequest);
String dlpJobName = dlpJob.getName();
final SettableApiFuture<Boolean> done = SettableApiFuture.create();
// Set up a Pub/Sub subscriber to listen on the job completion status
Subscriber subscriber = Subscriber.newBuilder(ProjectSubscriptionName.newBuilder().setProject(projectId).setSubscription(subscriptionId).build(), (pubsubMessage, ackReplyConsumer) -> {
if (pubsubMessage.getAttributesCount() > 0 && pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) {
// notify job completion
done.set(true);
ackReplyConsumer.ack();
}
}).build();
subscriber.startAsync();
// For long jobs, consider using a truly asynchronous execution model such as Cloud Functions
try {
done.get(1, TimeUnit.MINUTES);
// Wait for the job to become available
Thread.sleep(500);
} catch (TimeoutException e) {
System.out.println("Unable to verify job completion.");
}
// Retrieve completed job status
DlpJob completedJob = dlpServiceClient.getDlpJob(GetDlpJobRequest.newBuilder().setName(dlpJobName).build());
System.out.println("Job status: " + completedJob.getState());
AnalyzeDataSourceRiskDetails riskDetails = completedJob.getRiskDetails();
AnalyzeDataSourceRiskDetails.NumericalStatsResult result = riskDetails.getNumericalStatsResult();
System.out.printf("Value range : [%.3f, %.3f]\n", result.getMinValue().getFloatValue(), result.getMaxValue().getFloatValue());
int percent = 1;
Double lastValue = null;
for (Value quantileValue : result.getQuantileValuesList()) {
Double currentValue = quantileValue.getFloatValue();
if (lastValue == null || !lastValue.equals(currentValue)) {
System.out.printf("Value at %s %% quantile : %.3f", percent, currentValue);
}
lastValue = currentValue;
}
} catch (Exception e) {
System.out.println("Error in categoricalStatsAnalysis: " + e.getMessage());
}
}
use of org.neo4j.driver.v1.Value in project rdf2neo by Rothamsted.
the class CypherHandlersIT method testRelations.
/**
* Tests {@link CyRelationLoadingHandler} to see if relations are mapped from RDF and loaded into Neo4J.
*/
@Test
public void testRelations() throws Exception {
try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
CyRelationLoadingHandler handler = new CyRelationLoadingHandler();
RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver)) {
handler.setRdfDataManager(rdfMgr);
handler.setNeo4jDataManager(neoMgr);
handler.setRelationTypesSparql(RdfDataManagerTest.SPARQL_REL_TYPES);
handler.setRelationPropsSparql(RdfDataManagerTest.SPARQL_REL_PROPS);
Set<QuerySolution> relSparqlRows = new HashSet<>();
Dataset dataSet = rdfMgr.getDataSet();
Txn.executeRead(dataSet, () -> SparqlUtils.select(RdfDataManagerTest.SPARQL_REL_TYPES, rdfMgr.getDataSet().getDefaultModel()).forEachRemaining(row -> relSparqlRows.add(row)));
handler.accept(relSparqlRows);
Session session = neoDriver.session(AccessMode.READ);
StatementResult cursor = session.run("MATCH ()-[r]->() RETURN COUNT ( r ) AS ct");
Assert.assertEquals("Wrong count for relations", 3, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:TestNode{ iri:$iri1 })-[:relatedTo]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:1"), "iri2", iri("ex:2")));
Assert.assertEquals("Wrong count for {1 relatedTo 2}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:SuperTestNode{ iri:$iri1 })-[:derivedFrom]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:3"), "iri2", iri("ex:1")));
Assert.assertEquals("Wrong count for {3 derivedFrom 1}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH (:TestNode{ iri:$iri1 })-[r:relatedTo]->(:AdditionalLabel{ iri:$iri2 }) RETURN r.note AS note", parameters("iri1", iri("ex:2"), "iri2", iri("ex:3")));
assertTrue("{2 relatedTo 3} not found!", cursor.hasNext());
Set<String> values = cursor.next().get("note").asList().stream().map(v -> (String) v).collect(Collectors.toSet());
Set<String> refValues = new HashSet<>(Arrays.asList(new String[] { "Reified Relation", "Another Note" }));
assertTrue("reified relation, wrong property value for 'note'!", Sets.difference(values, refValues).isEmpty());
}
}
Aggregations