org.neo4j.graphdb.DynamicLabel Java Examples
The following examples show how to use
org.neo4j.graphdb.DynamicLabel.
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: PartitionedAnalysis.java From neo4j-mazerunner with Apache License 2.0 | 6 votes |
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(); }
Example #2
Source File: Neo4JDb.java From knowledge-extraction with Apache License 2.0 | 5 votes |
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(); } }
Example #3
Source File: Neo4JDb.java From knowledge-extraction with Apache License 2.0 | 5 votes |
public void createIndexes() { try (Transaction tx = graphDb.beginTx()) { Schema schema = graphDb.schema(); schema.indexFor(DynamicLabel.label(LAB_SUBJECT)) .on(PROP_NAME).create(); tx.success(); } }
Example #4
Source File: JenaNeoNode.java From neo4jena with Apache License 2.0 | 5 votes |
/** * 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; }
Example #5
Source File: JenaNeoNode.java From neo4jena with Apache License 2.0 | 5 votes |
/** * 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; }
Example #6
Source File: JenaNeoNode.java From neo4jena with Apache License 2.0 | 5 votes |
/** * 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; }
Example #7
Source File: Neo4jDriver.java From elasticsearch-river-neo4j with Apache License 2.0 | 5 votes |
@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} ); }
Example #8
Source File: Neo4jIndexerTest.java From elasticsearch-river-neo4j with Apache License 2.0 | 5 votes |
@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); }
Example #9
Source File: Neo4jIndexerTest.java From elasticsearch-river-neo4j with Apache License 2.0 | 5 votes |
@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 }
Example #10
Source File: UniqueNodeFactory.java From neo4jena with Apache License 2.0 | 4 votes |
/** * 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)); }
Example #11
Source File: IndexManager.java From paprika with GNU Affero General Public License v3.0 | 4 votes |
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(); } }
Example #12
Source File: WriterTest.java From neo4j-mazerunner with Apache License 2.0 | 4 votes |
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(); }
Example #13
Source File: WriterTest.java From neo4j-mazerunner with Apache License 2.0 | 2 votes |
@Test public void testParallelUpdate() throws Exception { GraphDatabaseService db = setUpDb(); Transaction tx = db.beginTx(); // Use test configurations ConfigurationLoader.testPropertyAccess = true; Node nodePartition = db.createNode(); nodePartition.addLabel(DynamicLabel.label("Category")); PartitionDescription partitionDescription = new PartitionDescription(nodePartition.getId(), "Category"); // Create sample PageRank result String nodeList = ""; for(int i = 0; i < 100; i++) { db.createNode(); nodeList += i + " .001\n"; } tx.success(); tx.close(); // Create test path String path = ConfigurationLoader.getInstance().getHadoopHdfsUri() + "/test/propertyNodeList.txt"; writeListFile(path, nodeList); ProcessorMessage processorMessage = new ProcessorMessage(path, "pagerank", ProcessorMode.Partitioned); processorMessage.setPartitionDescription(partitionDescription); BufferedReader br = FileUtil.readGraphAdjacencyList(processorMessage); BufferedReader br2 = FileUtil.readGraphAdjacencyList(processorMessage); // Test parallel update PartitionedAnalysis.updatePartition(processorMessage, br, db); PartitionedAnalysis.updatePartition(processorMessage, br2, db); }