Java 类org.neo4j.graphdb.DynamicLabel 实例源码

项目:neo4j-talend-component    文件:Neo4jBatchInserterNode.java   
protected Label[] computeLabels(Object incoming) throws IllegalAccessException {
    Label[] labels = new Label[0];

    if (StringUtils.isNotEmpty(this.labelsField)) {

        String labelList = (String) this.getObjectProperty(incoming, this.labelsField);

        if (StringUtils.isNotEmpty(labelList)) {
            String[] labelTab = labelList.split(";");
            labels = new Label[labelTab.length];
            for (int i = 0; i < labelTab.length; i++) {
                labels[i] = DynamicLabel.label(labelTab[i]);
            }
        }
    }

    return labels;
}
项目:neo4j-talend-component    文件:Neo4jBatchDatabaseTest.java   
@Test
public void create_node_uniqueness_constraint_should_work() {
    // Test const.
    String label = "Test";
    String property = "myProp";

    // crete the schema
    batchDb.createSchema("NODE_PROPERTY_UNIQUE", label, property);
    batchDb.shutdown();

    // Testing it with real graphdb
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
    try (Transaction tx = graphDb.beginTx()) {
        Assert.assertTrue(graphDb.schema().getConstraints(DynamicLabel.label(label)).iterator().hasNext());
    }
    graphDb.shutdown();
}
项目:neo4j-talend-component    文件:Neo4jBatchDatabaseTest.java   
@Test
public void create_node_index_should_work() {
    // Test const.
    String label = "Test";
    String property = "myProp";

    // crete the schema
    batchDb.createSchema("NODE_PROPERTY_INDEX", label, property);
    batchDb.shutdown();

    // Testing it with real graphdb
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
    try (Transaction tx = graphDb.beginTx()) {
        Assert.assertTrue(graphDb.schema().getIndexes(DynamicLabel.label(label)).iterator().hasNext());
    }
    graphDb.shutdown();

}
项目:artificial-guy    文件:KnowledgeGraph.java   
private Node addNode(String token, String pos, String ner, String sentId) throws Exception {

        if (token == null || pos == null || ner == null) {
            throw new Exception("Invalid arguments");
        }

        // check for duplicate nodes
        Node node = getNode(token, pos, ner, sentId);
        if (node != null) {
            return node;
        }

        try (Transaction tx = graphDb.beginTx()) {
            // Database operations go here
            node = graphDb.createNode();
            node.setProperty("token", token);
            node.setProperty("pos", pos);
            node.setProperty("ner", ner);
            node.addLabel(DynamicLabel.label("S_" + sentId));

            // transaction complete
            tx.success();
        }

        return node;
    }
