How to use the gremlin.v function in gremlin

To help you get started, we’ve selected a few gremlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
me.getPath = function(id, callback){
		var all = gremlin.v(id).inE().outV().inE().outV().path().toJSON();
		callback(all.error, all);
	};
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
me.del = function(id, callback){
		var vertex = gremlin.v(id).iterator().nextSync();
		var error = false;
		if (vertex) {
			vertex.removeSync();
			graphDB.commitSync();
		} else { 
			error = true;
		}
		
		callback(error, {_id: id});
	};
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
me.addEdge = function(object, callback) {
		var v1 = gremlin.v(object.source_id).iterator().nextSync();
		var v2 = gremlin.v(object.target_id).iterator().nextSync();
		var rel = graphDB.addEdgeSync(null, v1, v2, object._label);
		object._titan_id = gremlin.e(rel).toJSON()[0]._id;
		graphDB.commitSync();
		
		if (callback) {
			callback(null, object);
		}
	};
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
me.compareAll = function(id, callback){
		id = parseInt(id, 10);
		var alphas = gremlin.V().has('name', 'alpha report').toJSON();
		var targets = gremlin.V().has('name', 'target event').toJSON();
		var all = alphas.concat(targets);
		var a_json = gremlin.v(id).toJSON()[0];
		
		//gremlin.v(id).iterator().nextSync().setPropertySync('comparedTo', []);
		//graphDB.commitSync();
		var comparedTo = a_json.comparedTo;
		
		async.each(all, function(d, itCallback) {
			var score = 0.0;
			//gremlin.v(d._id).iterator().nextSync().setPropertySync('comparedTo', []);
			//graphDB.commitSync();
			if (indexOfId(comparedTo, d._id) === -1){
				var d_comparedTo = gremlin.v(d._id).toJSON()[0].comparedTo;
				var ar_nodes = gremlin.v(id).inE().outV().toJSON();
				var d_nodes = gremlin.v(d._id).inE().outV().toJSON();
				
				var ar_edges = gremlin.v(id).inE().outV().inE().toJSON();
				var d_edges = gremlin.v(d._id).inE().outV().inE().toJSON();
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
me.addEdge = function(object, callback) {
		var v1 = gremlin.v(object.source_id).iterator().nextSync();
		var v2 = gremlin.v(object.target_id).iterator().nextSync();
		var rel = graphDB.addEdgeSync(null, v1, v2, object._label);
		object._titan_id = gremlin.e(rel).toJSON()[0]._id;
		graphDB.commitSync();
		
		if (callback) {
			callback(null, object);
		}
	};
github NextCenturyCorporation / EVEREST / services / database / titan-graph.js View on Github external
gremlin.v(d._id).iterator().nextSync().setPropertySync('comparedTo', d_comparedTo);
		  	  	graphDB.commitSync();	
	  	  	}
		});
		var parsed = [];
		comparedTo.sort(function(a,b){
			var ja = JSON.parse(a);
			var jb = JSON.parse(b);
			if (jb.score === ja.score){
				return ja.item_id - jb.item_id;
			} else {
				return jb.score - ja.score;
			}
		});
		
		gremlin.v(ar_id).iterator().nextSync().setPropertySync('comparedTo', comparedTo);
		graphDB.commitSync();
		
		comparedTo.forEach(function(d){
			parsed.push(JSON.parse(d));
		});
		return parsed;
	};
};
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
async.each(all, function(d, itCallback) {
			var score = 0.0;
			//gremlin.v(d._id).iterator().nextSync().setPropertySync('comparedTo', []);
			//graphDB.commitSync();
			if (indexOfId(comparedTo, d._id) === -1){
				var d_comparedTo = gremlin.v(d._id).toJSON()[0].comparedTo;
				var ar_nodes = gremlin.v(id).inE().outV().toJSON();
				var d_nodes = gremlin.v(d._id).inE().outV().toJSON();
				
				var ar_edges = gremlin.v(id).inE().outV().inE().toJSON();
				var d_edges = gremlin.v(d._id).inE().outV().inE().toJSON();
				
				var ar_asserts = gremlin.v(id).inE().outV().inE().outV().path().toJSON();
				var d_asserts = gremlin.v(d._id).inE().outV().inE().outV().path().toJSON();
				
				if (ar_nodes.length === d_nodes.length){
					score = score + 1.0;
				}
				
				if (ar_edges.length === d_edges.length){
					score = score + 1.0;
				}
				
				if (d_nodes.length !== 0 && ar_nodes.length !== 0){
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
async.each(all, function(d, itCallback) {
			var score = 0.0;
			//gremlin.v(d._id).iterator().nextSync().setPropertySync('comparedTo', []);
			//graphDB.commitSync();
			if (indexOfId(comparedTo, d._id) === -1){
				var d_comparedTo = gremlin.v(d._id).toJSON()[0].comparedTo;
				var ar_nodes = gremlin.v(id).inE().outV().toJSON();
				var d_nodes = gremlin.v(d._id).inE().outV().toJSON();
				
				var ar_edges = gremlin.v(id).inE().outV().inE().toJSON();
				var d_edges = gremlin.v(d._id).inE().outV().inE().toJSON();
				
				var ar_asserts = gremlin.v(id).inE().outV().inE().outV().path().toJSON();
				var d_asserts = gremlin.v(d._id).inE().outV().inE().outV().path().toJSON();
				
				if (ar_nodes.length === d_nodes.length){
					score = score + 1.0;
				}
				
				if (ar_edges.length === d_edges.length){
					score = score + 1.0;
				}
				
				if (d_nodes.length !== 0 && ar_nodes.length !== 0){
					var ar_v_matches = me.getMatchingVertices(id, d_nodes);
					score += ar_v_matches.length / d_nodes.length;
github NextCenturyCorporation / EVEREST / services / database / titan_graph.js View on Github external
if (object.type === 'metadata') {
			v.setPropertySync('comparedTo', []);
		}
		
		//async.each(keys, function(k){
		keys.forEach(function(k){
			if (object[k]){
				if (k === '_id'){
					v.setPropertySync(id_replace, object[k]);
				} else {
					v.setPropertySync(k, object[k]);
				}
			}
		});
		
		object._titan_id = gremlin.v(v).toJSON()[0]._id; 
		graphDB.commitSync();

		if (callback) {
			callback(null, object);
		}

		return v;
	};
github NextCenturyCorporation / EVEREST / services / database / titan-graph.js View on Github external
var d_matches = me.getMatchingOrientation(d._id, ar_asserts);
					score += d_matches.length / ar_asserts.length;
				}
				
				comparedTo.push(JSON.stringify({
					item_id: d._id,
					score: 100 * score / 8
				}));
				
				d_comparedTo.push(JSON.stringify({
					item_id: ar_id,
					score: 100 * score / 8
				}));
								
				gremlin.v(d._id).iterator().nextSync().setPropertySync('comparedTo', d_comparedTo);
		  	  	graphDB.commitSync();	
	  	  	}
		});
		var parsed = [];