我使用
将Clojure地图持久保存到文件中using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;
public void Main()
{
// GET NAME OF FIRST SHEET
string filename = Dts.Variables["User::ActiveFileName"].Value.ToString();
string sheetName = null;
bool dummy = true;
string connStr =
String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"EXCEL 12.0 XML;HDR=YES\";", filename);
var conn = new OleDbConnection(connStr);
try
{
conn.Open();
using(var dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null))
{
var row0 = dtSheet.Rows[0];
sheetName = row0["TABLE_NAME"].ToString();
}
if (!String.IsNullOrEmpty(sheetName))
{
Dts.Variables["SheetName"].Value = sheetName;
Dts.Events.FireInformation(1, "User::SheetName", sheetName, "", 0, ref dummy);
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
throw new Exception("No SheetName found!");
}
}
catch (Exception ex)
{
Dts.Events.FireError(0, "User::SheetName", ex.Message, String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
finally
{
conn.Close();
conn.Dispose();
}
}
其中(spit (str tmpdir "/" "results.edn") (.toString c))
是一个非常大的哈希映射(文件是201MB)。地图的键是字符串,值是数字。
当我尝试从文件中读回地图时,我收到了重复的密钥异常。以下是我试图在
中阅读的方法c
当地图写入edn文件时,地图如何以重复键结束?有什么想法吗?
以下是例外之处:
(def phrases (edn/read
(PushbackReader.
(io/reader
"/tmp/mednotes8910030368496690883/results.edn"))))
根据要求,以下是地图中的内容示例:
Caused by java.lang.IllegalArgumentException
Duplicate key: ? 5
PersistentHashMap.java: 67 clojure.lang.PersistentHashMap/createWithCheck
RT.java: 1538 clojure.lang.RT/map
EdnReader.java: 631 clojure.lang.EdnReader$MapReader/invoke
EdnReader.java: 142 clojure.lang.EdnReader/read
EdnReader.java: 108 clojure.lang.EdnReader/read
edn.clj: 35 clojure.edn/read
edn.clj: 33 clojure.edn/read
AFn.java: 154 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
@ fl00r在评论中建议grep results.edn文件为字符串"? 5&#34 ;.使用egrep在此字符串之前和之后显示20个字符,我使用该键获得4个条目:
{"cervical region of" 32,
"partial brachial" 64,
"is an effective medication for" 32,
", as stopping them" 32,
", supportive treatment" 160,
"should be eating a normal" 128,
"o call back if supplement" 32,
"diagnosiscod diabc }" 32,
"days in case of allergies" 32,
"ointment 8 drops" 32,
"leg from pinched" 32,
...
有趣的是,4个中的3个具有完全相同的计数。仍然不确定如果从一张看似不太好的地图上写下这样的重复,这怎么会发生呢。