Java Code Examples for org.neo4j.graphdb.Label#label()

The following examples show how to use org.neo4j.graphdb.Label#label() . 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: Neo4jModule.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
public static void setupSchemaIndexes(GraphDatabaseService graphDb, Neo4jConfiguration config) {
  Map<String, Set<String>> schemaIndexes = config.getSchemaIndexes();
  for (Map.Entry<String, Set<String>> entry : schemaIndexes.entrySet()) {
    Label label = Label.label(entry.getKey());
    for (String property : entry.getValue()) {
      try (Transaction tx = graphDb.beginTx()) {
        Schema schema = graphDb.schema();
        IndexDefinition indexDefinition = schema.indexFor(label).on(property).create();
        tx.success();
        tx.close();

        Transaction tx2 = graphDb.beginTx();
        schema.awaitIndexOnline(indexDefinition, 2, TimeUnit.MINUTES);
        tx2.success();
        tx2.close();
      }
    }
  }
}
 
Example 2
Source File: GraphApi.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
public Optional<Node> getNode(String id, Optional<String> lblHint) {
  String iriResolved = curieUtil.getIri(id).orElse(id);
  Optional<Node> node = Optional.empty();
  if (lblHint.isPresent()) {
    Label hintLabel = Label.label(lblHint.get());
    Node hit = graphDb.findNode(hintLabel, NodeProperties.IRI, iriResolved);
    if (hit != null) {
      node = Optional.of(hit);
    }
  } else {
    String startQuery =
        "MATCH (n {" + NodeProperties.IRI + ": \"" + iriResolved + "\"}) RETURN n";
    Result res = cypherUtil.execute(startQuery);
    if (res.hasNext()) {
      node = Optional.of((Node) res.next().get("n"));
    }
  }

  return node;
}
 
Example 3
Source File: CategoryLabeler.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean call() throws Exception {
  Label label = Label.label(category);
  try (Transaction tx = graphDb.beginTx()) {
    for (Long id : ids) {
      Node node = graphDb.getNodeById(id);
      GraphUtil.addProperty(node, Concept.CATEGORY, category);
      node.addLabel(label);
    }
    tx.success();
    tx.close();
  }
  return true;
}
 
Example 4
Source File: TinkerGraphUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void labelsAreTranslated() {
  Label label = Label.label("label");
  when(node.getLabels()).thenReturn(newHashSet(label));
  TinkerGraphUtil tgu = new TinkerGraphUtil(curieUtil);
  Vertex v = tgu.addNode(node);
  assertThat((Iterable<String>)v.getProperty("types"), IsIterableContainingInAnyOrder.containsInAnyOrder("label"));
}
 
Example 5
Source File: DL4JMLModel.java    From neo4j-ml-procedures with Apache License 2.0 4 votes vote down vote up
private Node node(String label, Object...keyValues) {
    return new VirtualNode(new Label[] {Label.label(label)}, MapUtil.map(keyValues),null);
}
 
Example 6
Source File: AllNodesLabeler.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Inject
public AllNodesLabeler(String label, GraphDatabaseService graphDb) {
  this.label = Label.label(label);
  this.graphDb = graphDb;
}
 
Example 7
Source File: EmbeddedLabel.java    From extended-objects with Apache License 2.0 4 votes vote down vote up
public EmbeddedLabel(String name) {
    this(Label.label(name));
}