【发布时间】:2014-09-20 08:03:40
【问题描述】:
我正在尝试格式化数据文件,以便我的其他程序能够正确处理它。我正在尝试处理以下数据,但遇到了一个非常奇怪的错误,我似乎无法解决。
https://snap.stanford.edu/data/wiki-RfA.html
我正在尝试将数据格式化为 [SRC TGT VOT],所以我希望输出文件的前两行是
1 2 1
3 2 1
因为用户 1(首先存储在用户字典中)用 VOT 1 投票给用户 2,然后用户 3 用 VOT 1 投票给用户 2。我的问题是,当我尝试在下面运行我的代码时,我总是以收到一个非常奇怪的“无效的 ascii 序列”错误 - 谁能帮我确定问题或找到解决方法?如果我能知道我做错了什么显然是最好的。谢谢! 请注意,我知道这是一个有点具体的问题,我感谢任何帮助 - 我对这个错误感到困惑,目前不知道如何解决它。
f=open("original_vote_data.txt") #this is the file linked above
arr=readlines(f)
i=edge_count=src=tgt=vot=1
dict=Dict{ASCIIString, Int64}()
edges=["" for k=1:198275]
while i<1586200
src_temp=(arr[i])[5:end-2]
if (haskey(dict, src_temp))
new_src= dict[src_temp]
else
dict[src_temp]=src
new_src=src
src=src+1
end
tgt_temp=(arr[i+1])[5:end-2]
if (haskey(dict, tgt_temp))
new_tgt= dict[tgt_temp]
else
dict[tgt_temp]=tgt
new_tgt=tgt
tgt=tgt+1
end
vot_temp=(arr[i+2])[5]
edges[edge_count]=string(new_src)* " " * string(new_tgt)* " " *string(vot_temp)
edge_count=edge_count+1
i=i+8
end
【问题讨论】:
-
我没有仔细看这个,但我的预感在第四行:
dict=Dict{ASCIIString, Int64}。这是用户名所在的位置吗?用户名有时是 unicode 吗?也许试试Dict{UTF8String, Int64}。边缘也类似——试试edges=Array(UTF8String,198275)。 -
谢谢!我的延迟很长,但我明天会试试这个。希望你是对的!
-
@user3587051 你的问题解决了吗?
-
@Jubobs 是的,谢谢!