flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vasia <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-1741][gelly] Adds Jaccard Similarity Me...
Date Mon, 30 Mar 2015 16:53:43 GMT
Github user vasia commented on a diff in the pull request:

    https://github.com/apache/flink/pull/544#discussion_r27408463
  
    --- Diff: flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/JaccardSimilarityMeasureExample.java
---
    @@ -0,0 +1,207 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.graph.example;
    +
    +import org.apache.flink.api.common.ProgramDescription;
    +import org.apache.flink.api.common.functions.MapFunction;
    +import org.apache.flink.api.java.DataSet;
    +import org.apache.flink.api.java.ExecutionEnvironment;
    +import org.apache.flink.api.java.tuple.Tuple2;
    +import org.apache.flink.api.java.tuple.Tuple3;
    +import org.apache.flink.graph.Edge;
    +import org.apache.flink.graph.EdgeDirection;
    +import org.apache.flink.graph.Graph;
    +import org.apache.flink.graph.Vertex;
    +import org.apache.flink.graph.NeighborsFunction;
    +import org.apache.flink.graph.Triplet;
    +import org.apache.flink.graph.example.utils.JaccardSimilarityMeasureData;
    +import org.apache.flink.types.NullValue;
    +
    +import java.util.HashSet;
    +import java.util.Iterator;
    +
    +/**
    + * Given an undirected, unweighted graph,return a weighted graph where the edge values
are equal
    + * to the Jaccard similarity coefficient - the number of common neighbors divided by
the total number
    + * of neighbors - for the src and target vertices.
    + *
    + * <p>
    + * Input files are plain text files and must be formatted as follows:
    + * <br>
    + * 	Edges are represented by pairs of srcVertexId, trgVertexId separated by tabs.
    + * 	Edges themselves are separated by newlines.
    + * 	For example: <code>1	2\n1	3\n</code> defines two edges 1-2 and 1-3.
    + * </p>
    + *
    + * Usage <code> JaccardSimilarityMeasureExample &lt;edge path&gt; &lt;result
path&gt;</code><br>
    + * If no parameters are provided, the program is run with default data from
    + * {@link org.apache.flink.graph.example.utils.JaccardSimilarityMeasureData}
    + */
    +@SuppressWarnings("serial")
    +public class JaccardSimilarityMeasureExample implements ProgramDescription {
    +
    +	public static void main(String [] args) throws Exception {
    +
    +		if(!parseParameters(args)) {
    +			return;
    +		}
    +
    +		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    +
    +		DataSet<Edge<Long, Double>> edges = getEdgesDataSet(env);
    +
    +		Graph<Long, NullValue, Double> graph = Graph.fromDataSet(edges, env);
    +		// undirect the graph
    +		Graph<Long, NullValue, Double> undirectedGraph = graph.getUndirected();
    +
    +		DataSet<Vertex<Long, HashSet<Long>>> verticesWithNeighbors =
    +				undirectedGraph.reduceOnNeighbors(new GatherNeighbors(), EdgeDirection.ALL);
    --- End diff --
    
    If you have a directed graph, `EdgeDirection.ALL` will give you all neighbors (in-coming
and out-going). If you have an undirected graph, then this will return them twice..


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message