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


Java Traverser类代码示例

本文整理汇总了Java中org.neo4j.graphdb.traversal.Traverser的典型用法代码示例。如果您正苦于以下问题:Java Traverser类的具体用法?Java Traverser怎么用?Java Traverser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Traverser类属于org.neo4j.graphdb.traversal包,在下文中一共展示了Traverser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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