当前位置: 首页>>代码示例>>Java>>正文


Java GraphDatabaseService.execute方法代码示例

本文整理汇总了Java中org.neo4j.graphdb.GraphDatabaseService.execute方法的典型用法代码示例。如果您正苦于以下问题:Java GraphDatabaseService.execute方法的具体用法?Java GraphDatabaseService.execute怎么用?Java GraphDatabaseService.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.neo4j.graphdb.GraphDatabaseService的用法示例。


在下文中一共展示了GraphDatabaseService.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldTransformCypherAlbumsToJSONDoc

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Test
	public void shouldTransformCypherAlbumsToJSONDoc() throws SQLException {
		
//		GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
		GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(new File("/Applications/Development/Neo4j-2.3.2/neo4j-community-2.3.2/data/graph.db"));
		
		database.registerTransactionEventHandler(new Neo4jEventListener(database));
		
		String cypher = "MATCH (n) "
						+ "WHERE n.name = \"Volcano\" "
						+ "WITH n "
						+ "SET n.explicit = true "
						+ "RETURN n";
		
		try (Transaction tx = database.beginTx()) {

			database.execute(cypher);
			tx.success();
		}
	}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:21,代码来源:Neo4jEventHandlerTest.java

示例2: countRedundancies

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
/**
 * @see org.neo4art.sentiment.repository.RedundancyCounterRepository#countRedundancies(org.neo4art.literature.domain.Document, long, int, int)
 */
@Override
public void countRedundancies(Document document, long redundancyRootNodeId, int minWordCount, int maxWordCount)
{
  GraphDatabaseService graphDatabaseService = Neo4ArtGraphDatabaseServiceSingleton.getGraphDatabaseService();
  
  //TODO We can try to optime this statement by adding a vertex to the last nlp sentence node, to make the computation of p easier
  
  String cql = "MATCH (document:" + document.getLabels()[0].name() + ")-[r:" + NLPRelationship.TOKENIZED_IN_POS + "]->(startingNode:Nlp) " +
               "WHERE id(document) = " + document.getNodeId() + " " +
               "WITH r.nlpSentenceLength -1 as nlpPathLength, startingNode " +
               "MATCH p = (startingNode:Nlp)-[r*]->() " +
               "WHERE length(p) = nlpPathLength " +
               "UNWIND nodes(p) AS wordsInDocument " +
               "MATCH redundantWordsPath = (wordsInDocument)-[*" + (minWordCount - 1) + ".." + (maxWordCount - 1) + "]->() " +
               "WITH reduce(redundantWords = \"\", redundantWord in nodes(redundantWordsPath) | redundantWords + lower(redundantWord." + NLP.POS_PROPERTY_NAME + ") + \" \") as redundantPath " +
               "MERGE (redundancyNode:" + RedundancyTreeLabel.RedundancyTree + "{" + RedundancyCounter.REDUNDANT_PATH_PROPERTY_NAME + ": redundantPath}) " +
               "ON CREATE SET redundancyNode." + RedundancyCounter.REDUNDANCY_COUNTER_PROPERTY_NAME + " = 1 " +
               "ON MATCH SET redundancyNode." + RedundancyCounter.REDUNDANCY_COUNTER_PROPERTY_NAME + "=redundancyNode." + RedundancyCounter.REDUNDANCY_COUNTER_PROPERTY_NAME + " + 1";
  
  System.out.println(cql);
  
  graphDatabaseService.execute(cql);
}
 
开发者ID:neo4art,项目名称:neo4art,代码行数:27,代码来源:RedundancyCounterAggregatorTreeRepository.java

示例3: read

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
private List<Map<String, Object>> read(String cql) {
    GraphDatabaseService gds = graphDatabase.getGraphDatabaseService();
    List<Map<String, Object>> rows = new ArrayList<>();
    try (Transaction transaction = gds.beginTx();
         Result result = gds.execute(cql)) {

        while (result.hasNext()) {
            rows.add(result.next());
        }
        transaction.success();
    }
    return rows;
}
 
