コード例 #1
0
    @Override
    public Vertex<LongWritable, LongWritable, LongWritable> getCurrentVertex()
        throws IOException, InterruptedException {
      Vertex<LongWritable, LongWritable, LongWritable> vertex = conf.createVertex();
      String tokens[] = saperator.split(getRecordReader().getCurrentValue().toString());
      List<Edge<LongWritable, LongWritable>> edges =
          Lists.newArrayListWithCapacity(tokens.length - 1);
      long weight = ((long) 1.0) / (tokens.length - 1);

      LongWritable VertexId = new LongWritable(Long.parseLong(tokens[0]));
      LongWritable VertexValue = new LongWritable(Long.parseLong(tokens[1]));
      System.out.println(VertexValue);

      String edgeId[] = tokens[2].split(",");
      /*
      for(int n=2;n<tokens.length-1;n++)
      {
      	edges.add(EdgeFactory.create(new LongWritable(Long.parseLong(tokens[n])),new LongWritable(weight)));
      }
      */
      for (String edge : edgeId) {
        edges.add(
            EdgeFactory.create(new LongWritable(Long.parseLong(edge)), new LongWritable(weight)));
      }

      //	vertex.initialize(VertexId, (LongWritable) edges);
      vertex.initialize(VertexId, VertexValue, edges);
      return vertex;
    }
コード例 #2
0
    @Override
    public Vertex<LongWritable, DoubleWritable, FloatWritable> getCurrentVertex()
        throws IOException, InterruptedException {
      Vertex<LongWritable, DoubleWritable, FloatWritable> vertex = conf.createVertex();

      String[] tokens = neighborSeparator.split(getRecordReader().getCurrentValue().toString());
      List<Edge<LongWritable, FloatWritable>> edges =
          Lists.newArrayListWithCapacity(tokens.length - 1);

      for (int n = 1; n < tokens.length; n++) {
        String[] parts = weightSeparator.split(tokens[n]);
        edges.add(
            EdgeFactory.create(
                new LongWritable(Long.parseLong(parts[0])),
                new FloatWritable(Float.parseFloat(parts[1]))));
      }

      LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
      vertex.initialize(vertexId, new DoubleWritable(), edges);

      return vertex;
    }
コード例 #3
0
 @Override
 public Vertex<LongWritable, VertexDataStructure, FloatWritable> getCurrentVertex()
     throws IOException, InterruptedException {
   Text line = getRecordReader().getCurrentValue();
   Vertex<LongWritable, VertexDataStructure, FloatWritable> vertex = getConf().createVertex();
   try {
     JSONArray jsonVertex = new JSONArray(line.toString());
     vertex.initialize(
         new LongWritable(jsonVertex.getLong(0)),
         new VertexDataStructure(jsonVertex.getLong(1), new HashSet<Long>()));
     JSONArray jsonEdgeArray = jsonVertex.getJSONArray(2);
     for (int i = 0; i < jsonEdgeArray.length(); ++i) {
       JSONArray jsonEdge = jsonEdgeArray.getJSONArray(i);
       Edge<LongWritable, FloatWritable> edge =
           EdgeFactory.create(
               new LongWritable(jsonEdge.getLong(0)),
               new FloatWritable((float) jsonEdge.getDouble(1)));
       vertex.addEdge(edge);
     }
   } catch (JSONException e) {
     throw new IllegalArgumentException("next: Couldn't get vertex from line " + line, e);
   }
   return vertex;
 }