Package edu.ucla.sspace.graph

Examples of edu.ucla.sspace.graph.SparseWeightedGraph$SubgraphAdaptor


    @Override public WeightedGraph<WeightedEdge> readWeighted(
            File f, Indexer<String> vertexIndexer) throws IOException {       

        BufferedReader br = new BufferedReader(new FileReader(f));
        WeightedGraph<WeightedEdge> g = new SparseWeightedGraph();
        int lineNo = 0;
        for (String line = null; (line = br.readLine()) != null; ) {
            ++lineNo;
            line = line.trim();
            if (line.startsWith("#"))
                continue;
            else if (line.length() == 0)
                continue;
            String[] arr = line.split("\\s+");
            if (arr.length < 2)
                throw new IOException("Missing vertex on line " + lineNo);
            if (arr.length < 3)
                throw new IOException("Missing edge weight on line " + lineNo);
            int v1 = vertexIndexer.index(arr[0]);
            int v2 = vertexIndexer.index(arr[1]);
            double weight = Double.parseDouble(arr[2]);
            g.add(new SimpleWeightedEdge(v1, v2, weight));

            if (lineNo % 10000 == 0)
                veryVerbose(LOGGER, "Read %d lines from %s", lineNo, f);
        }
        verbose(LOGGER, "Read directed graph with %d vertices and %d edges",
                g.order(), g.size());
        return g;
    }
View Full Code Here


    @Override public WeightedGraph<WeightedEdge> readWeighted(
            File f, Indexer<String> vertexIndexer, double minWeight) throws IOException {       

        BufferedReader br = new BufferedReader(new FileReader(f));
        WeightedGraph<WeightedEdge> g = new SparseWeightedGraph();
        int lineNo = 0;
        for (String line = null; (line = br.readLine()) != null; ) {
            ++lineNo;
            line = line.trim();
            if (line.startsWith("#"))
                continue;
            else if (line.length() == 0)
                continue;
            String[] arr = line.split("\\s+");
            if (arr.length < 2)
                throw new IOException("Missing vertex on line " + lineNo);
            if (arr.length < 3)
                throw new IOException("Missing edge weight on line " + lineNo);
            int v1 = vertexIndexer.index(arr[0]);
            int v2 = vertexIndexer.index(arr[1]);
            double weight = Double.parseDouble(arr[2]);
            if (weight >= minWeight)
                g.add(new SimpleWeightedEdge(v1, v2, weight));

            if (lineNo % 100000 == 0)
                veryVerbose(LOGGER, "Read %d lines from %s", lineNo, f);
        }
        verbose(LOGGER, "Read directed graph with %d vertices and %d edges",
                g.order(), g.size());
        return g;
    }
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.graph.SparseWeightedGraph$SubgraphAdaptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.