开发者ID:fbiville,项目名称:hands-on-neo4j-devoxx-fr-2017,代码行数:14,代码来源:ExerciseRepositoryTest.java

示例4: write

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
private void write(String cql) {
    GraphDatabaseService graphDatabaseService = graphDatabase.getGraphDatabaseService();
    try (Transaction tx = graphDatabaseService.beginTx()) {
        graphDatabaseService.execute(cql);
        tx.success();
    }
}
 
开发者ID:fbiville,项目名称:hands-on-neo4j-devoxx-fr-2017,代码行数:8,代码来源:ExerciseRepositoryTest.java

示例5: main

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public static void main(String[] args) {

        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = Utils.parseCommandLine(getOptions(), args);

        String graphDbPath = cmd.getOptionValue("d", Owl2Neo4jLoader.GRAPH_DB_PATH);
        GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(graphDbPath));
        String query = "MATCH (n) RETURN n ORDER BY ID(n) DESC LIMIT 30;";
        Transaction tx = graphDb.beginTx();
        try {
            Result result = graphDb.execute(query);
            while (result.hasNext()) {
                Map<String, Object> row = result.next();
                for (String key : result.columns()) {
                    Node node = (Node) row.get(key);
                    Object name = node.getProperty("name");
                    System.out.printf("%s = %s; name = %s%n", key, row.get(key), name);
                }

            }
            tx.success();
        }
        catch (Exception e) {
            System.err.println("Exception caught: " + e.getMessage());
            e.printStackTrace();
            System.exit(ERR_STATUS);
        }
        finally {
            tx.close();
        }
        System.out.println("Exiting with success...");
        System.exit(OK_STATUS);

    }
 
开发者ID:ISA-tools,项目名称:FAIRsharing-Owl2Neo,代码行数:35,代码来源:Neo4jQuery.java

示例6: execute

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public Result execute(GraphDatabaseService database) {
	if (result == null) {
		start = System.currentTimeMillis();
		try ( Transaction ignored = database.beginTx(); Result queryResult = database.execute(cypher) ) {
			end = System.currentTimeMillis();
			result = queryResult;
		}
	}
	return result;
}
 
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:11,代码来源:Query.java

示例7: getNodeCount

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public int getNodeCount(GraphDatabaseService db) {
    Result result = db.execute( "CYPHER runtime=compiled MATCH (n) RETURN max(id(n)) AS maxId" );
    Map response = result.next();
    if (response.get("maxId") != null) {
        return ((Number) response.get("maxId")).intValue() + 1;
    } else {
        return 1;
    }
}
 
开发者ID:maxdemarzi,项目名称:pagerank_spi,代码行数:10,代码来源:NodeCounter.java

示例8: getRelationshipCount

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
public int getRelationshipCount(GraphDatabaseService db) {
    Result result = db.execute( "CYPHER runtime=compiled MATCH ()-[r]->() RETURN max(id(r)) AS maxId" );
    Map response = result.next();
    if (response.get("maxId") != null) {
        return ((Number) response.get("maxId")).intValue() + 1;
    } else {
        return 1;
    }

}
 
开发者ID:maxdemarzi,项目名称:pagerank_spi,代码行数:11,代码来源:NodeCounter.java

示例9: execute

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
/**
 * Execute the query on the given database.
 * @param db the database to execute the query on.
 * @return the query result.
 */
public List<EnrichedSequenceNode> execute(GraphDatabaseService db) {
	sb.append("RETURN n");
	List<EnrichedSequenceNode> result;
	try (Transaction tx = db.beginTx()) {
		Result r = db.execute(sb.toString(), parameters);
		ResourceIterator<Node> it = r.columnAs("n");
		result = IteratorUtil.asCollection(it).stream()
			.map(e -> new Neo4jSequenceNode(db, e))
			.filter(p)
			.collect(Collectors.toList());
		tx.success();
	}
	return result;
}
 
开发者ID:ProgrammingLife2015,项目名称:dnainator,代码行数:20,代码来源:Neo4jQuery.java

