Java Code Examples for org.neo4j.graphdb.Relationship#getProperty()

The following examples show how to use org.neo4j.graphdb.Relationship#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DDGPatcher.java    From EvilCoder with MIT License 5 votes vote down vote up
private void removeOldEdges(DDGDifference diff)
{
	List<DefUseRelation> relsToRemove = diff.getRelsToRemove();

	for (DefUseRelation rel : relsToRemove)
	{
		Node srcStatement = Neo4JDBInterface.getNodeById((Long) rel.src);

		Iterable<Relationship> rels = srcStatement
				.getRelationships(Direction.OUTGOING);

		for (Relationship reachRel : rels)
		{
			if (!reachRel.getType().name().equals(EdgeTypes.REACHES))
				continue;

			if (reachRel.getEndNode().getId() != (Long) rel.dst)
				continue;

			Object var = reachRel.getProperty("var");
			if (var == null || !var.toString().equals(rel.symbol))
				continue;

			Neo4JDBInterface.removeEdge(reachRel.getId());
		}
	}
}
 
Example 2
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
public static AbstractEdge convertRelationshipToEdge(Relationship relationship)
{
    AbstractEdge resultEdge = new Edge(convertNodeToVertex(relationship.getStartNode()), convertNodeToVertex(relationship.getEndNode()));
    for (String key : relationship.getPropertyKeys())
    {
        if(key.equals(PRIMARY_KEY) ||
                key.equals(CHILD_VERTEX_KEY) ||
                key.equals(PARENT_VERTEX_KEY))
        {
            continue;
        }
        Object value = relationship.getProperty(key);
        if (value instanceof String)
        {
            resultEdge.addAnnotation(key, (String) value);
        }
        else if (value instanceof Long)
        {
            resultEdge.addAnnotation(key, Long.toString((Long) value));
        }
        else if (value instanceof Double)
        {
            resultEdge.addAnnotation(key, Double.toString((Double) value));
        }
    }
    return resultEdge;
}
 
Example 3
Source File: DirectedModularity.java    From Neo4jSNA with Apache License 2.0 5 votes vote down vote up
@Override
public void compute(Relationship r) {
	Node n1 = r.getStartNode();
	Node n2 = r.getEndNode();
	
	if( n1.getProperty(attName) == n2.getProperty(attName) ) {
		double weight = r.hasProperty("weight") ? (double) r.getProperty("weight") : 1.0;
		eii += weight;
	}
}
 
Example 4
Source File: AbstractEmbeddedDBAccess.java    From jcypher with Apache License 2.0 5 votes vote down vote up
private RelationNodes init(Relationship relation) {
	RelationNodes ret = new RelationNodes();
	JsonObjectBuilder rel = Json.createObjectBuilder();
	rel.add("id", String.valueOf(relation.getId()));
	RelationshipType typ = relation.getType();
	if (typ != null)
		rel.add("type", typ.name());
	Node sn = relation.getStartNode();
	if (sn != null) {
		rel.add("startNode", String.valueOf(sn.getId()));
		ret.startNode = sn;
	}
	Node en = relation.getEndNode();
	if (en != null) {
		rel.add("endNode", String.valueOf(en.getId()));
		ret.endNode = en;
	}
	JsonObjectBuilder props = Json.createObjectBuilder();
	Iterator<String> pit = relation.getPropertyKeys().iterator();
	while (pit.hasNext()) {
		String pKey = pit.next();
		Object pval = relation.getProperty(pKey);
		writeLiteral(pKey, pval, props);
	}
	rel.add("properties", props);
	this.relationObject = rel;
	return ret;
}
 
Example 5
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 4 votes vote down vote up
public Set<QueriedEdge> readEdgeSet(String relationshipAliasInQuery, String query){
		Set<QueriedEdge> edgeSet = new HashSet<QueriedEdge>();
		try(Transaction tx = graphDb.beginTx()){
//			globalTxCheckin();
			try{
				Result result = graphDb.execute(query);
				Iterator<Relationship> relationships = result.columnAs(relationshipAliasInQuery);
				while(relationships.hasNext()){
					Relationship relationship = relationships.next();
					Object childVertexHashObject = relationship.getProperty(CHILD_VERTEX_KEY);
					String childVertexHashString = childVertexHashObject == null ? null
							: childVertexHashObject.toString();
					Object parentVertexHashObject = relationship.getProperty(PARENT_VERTEX_KEY);
					String parentVertexHashString = parentVertexHashObject == null ? null
							: parentVertexHashObject.toString();
					Object edgeHashObject = relationship.getProperty(PRIMARY_KEY);
					String edgeHashString = edgeHashObject == null ? null
							: edgeHashObject.toString();
					Map<String, String> annotations = new HashMap<String, String>();
					for(String key : relationship.getPropertyKeys()){
						if(!HelperFunctions.isNullOrEmpty(key)){
							if(key.equalsIgnoreCase(PRIMARY_KEY) || key.equalsIgnoreCase(CHILD_VERTEX_KEY)
									|| key.equalsIgnoreCase(PARENT_VERTEX_KEY)
									|| key.equalsIgnoreCase(edgeSymbolsPropertyKey)){
								// ignore
							}else{
								Object annotationValueObject = relationship.getProperty(key);
								String annotationValueString = annotationValueObject == null ? ""
										: annotationValueObject.toString();
								annotations.put(key, annotationValueString);
							}
						}
					}
					edgeSet.add(new QueriedEdge(edgeHashString, childVertexHashString, parentVertexHashString, annotations));
				}
			}catch(QueryExecutionException ex){
				logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
			}finally{
				tx.success();
			}
		}
		return edgeSet;
	}