项目:NeoDD    文件:Problem.java   
public final Node add(Map<String, Object> properties, String... types) {
    if (null == properties)
        throw new IllegalArgumentException("Illegal 'properties' argument in Problem.add(Map<String, Object>, String...): " + properties);
    if (null == types)
        throw new IllegalArgumentException("Illegal 'types' argument in Problem.add(Map<String, Object>, String...): " + types);
    Node result = null;
    try (Transaction tx = graph.beginTx()) {
        int i = 0;
        Label[] labels = new Label[types.length];
        for (String type : types) {
            labels[i++] = DynamicLabel.label(type);
        }
        result = graph.createNode(labels);
        for (String property : properties.keySet())
            result.setProperty(property, properties.get(property));
        tx.success();
    }
    return result;
}
项目:neo4j-mazerunner    文件:PartitionedAnalysis.java   
public void analyzePartitions() {
    // Query the nodes by label, which each set becomes a partition for analysis
    Transaction tx = graphDatabaseService.beginTx();

    Iterator<Node> partitions = GlobalGraphOperations.at(graphDatabaseService)
            .getAllNodesWithLabel(DynamicLabel.label(label))
            .iterator();

    // For each partition, query the target relationships between the partition
    partitions.forEachRemaining(partition -> {
        PartitionDescription partitionDescription = new PartitionDescription(partition.getId(), label);
        partitionDescription.setGroupRelationship(groupRelationship);
        partitionDescription.setTargetRelationship(targetRelationship);
        try {
            Path pt = Writer.exportPartitionToHDFSParallel(graphDatabaseService, partition, partitionDescription);
            if(pt != null)
                Writer.dispatchPartitionedJob(graphDatabaseService, type, partitionDescription, pt);
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    });

    tx.success();
    tx.close();
}
项目:dswarm-graph-neo4j    文件:Neo4jDeltaGDMHandler.java   
private void addLabel(final Node node, final String labelString) {

        final Label label = DynamicLabel.label(labelString);
        boolean hit = false;
        final Iterable<Label> labels = node.getLabels();

        for (final Label lbl : labels) {

            if (label.equals(lbl)) {

                hit = true;
                break;
            }
        }

        if (!hit) {

            node.addLabel(label);
            addedLabels++;
        }
    }
项目:dswarm-graph-neo4j    文件:PropertyEnrichGDMWorker.java   
public PropertyEnrichGDMWorker(final String prefixedResourceUriArg, final long resourceHashArg, final GraphDatabaseService databaseArg, final
NamespaceIndex namespaceIndexArg) throws DMPGraphException {

    prefixedResourceUri = prefixedResourceUriArg;
    resourceHash = resourceHashArg;
    database = databaseArg;
    namespaceIndex = namespaceIndexArg;
    nodeHandler = new CBDNodeHandler();
    startNodeHandler = new CBDStartNodeHandler();
    relationshipHandler = new CBDRelationshipHandler();

    final String prefixedRDFTypeURI = namespaceIndex.createPrefixedURI(RDF.type.getURI());
    final String prefixedRDFSClassURI = namespaceIndex.createPrefixedURI(RDFS.Class.getURI());

    prefixedRDFType = DynamicRelationshipType.withName(prefixedRDFTypeURI);
    prefixedRDFSClass = DynamicLabel.label(prefixedRDFSClassURI);
}
项目:dgMaster-trunk    文件:EntityEventNodeNeo4j.java   
/**
 * used when creating nodes in batch mode
 * 
 * @param id
 * @param name
 * @param columnNames
 * @param values
 * @return
 * @throws IOException
 */
private long createVertexBatchMode(double id, String name, List<String> columnNames, List<String> values) throws IOException {
    Label entityLabel = DynamicLabel.label(name);
    //getCurrentInserter().createDeferredSchemaIndex(entityLabel).on(_ID_PROPERTY).create();

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(_ID_PROPERTY, id);

    // fill out the properties in the columns
    for (int i = 0; i < columnNames.size(); i++) {
        String value = EMPTY_STRING;
        if (values != null && values.size() > i) {
            value = values.get(i);
        }
        properties.put(columnNames.get(i), value);
    }

    return getCurrentInserter().createNode(properties, entityLabel);
}
项目:obelix    文件:NeoHelpers.java   
public static List<String> getAllNodes(final GraphDatabaseService graphDb,
                                       final String labelName) {

    List<String> nodeIds = new ArrayList<>();
    Label label = DynamicLabel.label(labelName);
    ResourceIterable<Node> nodes;

    try (Transaction tx = graphDb.beginTx()) {
        nodes = GlobalGraphOperations.at(graphDb).getAllNodesWithLabel(label);

        for (Node node : nodes) {
            try {
                nodeIds.add(node.getProperty("node_id").toString());
            } catch (Exception e) {
                LOGGER.warn("Can't find a given node... skipping");
            }
        }

        tx.success();
    }

    return nodeIds;

}
项目:obelix    文件:NeoHelpers.java   
public static Node getOrCreateUserNode(final GraphDatabaseService graphDb,
                                       final String userID) {

    IndexManager index = graphDb.index();
    Index<Node> usersIndex = index.forNodes("users");

    Node node = usersIndex.get("node_id", userID).getSingle();

    if (node == null) {
        node = graphDb.createNode(DynamicLabel.label("User"));
        node.setProperty("node_id", userID);
        usersIndex.add(node, "node_id", userID);
    }

    return node;

}
项目:obelix    文件:NeoHelpers.java   
public static Node getOrCreateItemNode(final GraphDatabaseService graphDb,
                                       final String itemID) {

    IndexManager index = graphDb.index();
    Index<Node> usersIndex = index.forNodes("items");

    Node node = usersIndex.get("node_id", itemID).getSingle();

    if (node == null) {
        node = graphDb.createNode(DynamicLabel.label("Item"));
        node.setProperty("node_id", itemID);
        usersIndex.add(node, "node_id", itemID);
    }

    return node;

}
项目:Oracle2Neo4j    文件:NeoDb.java   
private synchronized void createNode(String labelName, Map<String, Object> properties, BatchInserterIndex idx,
        String pk) {
    idx.add(this.inserter.createNode(properties, DynamicLabel.label(labelName)),
            MapUtil.map(pk, properties.get(pk)));
    long n = this.counter.get(labelName);
    this.counter.put(labelName, ++n);
    if(n % this.flushInterval == 0)
        idx.flush();
}
项目:neo4j-talend-component    文件:Neo4jBatchDatabase.java   
/**
 * Create schema.
 *
 * @param type     Type of schema to create (ie. constraint or index on node property)
 * @param label    Node label
 * @param property Node property
 */
public void createSchema(String type, String label, String property) {
    switch (type) {
        case "NODE_PROPERTY_UNIQUE":
            this.inserter.createDeferredConstraint(DynamicLabel.label(label)).assertPropertyIsUnique(property).create();
            break;
        case "NODE_PROPERTY_INDEX":
            this.inserter.createDeferredSchemaIndex(DynamicLabel.label(label)).on(property).create();
            break;
        default:
            // default is unique constraint
            this.inserter.createDeferredConstraint(DynamicLabel.label(label)).assertPropertyIsUnique(property).create();
            break;
    }
}
项目:federator    文件:Neo4J.java   
@Override
public String insert(Entity entity, Set<Value> values) throws ParseException, Exception {

    try (Transaction tx = graphDb.beginTx()) {

        if (values == null || values.isEmpty() || values.size() == 0)
            throw new Exception("Cannot insert an empty list");

        Node node = graphDb.createNode();
        node.addLabel(DynamicLabel.label(entity.getId()));
        node.addLabel(DynamicLabel.label(entity.getName()));

        for (Value value : values) {
            node.setProperty(value.getField().getFieldName(), value.getValue());

            if (value.getType().equals("entity")) {

                Node related = graphDb.getNodeById(Long.valueOf(value.getValue()));

                node.createRelationshipTo(related,
                        DynamicRelationshipType.withName(value.getField().getFieldName()));
            }
        }

        tx.success();

        return entity.getId();
    }
}
项目:federator    文件:Neo4J.java   
@Override
public List<Hit> query(Entity entity, Set<Value> values) throws Exception {

    List<Hit> hits = new ArrayList<Hit>();

    try (Transaction tx = graphDb.beginTx()) {

        for (Value queryValue : values) {

            ResourceIterator<Node> nodes = graphDb.findNodes(DynamicLabel.label(entity.getName()),
                    queryValue.getField().getFieldName(), queryValue.getValue());

            while (nodes.hasNext()) {

                Node node = nodes.next();

                List<Value> tempValues = new ArrayList<Value>();

                for (String property : node.getAllProperties().keySet()) {
                    Value value = new Value(entity.getName(), property,
                            node.getAllProperties().get(property).toString(), new Type(DataType.STRING.toString()));
                    tempValues.add(value);
                }

                Hit hit = new Hit();
                hit.setEntity(entity);
                hit.setValues(tempValues);

                hits.add(hit);
            }
        }
    }

    return hits;
}
项目:knowledge-extraction    文件:Neo4JDb.java   
public void insertTriplet(TripletRelation triplet, boolean mergeSubject) {
    final Label label_sub = DynamicLabel.label(LAB_SUBJECT);
    final Label label_obj = DynamicLabel.label(LAB_OBJECT);

    Node arg1 = null;
    if (mergeSubject) {
        arg1 = getNode(null, PROP_NAME, triplet.getArg1()
                .toLowerCase());
    }

    try (Transaction tx = graphDb.beginTx()) {
        if (arg1 == null) {
            arg1 = graphDb.createNode(label_sub);
            arg1.setProperty(PROP_OCCURRENCES, 1);
            arg1.setProperty(PROP_NAME, triplet.getArg1().toLowerCase());
        } else {
            int occurences = (Integer) arg1.getProperty(PROP_OCCURRENCES) + 1;
            arg1.setProperty(PROP_OCCURRENCES, occurences);
        }
        Node arg2 = graphDb.createNode(label_obj);
        arg2.setProperty(PROP_OCCURRENCES, 1);
        arg2.setProperty(PROP_NAME, triplet.getArg2().toLowerCase());

        Relationship relationship = arg1.createRelationshipTo(arg2,
                RelTypes.RELATES);
        relationship.setProperty(PROP_NAME, triplet.getRelation()
                .toLowerCase());
        //confidence
        relationship.setProperty(PROP_CONFIDENCE, triplet.getConfidence());
        tx.success();
    }
}
项目:knowledge-extraction    文件:Neo4JDb.java   
public void createIndexes() {
    try (Transaction tx = graphDb.beginTx()) {
        Schema schema = graphDb.schema();
        schema.indexFor(DynamicLabel.label(LAB_SUBJECT))
                .on(PROP_NAME).create();
        tx.success();
    }
}
项目:neo4jena    文件:JenaNeoNode.java   
/**
 * Check if the given node is a URI.
 */
@Override
public boolean isURI() {
    Transaction tx = graphDb.beginTx();
    if(node!=null){
        //System.out.println("IS uri");
        return node.hasLabel(DynamicLabel.label(NeoGraph.LABEL_URI));
    }
    tx.success();
    return false;
}
项目:neo4jena    文件:JenaNeoNode.java   
/**
 * Check if the node is a blank node.
 */
@Override
 public boolean isBlank(){
    Transaction tx = graphDb.beginTx();
    if(node!=null){
        boolean check = node.hasLabel(DynamicLabel.label(NeoGraph.LABEL_BNODE));
        tx.success();
        return check;
    }
    return false;
 }
项目:neo4jena    文件:JenaNeoNode.java   
/**
 * Check if the node is a literal.
 */
@Override
public boolean isLiteral() {
 Transaction tx = graphDb.beginTx();
 if(node!=null){
     boolean check = node.hasLabel(DynamicLabel.label(NeoGraph.LABEL_LITERAL));
    // System.out.println("node is literal");
     tx.success();
     return check;
 }
 return false;
}
项目:zerograph    文件:Database.java   
private Label getLabel(String name) {
    if (labelCache.containsKey(name)) {
        return labelCache.get(name);
    } else {
        Label label = DynamicLabel.label(name);
        labelCache.put(name, label);
        return label;
    }
}
项目:zerograph    文件:FakeNode.java   
@Override
public Iterable<Label> getLabels() {
    ArrayList<Label> labels = new ArrayList<>(labelNames.size());
    for (String labelName : labelNames) {
        labels.add(DynamicLabel.label(labelName));
    }
    return labels;
}
项目:WikiN-G-ER    文件:GraphTest.java   
public GraphTest() {
        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("./database/");
        Transaction tx = graphDb.beginTx();     
        Label label = DynamicLabel.label( "message" );

//      firstNode = graphDb.createNode();
//      firstNode.setProperty( "message", "Hello, " );
//      secondNode = graphDb.createNode();
//      secondNode.setProperty( "message", "World!" );
//
//      relationship = firstNode.createRelationshipTo( secondNode, RelTypes.KNOWS );
//      relationship.setProperty( "message", "brave Neo4j " );
//      
//      System.out.print( firstNode.getProperty( "message" ) );
//      System.out.print( relationship.getProperty( "message" ) );
//      System.out.print( secondNode.getProperty( "message" ) );
//              
//      firstNode.getSingleRelationship( RelTypes.KNOWS, Direction.OUTGOING ).delete();
//      firstNode.delete();
//      secondNode.delete();

        ResourceIterator<Node> users = graphDb
                .findNodesByLabelAndProperty( label, "message", "Hello, " )
                .iterator();

        Node firstUserNode;
        if ( users.hasNext() )
        {
            firstUserNode = users.next();
            System.out.println("test: " + firstUserNode.getProperty("message"));
        }
        users.close();

        tx.success();
        graphDb.shutdown();
    }
项目:PhenoImageShare    文件:Neo4jAccessUtils.java   
public Label createLabel(String label){
    Label l = null;
    try ( Transaction tx = db.beginTx(); ){
        l = DynamicLabel.label(label);
        tx.close();
    }

    return l;

}
项目:jqassistant-plugins    文件:PerformanceIT.java   
private void cleanDb(final GraphDatabaseService graphDb) {
    try ( Transaction tx = graphDb.beginTx() )
    {
        for ( Node node : loop(graphDb.findNodes(DynamicLabel.label("Package"))))
        {
            for (Relationship rel : node.getRelationships()) {
                rel.delete();
            }
            node.delete();
        }
        tx.success();
    }
}
项目:csvtreeloader    文件:CSVTreeBuilder.java   
public ColumnSpec(String columnSpec) throws UnsupportedEncodingException {
    String[] headerSpec = columnSpec.split("\\.");
    this.name = URLDecoder.decode(headerSpec[0],"US-ASCII");
    this.property = field(headerSpec, 1, this.name.toLowerCase().replaceAll("\\s+", "_"));
    String defaultLabelName = StringUtils.capitalize(this.name).replaceAll("\\s+", "");
    this.label = DynamicLabel.label(field(headerSpec, 2, defaultLabelName));
    this.properties = field(headerSpec, 3, null);
}
项目:elasticsearch-river-neo4j    文件:Neo4jDriver.java   
@Inject
public Neo4jDriver(RiverName riverName, RiverSettings settings, @RiverIndexName final String riverIndexName, final Client client) {
    super(riverName, settings);
    this.client = client;

    uri = XContentMapValues.nodeStringValue(XContentMapValues.extractValue("neo4j.uri", settings.settings()), DEFAULT_NEO_URI);
    List<Object> neo4jLabels = XContentMapValues.extractRawValues("neo4j.labels", settings.settings());
    String label;
    if(XContentMapValues.isArray(neo4jLabels)) {
        for (Object neo4jLabel : neo4jLabels) {
            label = XContentMapValues.nodeStringValue(neo4jLabel, null);
            labels.add(DynamicLabel.label(label));
        }
    }
    timestampField = XContentMapValues.nodeStringValue(XContentMapValues.extractValue("neo4j.timestampField", settings.settings()), DEFAULT_NEO_TIMESTAMP_FIELD);
    interval = XContentMapValues.nodeIntegerValue(XContentMapValues.extractValue("neo4j.interval", settings.settings()), DEFAULT_NEO_INTERVAL);
    index = XContentMapValues.nodeStringValue(XContentMapValues.extractValue("index.name", settings.settings()), DEFAULT_NEO_INDEX);
    type = XContentMapValues.nodeStringValue(XContentMapValues.extractValue("index.type", settings.settings()), DEFAULT_NEO_TYPE);
    indexFromLabel = XContentMapValues.nodeStringValue(XContentMapValues.extractValue("index.name.label",
        settings.settings()), null);
    typeFromLabel = XContentMapValues.nodeStringValue(XContentMapValues.extractValue("index.type.label",
        settings.settings()), null);

    logger.debug("Neo4j settings [uri={}]", new Object[]{uri});
    logger.debug("River settings [indexName={}, type={}, interval={}, timestampField={}, indexLabel={}, " +
            "typelabel={}]",
        new Object[]{index,
            type,
            interval,
            timestampField,
            indexFromLabel,
            typeFromLabel}
    );

}
项目:elasticsearch-river-neo4j    文件:Neo4jIndexerTest.java   
@Before
public void before() {
    worker = mock(ElasticOperationWorker.class);
    db = mock(SpringCypherRestGraphDatabase.class);
    List<Label> labels = new ArrayList<>();
    labels.add(DynamicLabel.label("User"));
    indexer = new Neo4jIndexer(db, worker, new SimpleIndexingStrategy(), new SimpleDeletingStrategy(), "myindex", "mytype", labels);
}
项目:elasticsearch-river-neo4j    文件:Neo4jIndexerTest.java   
@Test
public void thatAllNodesAreQueuedAndExpunged() {     
    Node node1 = mock(Node.class);
    Node node2 = mock(Node.class);
    Node node3 = mock(Node.class);
    List<Node> nodes = Arrays.asList(node1, node2, node3);
    for (Node node : nodes) {
        Mockito.when(node.hasLabel(DynamicLabel.label("User"))).thenReturn(true);
    }
    Mockito.when(db.getAllNodes()).thenReturn(nodes);
    indexer.index();
    verify(worker, times(4)).queue(Matchers.any(IndexOperation.class)); // 3itimes for index and once for expunge
}
项目:neo4j-couchbase-connector    文件:Neo4jEventHandlerTest.java   
@Test
public void shouldTraceChangesOnGraph() {

    GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();

    database.registerTransactionEventHandler(new Neo4jEventListener(database));

    try (Transaction tx = database.beginTx()) {

        Node vanGogh = database.createNode(DynamicLabel.label("Artist"));

        vanGogh.setProperty("firstName", "Vincent");
        vanGogh.setProperty("secondName", "Willem");
        vanGogh.setProperty("lastName", "Van Gogh");

        tx.success();
    }
}
项目:lumen    文件:LumenPersistenceImportLabelsApp.java   
public void importLabels(File dbPath, final File file) throws IOException {
        log.info("Importing {} ({} KiB) to {} ...", file, NUMBER.format(DefaultGroovyMethods.asType(file.length() / 1024, Long.class)), dbPath);
        long importeds = 0l;

        final BatchInserter inserter = BatchInserters.inserter(dbPath);
        try {
            final Label resourceLabel = DynamicLabel.label("Resource");
            final Label labelLabel = DynamicLabel.label("Label");
            inserter.createDeferredConstraint(resourceLabel).assertPropertyIsUnique("href").create();

            // PLEASE create the label indexes on last step, not now! to speed up imports on later stages
//            inserter.createDeferredSchemaIndex(resourceLabel).on('prefLabel').create()
//            inserter.createDeferredSchemaIndex(resourceLabel).on('isPreferredMeaningOf').create()
//            inserter.createDeferredSchemaIndex(labelLabel).on('v').create()

            final DynamicRelationshipType rdfsLabel = DynamicRelationshipType.withName("rdfs_label");

            try (final Scanner scanner = new Scanner(file, StandardCharsets.UTF_8.name())) {
                scanner.useDelimiter("\u0001");// Ctrl+A (SOH)
                while (true) {
                    final Object line;
                    try {
                        line = scanner.next();
                    } catch (NoSuchElementException ex) {
                        break;
                    }

                    final IndexedResource res = mapper.readValue((String) line, IndexedResource.class);
                    if (res.getPrefLabel() == null && res.getLabels() != null && !res.getLabels().isEmpty()) {
                        res.setPrefLabel(res.getLabels().get(0).getValue());
                        res.getLabels().remove(0);
                    }

                    final Map<String, Object> props = new HashMap<>();
                    if (res.getPrefLabel() != null) {
                        props.put("prefLabel", res.getPrefLabel());
                    }

                    if (res.getIsPreferredMeaningOf() != null) {
                        props.put("isPreferredMeaningOf", res.getIsPreferredMeaningOf());
                    }

                    final long resNode = inserter.createNode(props, resourceLabel);
                    for (IndexedResource.LocalizedLabel it : res.getLabels()) {
                        final Map<String, Object> labelProps = new HashMap<>();

                        if (it.getLanguage() != null) {
                            labelProps.put("l", it.getLanguage());
                        }

                        final long labelNode = inserter.createNode(labelProps, labelLabel);
                        inserter.createRelationship(resNode, labelNode, rdfsLabel, new LinkedHashMap());
                    }
                    importeds++;

                    if (importeds % 10000 == 0) {
                        log.info("Imported {} resource nodes +prefLabel +isPreferredMeaningOf +label relationships from {}", NUMBER.format(importeds), file);
                    }

                }

            }
        } catch (Exception e) {
            throw new RuntimeException("Cannot process", e);
        } finally {
            log.info("Shutting down batchInserter after importing {} resource nodes from {} ...", NUMBER.format(importeds), file);
            inserter.shutdown();
        }

        log.info("Completed importing {} resource nodes +prefLabel +isPreferredMeaningOf +label relationships from {}", NUMBER.format(importeds), file);
    }
项目:mondo-hawk    文件:Neo4JBatchUtil.java   
public static Label createLabel(final String s) {
    Label a = DynamicLabel.label(s);
    return a;
}
项目:neo4jena    文件:UniqueNodeFactory.java   
/**
 * Initializes the node.
 */
@Override
protected void initialize(Node created, Map<String, Object> properties) {
    created.addLabel(DynamicLabel.label(NeoGraph.LABEL_URI));
    created.setProperty(NeoGraph.PROPERTY_URI, properties.get(NeoGraph.PROPERTY_URI));
}
项目:paprika    文件:IndexManager.java   
public void createIndex(){
    try ( Transaction tx = graphDatabaseService.beginTx() )
    {
        Schema schema = graphDatabaseService.schema();
        if(schema.getIndexes(DynamicLabel.label("Variable")).iterator().hasNext()) {
                 schema.indexFor(DynamicLabel.label("Variable"))
                .on("app_key")
                .create();
         }
        if(schema.getIndexes(DynamicLabel.label("Method")).iterator().hasNext()) {
            schema.indexFor(DynamicLabel.label("Method"))
                    .on("app_key")
                    .create();
            schema.indexFor(DynamicLabel.label("Method"))
                    .on("is_static")
                    .create();
        }
        if(schema.getIndexes(DynamicLabel.label("Argument")).iterator().hasNext()) {
            schema.indexFor(DynamicLabel.label("Argument"))
                    .on("app_key")
                    .create();
            schema.indexFor(DynamicLabel.label("Argument"))
                    .on("app_key")
                    .create();
        }
        if(schema.getIndexes(DynamicLabel.label("ExternalClass")).iterator().hasNext()) {
            schema.indexFor(DynamicLabel.label("ExternalClass"))
                    .on("app_key")
                    .create();
        }
        if(schema.getIndexes(DynamicLabel.label("ExternalMethod")).iterator().hasNext()) {
            schema.indexFor(DynamicLabel.label("ExternalMethod"))
                    .on("app_key")
                    .create();
        }
        tx.success();
    }
    try ( Transaction tx = graphDatabaseService.beginTx() )
    {
        org.neo4j.graphdb.index.IndexManager index = graphDatabaseService.index();
        if(!index.existsForRelationships("calls")) {
            index.forRelationships("calls");
        }
        tx.success();
    }
}
项目:neo4j-mazerunner    文件:WriterTest.java   
private void createSampleGraph(GraphDatabaseService db) {

        List<Node> nodes = new ArrayList<>();

        int max = 200;
        Transaction tx = db.beginTx();
        Node partitionNode = db.createNode();
        partitionNode.addLabel(DynamicLabel.label("Category"));
        tx.success();
        tx.close();
        int count = 0;
        int partitionBlockCount = 50;

        tx = db.beginTx();
        // Create nodes
        for (int i = 0; i < max; i++) {

            nodes.add(db.createNode());
            nodes.get(i).addLabel(DynamicLabel.label("Node"));
            partitionNode.createRelationshipTo(nodes.get(i), withName("HAS_CATEGORY"));
            count++;
            if(count >= partitionBlockCount && i != max - 1) {

                count = 0;
                partitionNode = db.createNode();
                partitionNode.addLabel(DynamicLabel.label("Category"));

                tx.success();
                tx.close();
                tx = db.beginTx();

                System.out.println(i);
            }
        }

        tx.success();
        tx.close();

        tx = db.beginTx();
        // Create PageRank test graph
        for (int i = 0; i < (max / 2) - 1; i++) {
            nodes.get(i).createRelationshipTo(nodes.get(i + (max / 2)), withName("CONNECTED_TO"));
            nodes.get(i + (max / 2)).createRelationshipTo(nodes.get(i + 1), withName("CONNECTED_TO"));
            if(count >= partitionBlockCount / 2 && i != max - 1) {
                tx.success();
                tx.close();
                tx = db.beginTx();

                System.out.println("B: " + i);
            }
            if(i == (max / 2) - 2) {
                nodes.get((i + 1) + (max / 2)).createRelationshipTo(nodes.get(0), withName("CONNECTED_TO"));
                nodes.get(i + 1).createRelationshipTo(nodes.get((max / 2)), withName("CONNECTED_TO"));
            }
        }

        tx.success();
        tx.close();
    }
项目:zerograph    文件:ResourceTest.java   
public void addLabels(Node node, Collection<String> labelNames) {
    for (String labelName : labelNames) {
        node.addLabel(DynamicLabel.label(labelName));
    }
}
项目:jqassistant-plugins    文件:PerformanceIT.java   
private void importDb(final GraphDatabaseService graphDb) {
        Label packageLabel = DynamicLabel.label("Package" );
        Label javaLabel = DynamicLabel.label("Java" );
        Label plantUmlLabel = DynamicLabel.label("PlantUml" );
        try ( Transaction tx = graphDb.beginTx() )
        {
            Node firstNode;
            Node secondNode;

            // create X Java dependencies
            for(int i = 0; i < 100000; i++) {
                firstNode = graphDb.createNode(packageLabel, javaLabel);
                firstNode.setProperty( "fqn", "p1_"+i );
                secondNode = graphDb.createNode(packageLabel, javaLabel);
                secondNode.setProperty( "fqn", "p2_"+i );
                firstNode.createRelationshipTo(secondNode, RelTypes.DEPENDS_ON);
            }

            // create X PlantUml dependencies correct direction
            for(int i = 0; i < 1000; i++) {
                firstNode = graphDb.createNode(packageLabel, plantUmlLabel);
                firstNode.setProperty( "fqn", "p1_"+i );
                secondNode = graphDb.createNode(packageLabel, plantUmlLabel);
                secondNode.setProperty( "fqn", "p2_"+i );
                firstNode.createRelationshipTo(secondNode, RelTypes.MAY_DEPEND_ON);
            }
            // create X PlantUml dependencies wrong direction
            for(int i = 0; i < 10; i++) {
                firstNode = graphDb.createNode(packageLabel, plantUmlLabel);
                firstNode.setProperty( "fqn", "p2_"+i );
                secondNode = graphDb.createNode(packageLabel, plantUmlLabel);
                secondNode.setProperty( "fqn", "p1_"+i );
                firstNode.createRelationshipTo(secondNode, RelTypes.MAY_DEPEND_ON);
            }
            tx.success();
        }

/*
        try ( Transaction tx = graphDb.beginTx() )
        {
            graphDb.schema().indexFor(packageLabel )
                    .on( "fqn" )
                    .create();
            tx.success();
        }
*/
    }
项目:obelix    文件:ObelixBatchImport.java   
public static void run(final String neo4storage,
        final String redisQueueName, final String redisHost) {

    ObelixQueue redisQueueManager = new RedisObelixQueue(redisQueueName, redisHost);

    Label userLabel = DynamicLabel.label("User");
    Label itemLabel = DynamicLabel.label("Item");

    Map<String, Long> usersNodesMap = new HashMap<>();
    Map<String, Long> itemsNodesMap = new HashMap<>();
    Map<String, Long> relationshipsMap = new HashMap<>();

    Map<String, String> config = new HashMap<>();
    config.put("neostore.nodestore.db.mapped_memory", "2G");
    config.put("neostore.relationshipstore.db.mapped_memory", "9G");
    config.put("neostore.propertystore.db.mapped_memory", "800M");
    config.put("neostore.propertystore.db.strings.mapped_memory", "800M");
    config.put("neostore.propertystore.db.arrays.mapped_memory", "500M");

    BatchInserter inserter;

    inserter = BatchInserters.inserter(neo4storage, config);

    BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);

    registerShutdownHook(inserter, indexProvider);

    BatchInserterIndex usersIndex = indexProvider.nodeIndex("users",
            MapUtil.stringMap("type", "exact"));
    usersIndex.setCacheCapacity("node_id", NEO_CACHE_CAPACITY);

    BatchInserterIndex itemsIndex = indexProvider.nodeIndex("items",
            MapUtil.stringMap("type", "exact"));
    usersIndex.setCacheCapacity("node_id", NEO_CACHE_CAPACITY);

    BatchInserterIndex relationshipIndex = indexProvider.relationshipIndex("relationships",
            MapUtil.stringMap("type", "exact"));
    usersIndex.setCacheCapacity("timestamp", NEO_CACHE_CAPACITY);

    boolean notFinised = true;

    int c = 0;
    while (notFinised) {

        ObelixQueueElement result = redisQueueManager.pop();

        if (result == null) {
            notFinised = false;
        }

        if (result != null) {

            NeoEvent event = getEvent(result.toString());

            if (event == null) {
                continue;
            }

            long userid = getOrCreateUserNodeID(event.getUser(), usersNodesMap,
                    usersIndex, inserter, userLabel);

            long itemid = getOrCreateItemNodeID(event.getItem(), itemsNodesMap,
                    itemsIndex, inserter, itemLabel);


            getOrCreateRelatinshipID(event.getTimestamp(),
                    userid, itemid, relationshipsMap, relationshipIndex,
                    inserter, NeoHelpers.RelTypes.VIEWED);

        }

        c += 1;

        if (c % IMPORTS_BETWEEN_EACH_LOG_MESSAGE == 0) {
            LOGGER.info("Imported " + c);
        }
    }
}
项目:extended-objects    文件:EmbeddedLabel.java   
public EmbeddedLabel(String name) {
    this(DynamicLabel.label(name));
}