コード例 #1
0
 def __init__(self, filename=None, delimiter=None):
     self._e = 0
     self._adj = dict()
     if filename is not None:
         instream = InStream(filename)
         while instream.hasNextLine():
             line = instream.readLine()
             names = line.split(delimiter)
             for i in range(1, len(names)):
                 self.addEdge(names[0], names[i])
コード例 #2
0
ファイル: graph.py プロジェクト: davidhuizhou/python
 def __init__(self, filename=None, delimiter=None):
     self._e = 0
     self._adj = dict()
     if filename is not None:
         instream = InStream(filename)
         while instream.hasNextLine():
             line = instream.readLine()
             names = line.split(delimiter)
             for i in range(1, len(names)):
                 self.addEdge(names[0], names[i])
コード例 #3
0
fileName = sys.argv[1]
fieldCount = int(sys.argv[2])

# Create the input stream.
inStream = InStream(fileName + '.csv')

# Create output streams.
outStreams = stdarray.create1D(fieldCount)
for i in range(fieldCount):
    file = OutStream(fileName + str(i) + '.txt')
    outStreams[i] = file

# Read lines from the input stream and write them to the
# output stream.
while inStream.hasNextLine():
    line = inStream.readLine()
    fields = line.split(DELIM)
    for i in range(fieldCount):
        outStreams[i].writeln(fields[i])

#-----------------------------------------------------------------------

# more djia.csv
# Date,Open,High,Low,Close,Volume,Adj. Close*
# 17-Mar-06,11294.94,11294.94,11253.23,11279.65,2549619968,11279.65
# 16-Mar-06,11210.97,11324.80,11176.07,11253.24,2292179968,11253.24
# 15-Mar-06,11149.76,11258.28,11097.23,11209.77,2292999936,11209.77
# ...

# python split.py djia 3
コード例 #4
0
ファイル: performer.py プロジェクト: davidhuizhou/python
from graph import Graph
from instream import InStream

# Accept the name of a movie-cast file and a delimiter as command-line
# arguments and create the associated performer-performer graph. Write
# to standard output the number of vertices, the average degree, 
# the average path length, and the clustering coefficient of the graph.
# Assume that the performer-performer graph is connected so that the
# average page length is defined.

file      = sys.argv[1]
delimiter = sys.argv[2]

graph = Graph()
instream = InStream(file)
while instream.hasNextLine():
    line = instream.readLine()
    names = line.split(delimiter)
    for i in range(1, len(names)):
        for j in range(i+1, len(names)):
            graph.addEdge(names[i], names[j])

degree  = smallworld.averageDegree(graph)
length  = smallworld.averagePathLength(graph)
cluster = smallworld.clusteringCoefficient(graph)

stdio.writef('number of vertices     = %d\n', graph.countV())
stdio.writef('average degree         = %7.3f\n', degree)
stdio.writef('average path length    = %7.3f\n', length)
stdio.writef('clustering coefficient = %7.3f\n', cluster)
コード例 #5
0
from graph import Graph
from instream import InStream

# Accept the name of a movie-cast file and a delimiter as command-line
# arguments and create the associated performer-performer graph. Write
# to standard output the number of vertices, the average degree,
# the average path length, and the clustering coefficient of the graph.
# Assume that the performer-performer graph is connected so that the
# average page length is defined.

file = sys.argv[1]
delimiter = sys.argv[2]

graph = Graph()
instream = InStream(file)
while instream.hasNextLine():
    line = instream.readLine()
    names = line.split(delimiter)
    for i in range(1, len(names)):
        for j in range(i + 1, len(names)):
            graph.addEdge(names[i], names[j])

degree = smallworld.averageDegree(graph)
length = smallworld.averagePathLength(graph)
cluster = smallworld.clusteringCoefficient(graph)

stdio.writef('number of vertices     = %d\n', graph.countV())
stdio.writef('average degree         = %7.3f\n', degree)
stdio.writef('average path length    = %7.3f\n', length)
stdio.writef('clustering coefficient = %7.3f\n', cluster)