本文整理匯總了Java中org.neo4j.graphdb.RelationshipType類的典型用法代碼示例。如果您正苦於以下問題:Java RelationshipType類的具體用法?Java RelationshipType怎麽用?Java RelationshipType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RelationshipType類屬於org.neo4j.graphdb包,在下文中一共展示了RelationshipType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveRelationships
import org.neo4j.graphdb.RelationshipType; //導入依賴的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: diffFromCurrent
import org.neo4j.graphdb.RelationshipType; //導入依賴的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;
}
示例3: fromTextToJira
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
private void fromTextToJira(){
Map<String, Node> jiraMap=new HashMap<>();
try (Transaction tx = db.beginTx()) {
for (Node node:db.getAllNodes()){
if (node.hasLabel(Label.label(JiraExtractor.ISSUE))){
String name=(String) node.getProperty(JiraExtractor.ISSUE_NAME);
jiraMap.put(name, node);
}
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
for (Node srcNode : textNodes) {
String content = text(srcNode);
Set<String> tokenSet=new HashSet<>();
for (String e:content.split("[^A-Za-z0-9\\-_]+"))
tokenSet.add(e);
for (String jiraName:jiraMap.keySet()){
if (tokenSet.contains(jiraName))
srcNode.createRelationshipTo(jiraMap.get(jiraName), RelationshipType.withName(REFERENCE));
}
}
tx.success();
}
}
示例4: run
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
public void run(GraphDatabaseService db) {
this.db = db;
MboxHandler myHandler = new MboxHandler();
myHandler.setDb(db);
MimeConfig config=new MimeConfig();
config.setMaxLineLen(-1);
parser = new MimeStreamParser(config);
parser.setContentHandler(myHandler);
parse(new File(mboxPath));
try (Transaction tx = db.beginTx()) {
for (String address : myHandler.getMailUserNameMap().keySet()) {
Node node = myHandler.getMailUserMap().get(address);
node.setProperty(MAILUSER_NAMES, String.join(", ", myHandler.getMailUserNameMap().get(address)));
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
for (String mailId : myHandler.getMailReplyMap().keySet()) {
Node mailNode = myHandler.getMailMap().get(mailId);
Node replyNode = myHandler.getMailMap().get(myHandler.getMailReplyMap().get(mailId));
if (mailNode != null & replyNode != null)
mailNode.createRelationshipTo(replyNode, RelationshipType.withName(MailListExtractor.MAIL_IN_REPLY_TO));
}
tx.success();
}
}
示例5: createUserNode
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
private void createUserNode(Node mailNode, String userName, String userAddress, boolean sender) {
Node userNode;
if (!mailUserMap.containsKey(userAddress)) {
userNode = db.createNode();
userNode.addLabel(Label.label(MailListExtractor.MAILUSER));
userNode.setProperty(MailListExtractor.MAILUSER_MAIL, userAddress);
mailUserMap.put(userAddress, userNode);
}
userNode = mailUserMap.get(userAddress);
if (!mailUserNameMap.containsKey(userAddress))
mailUserNameMap.put(userAddress, new HashSet<>());
mailUserNameMap.get(userAddress).add(userName);
if (sender)
mailNode.createRelationshipTo(userNode, RelationshipType.withName(MailListExtractor.MAIL_SENDER));
else
mailNode.createRelationshipTo(userNode, RelationshipType.withName(MailListExtractor.MAIL_RECEIVER));
}
示例6: accept
import org.neo4j.graphdb.RelationshipType; //導入依賴的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();
}
示例7: add
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
public final Relationship add(RelationshipType type, Node tail, Node head, double prob) {
if (null == type)
throw new IllegalArgumentException("Illegal 'type' argument in Problem.add(RelationshipType, Node, Node, double): " + type);
if (null == tail)
throw new IllegalArgumentException("Illegal 'tail' argument in Problem.add(RelationshipType, Node, Node, double): " + tail);
if (null == head)
throw new IllegalArgumentException("Illegal 'head' argument in Problem.add(RelationshipType, Node, Node, double): " + head);
if (prob < 0.0 || prob > 1.0)
throw new IllegalArgumentException("Illegal 'prob' argument in Problem.add(RelationshipType, Node, Node, double): " + prob);
Relationship result = null;
try (Transaction tx = graph.beginTx()) {
result = tail.createRelationshipTo(head, type);
result.setProperty("prob", prob);
count += 1;
tx.success();
}
return result;
}
示例8: shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
@Test
public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode()
{
// GIVEN
RelationshipIndex index = relationshipIndex( EXACT_CONFIG );
Node start = graphDb.createNode();
Node end = graphDb.createNode();
RelationshipType type = withName( "REL" );
Relationship rel = start.createRelationshipTo( end, type );
index.add( rel, "Type", type.name() );
finishTx( true );
beginTx();
// WHEN
IndexHits<Relationship> hits = index.get( "Type", type.name(), start, end );
assertEquals( 1, count( (Iterator<Relationship>)hits ) );
assertEquals( 1, hits.size() );
index.remove( rel );
// THEN
hits = index.get( "Type", type.name(), start, end );
assertEquals( 0, count( (Iterator<Relationship>)hits ) );
assertEquals( 0, hits.size() );
}
示例9: createRelationship
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
/**
*
* @param properties
* @param labels
* @return
*/
public static long createRelationship(long startNodeId, long endNodeId, RelationshipType relationshipType, Map<String, Object> properties)
{
GraphDatabaseService graphDatabaseService = getGraphDatabaseService();
Node startNode = graphDatabaseService.getNodeById(startNodeId);
Node endNode = graphDatabaseService.getNodeById(endNodeId);
Relationship relationship = startNode.createRelationshipTo(endNode, relationshipType);
for (String key : properties.keySet())
{
relationship.setProperty(key, properties.get(key));
}
return relationship.getId();
}
示例10: getAdjacentNodes
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
public static Iterable<Node> getAdjacentNodes(final Node sourceNode, final RelationshipType relationshipType, final Direction direction, final Label targetNodeLabel) {
final Collection<Node> nodes = new ArrayList<>();
final Iterable<Relationship> relationships = sourceNode.getRelationships(relationshipType, direction);
for (final Relationship relationship : relationships) {
final Node candidate;
switch (direction) {
case INCOMING:
candidate = relationship.getStartNode();
break;
case OUTGOING:
candidate = relationship.getEndNode();
break;
default:
throw new UnsupportedOperationException("Direction: " + direction + " not supported.");
}
if (!candidate.hasLabel(targetNodeLabel)) {
continue;
}
nodes.add(candidate);
}
return nodes;
}
示例11: get
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
/**
* Finds relationship of given type between subject and object nodes.
*
* @return Relationship if exists or null.
*/
public Relationship get(Node subject, RelationshipType type, Node object) {
try {
// FIXME Use relationship index instead of iterating over all relationships
Iterable<Relationship> relations = subject.getRelationships(Direction.OUTGOING, type);
for(Relationship relation: relations) {
org.neo4j.graphdb.Node target = relation.getEndNode();
// Match object with target node in the existing triple
Iterable<Label> labels = object.getLabels();
for(Label label:labels) {
if(label.name().equals(NeoGraph.LABEL_LITERAL)) {
// Match literal value of object and target in existing triple
if(object.getProperty(NeoGraph.PROPERTY_VALUE).equals(target.getProperty(NeoGraph.PROPERTY_VALUE)))
return relation;
else return null;
}
}
// Now match URI of object and target in existing triple
// FIXME Blank Nodes?
if(object.getProperty(NeoGraph.PROPERTY_URI).equals(target.getProperty(NeoGraph.PROPERTY_URI)))
return relation;
}
} catch(RuntimeException exception) { }
return null;
}
示例12: createRelationship
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
@Override
public long createRelationship(long start, long end, RelationshipType type) {
Optional<Long> relationshipId = getRelationship(start, end, type);
if (relationshipId.isPresent()) {
return relationshipId.get();
} else {
try (Transaction tx = graphDb.beginTx()) {
Node startNode = graphDb.getNodeById(start);
Node endNode = graphDb.getNodeById(end);
Relationship relationship;
synchronized (graphLock) {
relationship = startNode.createRelationshipTo(endNode, type);
relationshipMap.put(start, end, type, relationship.getId());
}
tx.success();
return relationship.getId();
}
}
}
示例13: createRelationshipsPairwise
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
@Override
public Collection<Long> createRelationshipsPairwise(Collection<Long> nodeIds,
RelationshipType type) {
Set<Long> relationships = new HashSet<>();
for (Long start : nodeIds) {
for (Long end : nodeIds) {
if (start.equals(end)) {
continue;
} else {
if (!getRelationship(end, start, type).isPresent()) {
relationships.add(createRelationship(start, end, type));
}
}
}
}
return relationships;
}
示例14: createRelationshipsPairwise
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
@Override
public Collection<Long> createRelationshipsPairwise(Collection<Long> nodes, RelationshipType type) {
Set<Long> relationships = new HashSet<>();
for (Long start : nodes) {
for (Long end : nodes) {
if (start.equals(end)) {
continue;
} else {
synchronized (graphLock) {
if (!getRelationship(end, start, type).isPresent()) {
relationships.add(createRelationship(start, end, type));
}
}
}
}
}
return relationships;
}
示例15: processCategory
import org.neo4j.graphdb.RelationshipType; //導入依賴的package包/類
long processCategory(Node root, RelationshipType type, Direction direction, String category) {
long count = 0;
int batchSize = 100_000;
Label label = Label.label(category);
Transaction tx = graphDb.beginTx();
for (Path position : graphDb.traversalDescription().uniqueness(Uniqueness.NODE_GLOBAL)
.depthFirst().relationships(type, direction)
.relationships(OwlRelationships.RDF_TYPE, Direction.INCOMING)
.relationships(OwlRelationships.OWL_EQUIVALENT_CLASS, Direction.BOTH).traverse(root)) {
Node end = position.endNode();
GraphUtil.addProperty(end, Concept.CATEGORY, category);
end.addLabel(label);
if (0 == ++count % batchSize) {
logger.fine("Commiting " + count);
tx.success();
tx.close();
tx = graphDb.beginTx();
}
}
tx.success();
tx.close();
return count;
}