示例10: makeSentimentAnalisysByArtist

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Override
public List<SentimentAnalysis> makeSentimentAnalisysByArtist(Artist artist)
{
  List<SentimentAnalysis> results = new ArrayList<SentimentAnalysis>();

  GraphDatabaseService graphDatabaseService = Neo4ArtGraphDatabaseServiceSingleton.getGraphDatabaseService();

  String cql = "MATCH (sentiment:" + SentymentLabel.SentimentAnalysis + ")-[:"+LiteratureRelationship.HAS_SENTIMENT+"]->(letter:" + LiteratureLabel.Letter + ") " + 
      //"WHERE letter.from={name} " + 
      "RETURN letter, sentiment ";

  Result result = graphDatabaseService.execute(cql, MapUtil.map("name", artist.getName()));

  //System.out.println("cql: "+cql);
  
  while (result.hasNext())
  {
    Map<String, Object> next = result.next();

    Node letterNode = (Node) next.get("letter");
    Node sentimentNode = (Node) next.get("sentiment");

    Letter letter = new Letter();
    letter.setTitle((String) letterNode.getProperty("title"));
    letter.setDate((String) letterNode.getProperty("when"));

    SentimentAnalysis sentimentAnalysis = new SentimentAnalysis();
    sentimentAnalysis.setSource(letter);
    sentimentAnalysis.setPolarity((String) sentimentNode.getProperty("polarity"));
    
    results.add(sentimentAnalysis);
  }

  return results;
}
 
开发者ID:neo4art,项目名称:neo4art,代码行数:36,代码来源:DefaultSentimentAnalisysRepository.java

示例11: populateDb

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
private void populateDb(GraphDatabaseService db) {
    try ( Transaction tx = db.beginTx()) {
        db.execute(TestObjects.MOVIES_QUERY);
        db.execute(TestObjects.KNOWS_QUERY);
        tx.success();
    }
}
 
开发者ID:maxdemarzi,项目名称:graph_processing,代码行数:8,代码来源:ClosenessCentralityTest.java

示例12: populateDb

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
private static void populateDb(GraphDatabaseService db) {
    try ( Transaction tx = db.beginTx()) {
        db.execute(TestObjects.COMPANIES_QUERY);
        tx.success();
    }
}
 
开发者ID:maxdemarzi,项目名称:pagerank_spi,代码行数:7,代码来源:PageRankTest.java

