Skip to content

Instantly share code, notes, and snippets.

View okram's full-sized avatar
🏠
Working from home

Marko A. Rodriguez okram

🏠
Working from home
View GitHub Profile
package com.tinkerpop.blueprints.util;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.TransactionalGraph;
import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
public interface MetaGraph<G, V, E> extends Graph {
/**
* Get the raw underlying graph engine that exposes the Blueprints API.
*
* @return the raw underlying graph engine
*/
public G getRawGraph();
public V getRawVertex(Vertex vertex);
,
, |\ ,__
|\ \/ `\
\ `-.:. `\
`-.__ `\/\/\|
/ `'/ () \
.' /\ )
.-' .'| \' \__
.' __( \ '`(()
/_.'` `. | )(
public static class Map extends Mapper<NullWritable, LongWritable, NullWritable, NullWritable> {
private TitanGraph graph;
@Override
public void setup(final Mapper.Context context) throws IOException, InterruptedException {
this.graph = TitanFactory.open(context.get("titanConfiguration"));
}
@Override
public static class Map extends Mapper<ByteBuffer, SortedMap<ByteBuffer, IColumn>, Text, Text> {
@Override
public void map(final ByteBuffer key, final SortedMap<ByteBuffer, IColumn> value, final Mapper<ByteBuffer, SortedMap<ByteBuffer, IColumn>, Text, Text>.Context context) throws IOException, InterruptedException {
final StringBuffer string = new StringBuffer();
for (java.util.Map.Entry<ByteBuffer, IColumn> entry : value.entrySet()) {
string.append(ByteBufferUtil.string(entry.getKey())).append("\t").append(ByteBufferUtil.string(entry.getValue().value()));
}
context.write(new Text(ByteBufferUtil.string(key, Charset.forName("UTF-8"))), new Text(string.toString()));
private static FaunusVertex createFaunusVertex(final Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>> row) {
final FaunusVertex vertex = new FaunusVertex(1l);
try {
for (final java.util.Map.Entry<ByteBuffer, IColumn> entry : row.right.entrySet()) {
vertex.setProperty(ByteBufferUtil.string(entry.getKey()), ByteBufferUtil.string(entry.getValue().value()));
}
} catch (Exception e) {
}
return vertex;
}
arguments to pass in:
twitterId
traversals
numRecommendations
///////////////////////////
// this function will return an ordered collection
// one thing to optimize is to return the map, not the set of vertices (this is more information and faster)
// to do so, "return [:]" and no ".keySet()" on last line.
g = new Neo4jGraph('/graph/neo4pedia2')
counter = 0;
for(final Vertex v : g.V()) {
v.toString()
for(Edge e: v.getEdges(BOTH)) {
e.toString()
}
if((counter++ % 500) == 0) {
println("vertices parsed: " + counter);
}
public Iterator<Neo4jEdge> iterator() {
final Iterator<Relationship> itty;
if (labels.length > 0)
itty = node.getRelationships(direction, labels).iterator();
else
itty = node.getRelationships(direction).iterator();
return new Iterator<Neo4jEdge>() {
public Neo4jEdge next() {
return new Neo4jEdge(itty.next(), graph);
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
boolean isNext;
try {
this.vertex.readFields(this.rexsterInputStream);
this.value.enablePath(this.pathEnabled);
itemsIterated++;
isNext = true;
} catch (Exception e) {