本文整理匯總了Java中org.neo4j.graphdb.Direction類的典型用法代碼示例。如果您正苦於以下問題:Java Direction類的具體用法?Java Direction怎麽用?Java Direction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Direction類屬於org.neo4j.graphdb包,在下文中一共展示了Direction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveRelationships
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
private Set<DirectedRelationshipType> resolveRelationships(String key, String value) {
Set<DirectedRelationshipType> rels = new HashSet<>();
String cypherIn = String.format("[%s:%s]", key, value);
String cypherOut = cypherUtil.resolveRelationships(cypherIn);
Matcher m = ENTAILMENT_PATTERN.matcher(cypherOut);
while (m.find()) {
String types = m.group(2);
String[] cypherRels = types.split("\\|");
for (String cypherRel : cypherRels) {
String unquotedCypherRel = cypherRel.replaceAll("^`|`$","");
RelationshipType relType = RelationshipType.withName(unquotedCypherRel);
DirectedRelationshipType dirRelType = new DirectedRelationshipType(relType, Direction.OUTGOING);
rels.add(dirRelType);
}
}
return rels;
}
示例2: getDDGForFunction
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
public static DDG getDDGForFunction(Node funcNode)
{
DDG retval = new DDG();
for (Node statement : Traversals.getStatementsForFunction(funcNode))
{
Iterable<Relationship> rels = statement
.getRelationships(Direction.OUTGOING);
long srcId = statement.getId();
for (Relationship rel : rels)
{
if (!rel.getType().toString().equals(EdgeTypes.REACHES))
continue;
long dstId = rel.getEndNode().getId();
String symbol = rel.getProperty("var").toString();
retval.add(srcId, dstId, symbol);
}
}
return retval;
}
示例3: alternatingOrder
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
static ArrayList<Node> alternatingOrder (Node order) {
ArrayList<Node> products = new ArrayList<>();
Relationship prevRel = order.getSingleRelationship(RelationshipTypes.PREV, Direction.OUTGOING);
if (prevRel != null) {
Node prevOrder = prevRel.getEndNode();
prevRel = prevOrder.getSingleRelationship(RelationshipTypes.PREV, Direction.OUTGOING);
if (prevRel != null) {
prevOrder = prevRel.getEndNode();
for (Relationship r1 : prevOrder.getRelationships(Direction.OUTGOING, RelationshipTypes.HAS)) {
Node product = r1.getEndNode();
products.add(product);
}
}
}
return products;
}
示例4: diffFromCurrent
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Procedure(value = "graph.versioner.diff.from.current", mode = DEFAULT)
@Description("graph.versioner.diff.from.current(state) - Get a list of differences that must be applied to the given state in order to become the current entity state")
public Stream<DiffOutput> diffFromCurrent(
@Name("state") Node state) {
Optional<Node> currentState = Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.INCOMING))
.map(Relationship::getStartNode).map(entity -> entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
.map(Relationship::getEndNode);
Stream<DiffOutput> result = Stream.empty();
if(currentState.isPresent() && !currentState.equals(Optional.of(state))){
result = diffBetweenStates(Optional.of(state), currentState);
}
return result;
}
示例5: matchUser
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Procedure(name = "com.maxdemarzi.match.user", mode = Mode.READ)
@Description("CALL com.maxdemarzi.match.user(username) - find matching rules")
public Stream<NodeResult> matchUser(@Name("username") String username) throws IOException {
// We start by finding the user
Node user = db.findNode(Labels.User, "username", username);
if (user != null) {
// Gather all of their attributes in to a Set
Set<Node> userAttributes = new HashSet<>();
Collection<String> attributes = new HashSet<>();
for (Relationship r : user.getRelationships(Direction.OUTGOING, RelationshipTypes.HAS)) {
userAttributes.add(r.getEndNode());
attributes.add((String)r.getEndNode().getProperty("id"));
}
// Find the rules
Set<Node> rules = findRules(attributes, userAttributes);
return rules.stream().map(NodeResult::new);
}
return null;
}
示例6: accept
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Override
public <R, E extends Throwable> R accept(Visitor<R, E> visitor) throws E {
//filternodes:
for (Node node : nodes) {
visitor.visitNode(node);
for (Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
if (nodes.contains(relationship.getOtherNode(node))) {
if (!relationshipLabels.contains(relationship.getType().name())) {
continue;
}
visitor.visitRelationship(relationship);
}
}
}
return visitor.done();
}
示例7: accept
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Override
public <R, E extends Throwable> R accept(Visitor<R, E> visitor) throws E {
for (Node node : dbServices.getAllNodes()) {
if (node.hasLabel(Label.label("CompilationUnit"))) {
continue;
}
if (node.hasLabel(Label.label("SourceSpan"))) {
continue;
}
if (node.hasLabel(Label.label("SourceLocation"))) {
continue;
}
visitor.visitNode(node);
for (Relationship edge : node.getRelationships(Direction.OUTGOING)) {
if (edge.isType(RelationshipType.withName("location"))) {
continue;
}
visitor.visitRelationship(edge);
}
}
return visitor.done();
}
示例8: getPatternMatch
import org.neo4j.graphdb.Direction; //導入依賴的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);
}
示例9: shouldDeleteOneRelations
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Test
public void shouldDeleteOneRelations()
{
context.setDocumentKey("key");
Node parent = db.createNode();
parent.setProperty("type", "album");
Node child = db.createNode();
child.setProperty("type", "artist");
Node track = db.createNode();
track.setProperty("type", "track");
this.docrel.buildRelation(parent, child, context);
context.setDocumentKey("another_key");
this.docrel.buildRelation(child, track, context);
Set<Node> orphans = this.docrel.deleteRelations(context);
Assert.assertEquals(1, orphans.size());
Assert.assertEquals(1, StreamSupport.stream(parent.getRelationships().spliterator(), false).count());
Assert.assertEquals(0, StreamSupport.stream(child.getRelationships(Direction.OUTGOING).spliterator(), false).count());
}
示例10: shouldCreate3Relation
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Test
public void shouldCreate3Relation()
{
context.setDocumentKey("key");
Node parent = db.createNode();
parent.setProperty("type", "album");
Node child = db.createNode();
child.setProperty("type", "artist");
this.docrel.buildRelation(parent, child, context);
context.setDocumentKey("another_key");
Node track = db.createNode();
track.setProperty("type", "track");
this.docrel.buildRelation(parent, child, context);
this.docrel.buildRelation(child, track, context);
Assert.assertEquals(2, StreamSupport.stream(parent.getRelationships().spliterator(), false).count());
Assert.assertEquals(1, StreamSupport.stream(child.getRelationships(Direction.OUTGOING).spliterator(), false).count());
}
示例11: shouldDeleteRelationsOfKey
import org.neo4j.graphdb.Direction; //導入依賴的package包/類
@Test
public void shouldDeleteRelationsOfKey()
{
context.setDocumentKey("key");
Node parent = db.createNode();
parent.setProperty("type", "album");
Node child = db.createNode();
child.setProperty("type", "artist");
Node track = db.createNode();
track.setProperty("type", "track");
this.docrel.buildRelation(parent, child, context);
context.setDocumentKey("another_key");
this.docrel.buildRelation(child, track, context);
Set<Node> orphans = this.docrel.deleteRelations(context);
Assert.assertEquals(1, orphans.size());
Assert.assertEquals(1, StreamSupport.stream(parent.getRelationships().spliterator(), false).count());
Assert.assertEquals(0, StreamSupport.stream(child.getRelationships(Direction.OUTGOING).spliterator(), false).count());
}
示例12: getHypernyms
import org.neo4j.graphdb.Direction; //導入依賴的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;
}
示例13: getHyponyms
import org.neo4j.graphdb.Direction; //導入依賴的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;
}
示例14: isa
import org.neo4j.graphdb.Direction; //導入依賴的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;
}
示例15: minDistance
import org.neo4j.graphdb.Direction; //導入依賴的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;
}