示例13: createTestData

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@GET
@Path("/createtestdata")
public Response createTestData(@Context GraphDatabaseService db) throws IOException {
    final String AIRLINES_STATEMENT=
            new StringBuilder()
                    .append("CREATE (airlines:Metadata {name:'Airlines'})")
                    .append("CREATE (airline1:Airline {name:'Neo4j Airlines', code:'NA'})")
                    .append("CREATE (airline2:Airline {name:'Unamerican Airlines', code:'UA'})")
                    .append("CREATE (airline3:Airline {name:'Divided Airlines', code:'DA'})")
                    .append("CREATE (airlines)<-[:IS_AIRLINE]-(airline1)")
                    .append("CREATE (airlines)<-[:IS_AIRLINE]-(airline2)")
                    .append("CREATE (airlines)<-[:IS_AIRLINE]-(airline3)")
                    .toString();

    final String MODEL_STATEMENT =
            new StringBuilder()
                    .append("CREATE (dfw_20150901:AirportDay {key:'DFW-1441065600'})")
                    .append("CREATE (iah_20150901:AirportDay {key:'IAH-1441065600'})")
                    .append("CREATE (ord_20150901:AirportDay {key:'ORD-1441065600'})")
                    .append("CREATE (ewr_20150901:AirportDay {key:'EWR-1441065600'})")
                    .append("CREATE (hnd_20150902:AirportDay {key:'HND-1441152000'})")

                    .append("CREATE (dst0:Destination {code:'IAH'})")
                    .append("CREATE (dst1:Destination {code:'ORD'})")
                    .append("CREATE (dst2:Destination {code:'EWR'})")
                    .append("CREATE (dst3:Destination {code:'HND'})")
                    .append("CREATE (dst4:Destination {code:'HND'})")

                    .append("CREATE (flight0:Flight {code:'UA-0', departs:1441101600, arrives:1441105200, distance:225})")
                    .append("CREATE (flight1:Flight {code:'UA-1', departs:1441108800, arrives:1441119600, distance:718})")
                    .append("CREATE (flight2:Flight {code:'UA-2', departs:1441108800, arrives:1441123200, distance:1416})")
                    .append("CREATE (flight3:Flight {code:'UA-3', departs:1441123200, arrives:1441177200, distance:6296})")
                    .append("CREATE (flight4:Flight {code:'UA-4', departs:1441130400, arrives:1441180800, distance:6731})")

                    .append("CREATE (dfw_20150901)-[:HAS_DESTINATION]->(dst0)")
                    .append("CREATE (iah_20150901)-[:HAS_DESTINATION]->(dst1)")
                    .append("CREATE (iah_20150901)-[:HAS_DESTINATION]->(dst2)")
                    .append("CREATE (ord_20150901)-[:HAS_DESTINATION]->(dst3)")
                    .append("CREATE (ewr_20150901)-[:HAS_DESTINATION]->(dst4)")

                    .append("CREATE (dst0)-[:UA_FLIGHT]->(flight0)")
                    .append("CREATE (dst1)-[:UA_FLIGHT]->(flight1)")
                    .append("CREATE (dst2)-[:UA_FLIGHT]->(flight2)")
                    .append("CREATE (dst3)-[:UA_FLIGHT]->(flight3)")
                    .append("CREATE (dst4)-[:UA_FLIGHT]->(flight4)")

                    .append("CREATE (flight0)-[:UA_FLIGHT]->(iah_20150901)")
                    .append("CREATE (flight1)-[:UA_FLIGHT]->(ord_20150901)")
                    .append("CREATE (flight2)-[:UA_FLIGHT]->(ewr_20150901)")
                    .append("CREATE (flight3)-[:UA_FLIGHT]->(hnd_20150902)")
                    .append("CREATE (flight4)-[:UA_FLIGHT]->(hnd_20150902)")

                    .toString();

    try (Transaction tx = db.beginTx()) {
        db.execute(AIRLINES_STATEMENT);
        db.execute(MODEL_STATEMENT);
        tx.success();
    }
    Map<String, String> results = new HashMap<String,String>(){{
        put("testdata","created");
    }};
    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:neo_airlines,代码行数:65,代码来源:Sample.java

示例14: run

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Override
public void run(String... args) throws Exception {
    final File schemeFile = new File("/data/project_netadm/opencog/neo4j/Bio_schemeFiles/mmc4.scm");
    final CypherParts parts = new CypherParts();
    final List<List<?>> lists = readScheme(schemeFile);
    for (final List<?> top : lists) {
        final Symbol symbol = (Symbol) top.get(0);
        switch (symbol.getName()) {
            // ignore 'define'
            // ignore 'display'
            // ignore 'set!'
            case "define":
            case "display":
            case "set!":
                break;
            // InheritanceLink is mapped to "rdfs:subClassOf"
            case "InheritanceLink":
                log.info("INHERITANCE {}", top);
                inheritanceToCypher(parts, top);
                break;
            // EvaluationLink
            case "EvaluationLink":
                log.info("EVALUATION {}", top);
                evaluationToCypher(parts, top);
                break;
            // MemberLink/2 gene:GeneNode concept:ConceptNode
            // MemberLink is mapped to "rdf:type" ("a" in TURTLE-speak)
            case "MemberLink":
                log.info("MEMBER {}", top);
                memberToCypher(parts, top);
                break;
            default:
                log.error("Unknown symbol in '{}'", top);
        }
    }
    log.info("Cypher:\n{}", parts);

    final GraphDatabaseService graphDb = graphDb();
    try (final Transaction tx = graphDb.beginTx()) {
        log.info("Ensuring constraints and indexes...");
        graphDb.execute("CREATE CONSTRAINT ON (n:opencog_Concept) ASSERT n.href IS UNIQUE");
        graphDb.execute("CREATE CONSTRAINT ON (n:opencog_Gene) ASSERT n.href IS UNIQUE");
        graphDb.execute("CREATE CONSTRAINT ON (n:opencog_Predicate) ASSERT n.href IS UNIQUE");
        graphDb.execute("CREATE CONSTRAINT ON (n:opencog_Phrase) ASSERT n.href IS UNIQUE");

        graphDb.execute("CREATE INDEX ON :opencog_Concept(prefLabel)");
        graphDb.execute("CREATE INDEX ON :opencog_Gene(prefLabel)");
        graphDb.execute("CREATE INDEX ON :opencog_Predicate(prefLabel)");
        graphDb.execute("CREATE INDEX ON :opencog_Phrase(prefLabel)");

        tx.success();
    }
    log.info("Ensured constraints and indexes.");

    try (final Transaction tx = graphDb.beginTx()) {
        log.info("Executing Cypher ...");
        graphDb.execute(parts.getAllCypher(), parts.getAllParams());
        tx.success();
    }
    log.info("Done");
}
 
开发者ID:ceefour,项目名称:opencog-neo4j,代码行数:62,代码来源:ImportBio1App.java

示例15: getNearestPointOfInterest

import org.neo4j.graphdb.GraphDatabaseService; //导入方法依赖的package包/类
@Override
public List<PointOfInterest> getNearestPointOfInterest(double lat, double lng, int limit, String type) {
	List<PointOfInterest> pointsOfInterest = null;

	GraphDatabaseService graphDatabaseService = Neo4ArtGraphDatabaseServiceSingleton.getGraphDatabaseService();

	String cql = "";
	if(type == null || "".equals(type)){
		cql = "MATCH node RETURN node LIMIT {limit}";
	} else {
		cql = "MATCH node:{type} RETURN node LIMIT {limit}";
	}

	Result result = graphDatabaseService.execute(cql, MapUtil.map("lat", lat, "lng", lng, "limit", limit));

	while (result.hasNext()) {
		Map<String, Object> next = result.next();

		if (pointsOfInterest == null) {
			pointsOfInterest = new ArrayList<PointOfInterest>();
		}

		/*WikipediaSearchResultNode artworkNode = (WikipediaSearchResultNode) next.get("artwork");
		WikipediaSearchResultNode colourAnalysisNode = (WikipediaSearchResultNode) next.get("colourAnalysis");
		WikipediaSearchResultNode averageClosestColourNode = (WikipediaSearchResultNode) next.get("averageClosestColour");

		Artwork artwork = new Artwork();
		// artwork.setArtist(artist);
		artwork.setTitle((String) artworkNode.getProperty("title"));
		artwork.setYear((String) artworkNode.getProperty("year"));
		artwork.setCompletionDate(new Date((Long) artworkNode.getProperty("completionDate")));

		Colour averageClosestColour = new Colour();
		averageClosestColour.setName((String) averageClosestColourNode.getProperty("name"));
		averageClosestColour.setRgb((int) averageClosestColourNode.getProperty("rgb"));

		Color minimumColour = new Color((int) colourAnalysisNode.getProperty("minimumColour"));
		Color averageColour = new Color((int) colourAnalysisNode.getProperty("averageColour"));
		Color maximumColour = new Color((int) colourAnalysisNode.getProperty("maximumColour"));

		ColourAnalysis colourAnalysis = new ColourAnalysis();
		colourAnalysis.setArtwork(artwork);
		colourAnalysis.setAverageClosestColour(averageClosestColour);
		colourAnalysis.setMinimumColour(minimumColour);
		colourAnalysis.setAverageColour(averageColour);
		colourAnalysis.setMaximumColour(maximumColour);
		colourAnalysis.setSource((String) colourAnalysisNode.getProperty("source"));*/
		
		PointOfInterest point = new PointOfInterest();
		pointsOfInterest.add(point);
	}

	return pointsOfInterest;
}
 
开发者ID:neo4art,项目名称:neo4art,代码行数:55,代码来源:POIGraphDatabaseServiceRepository.java


注:本文中的org.neo4j.graphdb.GraphDatabaseService.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。