本文整理汇总了Java中org.neo4j.graphdb.traversal.Traverser类的典型用法代码示例。如果您正苦于以下问题:Java Traverser类的具体用法?Java Traverser怎么用?Java Traverser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Traverser类属于org.neo4j.graphdb.traversal包,在下文中一共展示了Traverser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPatternMatch
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
private Traverser getPatternMatch(Node startNode, final List<String> patterns, final List<NodeLabel> nodeLabels, final List<LinkLabel> linkLabels) {
TraversalDescription td = database.traversalDescription()
.depthFirst()
.evaluator( new Evaluator() {
public Evaluation evaluate( final org.neo4j.graphdb.Path path ) {
if ( path.length() == 0 ) {
return Evaluation.EXCLUDE_AND_CONTINUE;
}
boolean isToken = path.endNode().hasLabel(NodeLabel.WordToken);
boolean included = isToken && (path.length() == 1 || nodeHasAnnotation(path.endNode(), linkLabels.get(path.length() - 1), patterns.get(path.length() - 1)));
boolean continued = path.length() < patterns.size();
return Evaluation.of( included, continued );
}
} )
.relationships(LinkLabel.NEXT, Direction.OUTGOING)
.relationships(LinkLabel.HAS_TYPE, Direction.INCOMING)
.relationships(LinkLabel.HAS_LEMMA, Direction.INCOMING)
.relationships(LinkLabel.HAS_POS_TAG, Direction.INCOMING)
.relationships(LinkLabel.HAS_HEAD, Direction.INCOMING);
return td.traverse(startNode);
}
开发者ID:Taalmonsters,项目名称:WhiteLab2.0-Neo4J-Plugin,代码行数:22,代码来源:QueryBenchmark.java
示例2: getHypernyms
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public static List<String> getHypernyms(String cui){
List<String> hypers = new ArrayList<>();
try ( Transaction tx = graphDb.beginTx() ){
TraversalDescription td = graphDb.traversalDescription()
.breadthFirst()
.relationships(RelReader.RelTypes.ISA, Direction.OUTGOING)
.evaluator(Evaluators.excludeStartPosition());
Node cuiNode = graphDb.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, cui);
if(cuiNode == null) return hypers;
Traverser traverser = td.traverse(cuiNode);
for(Path path : traverser){
hypers.add(path.endNode().getProperty(RelReader.CUI_PROPERTY).toString());
}
tx.success();
}
return hypers;
}
开发者ID:tmills,项目名称:umls-graph-api,代码行数:21,代码来源:GraphFunctions.java
示例3: getHyponyms
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public static List<String> getHyponyms(String cui){
List<String> hypos = new ArrayList<>();
try ( Transaction tx = graphDb.beginTx() ){
TraversalDescription td = graphDb.traversalDescription()
.breadthFirst()
.relationships(RelReader.RelTypes.ISA, Direction.INCOMING)
.evaluator(Evaluators.excludeStartPosition());
Node cuiNode = graphDb.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, cui);
if(cuiNode == null) return hypos;
Traverser traverser = td.traverse(cuiNode);
for(Path path : traverser){
hypos.add(path.endNode().getProperty(RelReader.CUI_PROPERTY).toString());
}
tx.success();
}
return hypos;
}
开发者ID:tmills,项目名称:umls-graph-api,代码行数:21,代码来源:GraphFunctions.java
示例4: isa
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public static boolean isa(String cui1, String cui2){
boolean match=false;
try ( Transaction tx = graphDb.beginTx() ){
Node cui1Node = graphDb.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, cui1);
Node cui2Node = graphDb.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, cui2);
if(cui1Node == null || cui2Node == null) return match;
TraversalDescription td = graphDb.traversalDescription()
.breadthFirst()
.relationships(RelReader.RelTypes.ISA, Direction.OUTGOING)
.evaluator(Evaluators.excludeStartPosition())
.evaluator(Evaluators.includeWhereEndNodeIs(cui2Node));
Traverser traverser = td.traverse(cui1Node);
if(traverser.iterator().hasNext()){
match = true;
}
tx.success();
}
return match;
}
开发者ID:tmills,项目名称:umls-graph-api,代码行数:22,代码来源:GraphFunctions.java
示例5: minDistance
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public static int minDistance(String cui1, String cui2){
int distance = -1;
try ( Transaction tx = graphDb.beginTx() ){
Node cui1Node = graphDb.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, cui1);
Node cui2Node = graphDb.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, cui2);
if(cui1Node == null || cui2Node == null) return distance;
TraversalDescription td = graphDb.traversalDescription()
.breadthFirst()
.relationships(RelReader.RelTypes.ISA, Direction.OUTGOING)
.evaluator(Evaluators.excludeStartPosition())
.evaluator(Evaluators.includeWhereEndNodeIs(cui2Node));
Traverser traverser = td.traverse(cui1Node);
for(Path path : traverser){
int len = path.length();
if(distance == -1 || len < distance){
distance = len;
}
}
tx.success();
}
return distance;
}
开发者ID:tmills,项目名称:umls-graph-api,代码行数:25,代码来源:GraphFunctions.java
示例6: testRelReader
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
@Test
public void testRelReader() throws IOException{
RelReader reader = new RelReader(neo4jLocation);
reader.batchBuildGraph(new File("my_test_umls/"), "CtakesAllTuis.txt", "SNOMEDCT_US");
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(new File(neo4jLocation));
try ( Transaction tx = db.beginTx() ){
TraversalDescription td = db.traversalDescription()
.breadthFirst()
.relationships(RelReader.RelTypes.ISA, Direction.INCOMING)
.evaluator(Evaluators.excludeStartPosition());
Node cuiNode = db.findNode(RelReader.DictLabels.Concept, RelReader.CUI_PROPERTY, "C0007102");
Assert.assertNotNull(cuiNode);
Traverser traverser = td.traverse(cuiNode);
for(Path path : traverser){
System.out.println("At depth " + path.length() + " => " + path.endNode().getProperty("cui"));
}
}
db.shutdown();
}
开发者ID:tmills,项目名称:umls-graph-api,代码行数:23,代码来源:TestRelReader.java
示例7: printNeoFriends
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public String printNeoFriends() {
try (Transaction tx = graphDb.beginTx()) {
Node neoNode = getNeoNode();
// START SNIPPET: friends-usage
int numberOfFriends = 0;
String output = neoNode.getProperty("name") + "'s friends:\n";
Traverser friendsTraverser = getFriends(neoNode);
for (Path friendPath : friendsTraverser) {
output += "At depth " + friendPath.length() + " => " + friendPath.endNode().getProperty("name") + "\n";
numberOfFriends++;
}
output += "Number of friends found: " + numberOfFriends + "\n";
// END SNIPPET: friends-usage
return output;
}
}
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:17,代码来源:Quel.java
示例8: findAllPaths
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public Iterable<WeightedPath> findAllPaths( Node start, final Node end )
{
Predicate<Path> filter = new Predicate<Path>()
{
public boolean accept( Path position )
{
return position.endNode().equals( end );
}
};
final Traverser traverser = TRAVERSAL.expand( expander ).order(
new SelectorFactory( costEvaluator ) ).filter( filter ).traverse( start );
return new Iterable<WeightedPath>()
{
public Iterator<WeightedPath> iterator()
{
return new StopAfterWeightIterator( traverser.iterator(),
costEvaluator );
}
};
}
开发者ID:neo4j-contrib,项目名称:neo4j-mobile-android,代码行数:22,代码来源:Dijkstra.java
示例9: findAllPaths
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public Iterable<WeightedPath> findAllPaths( Node start, final Node end )
{
Predicate<Path> filter = new Predicate<Path>()
{
public boolean accept( Path position )
{
return position.endNode().equals( end );
}
};
final Traverser traverser = traversalDescription.order(
new SelectorFactory( end ) ).filter( filter ).traverse( start );
return new Iterable<WeightedPath>()
{
public Iterator<WeightedPath> iterator()
{
return new StopAfterWeightIterator( traverser.iterator(),
costEvaluator );
}
};
}
开发者ID:neo4j-contrib,项目名称:neo4j-mobile-android,代码行数:22,代码来源:ExperimentalAStar.java
示例10: printMatrixHackers
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public String printMatrixHackers() {
try (Transaction tx = graphDb.beginTx()) {
// START SNIPPET: find--hackers-usage
String output = "Hackers:\n";
int numberOfHackers = 0;
Traverser traverser = findHackers(getNeoNode());
for (Path hackerPath : traverser) {
output += "At depth " + hackerPath.length() + " => " + hackerPath.endNode().getProperty("name") + "\n";
numberOfHackers++;
}
output += "Number of hackers found: " + numberOfHackers + "\n";
// END SNIPPET: find--hackers-usage
return output;
}
}
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:16,代码来源:Quel.java
示例11: fillNodesFromBeginning
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
private void fillNodesFromBeginning(Node currentNode, ViralShortUrl url) {
// nodes from beginning, counted via a simple depth-first traversal
// in the opposite direction
Traverser t = Traversal.description().depthFirst()
.evaluator(Evaluators.excludeStartPosition())
.relationships(LinkRelationship.SPAWNS, Direction.INCOMING)
.traverse(currentNode);
int nodesFromBeginning = IteratorUtil.count(t);
url.setNodesFromBeginning(nodesFromBeginning);
}
开发者ID:Glamdring,项目名称:welshare,代码行数:11,代码来源:ViralLinkDaoNeo4j.java
示例12: getAncestors
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public void getAncestors(String task){
final Traverser traverser = getTraverser(task, Direction.OUTGOING);
for (Path path : traverser) {
System.out.println(pathToString(path, TASK_PATH_PRINTER));
}
System.out.println("----------------------------------------------");
}
开发者ID:fizalihsan,项目名称:Fig,代码行数:8,代码来源:Neo4jTaskAdapter.java
示例13: getDescendants
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public void getDescendants(String task){
final Traverser traverser = getTraverser(task, Direction.INCOMING);
for (Path path : traverser) {
System.out.println(pathToString(path, TASK_PATH_PRINTER));
}
System.out.println("----------------------------------------------");
}
开发者ID:fizalihsan,项目名称:Fig,代码行数:8,代码来源:Neo4jTaskAdapter.java
示例14: getTraverser
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public Traverser getTraverser(String task, Direction direction){
TraversalDescription td = Traversal.description()
.breadthFirst()
.relationships( TaskRelations.DEPENDS_ON, direction )
.evaluator(Evaluators.excludeStartPosition());
return td.traverse(getNode(task));
}
开发者ID:fizalihsan,项目名称:Fig,代码行数:8,代码来源:Neo4jTaskAdapter.java
示例15: getConnectedComponentsCount
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
@GET
@Path("/cc/{name}")
public String getConnectedComponentsCount(@PathParam("name") String name, @Context GraphDatabaseService db) throws IOException {
int CCid = 0;
for ( Node n : GlobalGraphOperations.at( db ).getAllNodes() ) {
if(!n.hasProperty("CCId")) {
Transaction tx = db.beginTx();
try {
Traverser traverser = Traversal.description()
.breadthFirst()
.relationships(DynamicRelationshipType.withName(name), Direction.BOTH)
.evaluator(Evaluators.excludeStartPosition())
.uniqueness(Uniqueness.NODE_GLOBAL)
.traverse(n);
int currentCCid = CCid;
CCid++;
n.setProperty("CCId", currentCCid);
for ( org.neo4j.graphdb.Path p : traverser )
{
p.endNode().setProperty("CCId", currentCCid);
}
tx.success();
}
catch ( Exception e )
{
tx.failure();
}
finally
{
tx.finish();
}
}
}
return String.valueOf(CCid);
}
开发者ID:maxdemarzi,项目名称:neo_cc,代码行数:36,代码来源:MyService.java
示例16: getFriends
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
private Traverser getFriends(final Node person) {
TraversalDescription td = graphDb.traversalDescription().breadthFirst().relationships(RelTypes.KNOWS, Direction.OUTGOING)
.evaluator(Evaluators.excludeStartPosition());
return td.traverse(person);
}
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:6,代码来源:Quel.java
示例17: findHackers
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
private Traverser findHackers(final Node startNode) {
TraversalDescription td = graphDb.traversalDescription().breadthFirst().relationships(RelTypes.CODED_BY, Direction.OUTGOING)
.relationships(RelTypes.KNOWS, Direction.OUTGOING).evaluator(Evaluators.includeWhereLastRelationshipTypeIs(RelTypes.CODED_BY));
return td.traverse(startNode);
}
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:6,代码来源:Quel.java
示例18: traverse
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public Traverser traverse( Node startNode )
{
return new TraverserImpl( this, startNode );
}
开发者ID:neo4j-contrib,项目名称:neo4j-mobile-android,代码行数:5,代码来源:TraversalDescriptionImpl.java
示例19: getCostFunctionsForNode
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
public static List<CostFunction> getCostFunctionsForNode(Long id, EmbeddedGraphDatabase database) {
List<CostFunction> costFunctions = new ArrayList<CostFunction>();
boolean transactionAllreadyRunning = false;
try {
transactionAllreadyRunning = (database.getTxManager().getStatus() == Status.STATUS_ACTIVE);
} catch (SystemException ex) {
log.error(ex.getMessage(), ex);
}
Transaction tx = (transactionAllreadyRunning) ? null : database.beginTx();
try {
Node parentNode = database.getNodeById(id);
if (parentNode == null) {
return costFunctions;
}
//search from this node with ID=id the target nodes for which it has a HAS_COST_FUNCTION relationship
TraversalDescription description = Traversal.traversal()
.evaluator(Evaluators.excludeStartPosition())
.relationships(ServiceUnitRelationship.hasCostFunction, Direction.OUTGOING)
.uniqueness(Uniqueness.NODE_PATH);
Traverser traverser = description.traverse(parentNode);
for (Path path : traverser) {
Node node = path.endNode();
CostFunction costFunction = new CostFunction();
costFunction.setId(node.getId());
if (node.hasProperty(KEY)) {
costFunction.setName(node.getProperty(KEY).toString());
} else {
log.warn("Retrieved CostFunction " + node + " has no " + KEY);
}
if (node.hasProperty(UUID)) {
costFunction.setUuid(java.util.UUID.fromString(node.getProperty(UUID).toString()));
} else {
log.warn("Retrieved CloudProvider " + costFunction + " has no " + UUID);
}
//carefull. this can lead to infinite recursion (is still a graph. maybe improve later)
costFunction.getAppliedIfServiceInstanceUses().addAll(getAppliedInConjunctionWithEntities(node.getId(), database));
//need to also retrieve Resurce and Quality
costFunction.getCostElements().addAll(CostElementDAO.getCostElementPropertiesForNode(node.getId(), database));
if (costFunction != null) {
//hack. if the costFunction has allready been added (equals is done on the DB Node),
//this means ServiceUnit has elasticity capability on it, and the old is also removed
if (costFunctions.contains(costFunction)) {
costFunctions.remove(costFunction);
} else {
costFunctions.add(costFunction);
}
}
}
if (!transactionAllreadyRunning) {
tx.success();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
} finally {
if (!transactionAllreadyRunning) {
tx.finish();
}
}
return costFunctions;
}
开发者ID:tuwiendsg,项目名称:MELA,代码行数:74,代码来源:CostFunctionDAO.java
示例20: getElasticityDependency
import org.neo4j.graphdb.traversal.Traverser; //导入依赖的package包/类
/**
* Counts how many elasticity characteristic nodes point to it with a
* "elasticityCapabilityFor" relationship
*
* @param id
* @param database
* @return sum of incoming MANDATORY_ASSOCIATION and OPTIONAL_ASSOCIATION
* elasticity capabilities if returns -1, means error encountered. otherwise
* the result is always >= 0
*/
public static int getElasticityDependency(long id, EmbeddedGraphDatabase database) {
CloudOfferedService elTarget = null;
int incomingPaths = 0;
boolean transactionAllreadyRunning = false;
try {
transactionAllreadyRunning = (database.getTxManager().getStatus() == Status.STATUS_ACTIVE);
} catch (SystemException ex) {
log.error(ex.getMessage(), ex);
}
Transaction tx = (transactionAllreadyRunning) ? null : database.beginTx();
try {
Node parentNode = database.getNodeById(id);
if (parentNode == null) {
log.error("Node with id " + id + " was not found");
return 0;
}
TraversalDescription description = Traversal.traversal()
.evaluator(Evaluators.excludeStartPosition())
.relationships(ServiceUnitRelationship.hasElasticityCapability, Direction.OUTGOING)
.uniqueness(Uniqueness.NODE_PATH);
Traverser traverser = description.traverse(parentNode);
//for each incoming path, if is MANDATORY_ASSOCIATION decrease the in
for (Path path : traverser) {
incomingPaths++;
}
if (!transactionAllreadyRunning) {
if (!transactionAllreadyRunning) {
tx.success();
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
} finally {
if (!transactionAllreadyRunning) {
tx.finish();
}
}
return incomingPaths;
}
开发者ID:tuwiendsg,项目名称:MELA,代码行数:57,代码来源:ServiceUnitDAO.java
注:本文中的org.neo4j.graphdb.traversal.Traverser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论