简体   繁体   English

为什么地图关键字无法检索在地图中可以清楚看到的值?

[英]Why does the map key not retrieve the value that can be plainly seen in the map?

The following key :GIC-ID won't return its value "999-99-9999" . 以下密钥:GIC-ID不会返回其值"999-99-9999" I am trying to figure out why. 我试图找出原因。

Here are the keys -- the first row containing column names of a .csv report. 这些是键-第一行包含.csv报表的列名。 The output is formatted to prevent scrolling: 格式化输出以防止滚动:

["AGY/DIV " "STS" "GIC-ID     " "LAST-NAME      " "FIRST-NAME     " 
"COVERAGE DESCRIPTION                                   " 
"PREMIUM  " "RUN-DATE" "BIL MO "]

Here is the data doctored for privacy (output formatted to prevent scrolling): 这是为隐私而篡改的数据(格式化输出以防止滚动):

["666/0010" "ACT" "999-99-9999" "MARGE       " "SIMPSON          " 
"YE OLD PILGRIM FAMILY - INSURED                       " 
"0000.00" "123456789" "99999enter code here"]

I get the first column containing the keys/column headers and the data created with the following including the zipping together of the column names with what will be each row of data. 我得到的第一列包含键/列标题和使用以下内容创建的数据,包括将列名称与每个数据行压缩在一起。

(def gic-csv-inp (fetch-csv-data "billing_roster.csv"))
(def gic-csv-cols  (first gic-csv-inp))
(def gic-csv-data (rest gic-csv-inp))
(def zm2 (zipmap (map #(keyword %1) gic-csv-cols) (first gic-csv-data)))

Now the following keys and data, pulled from a similar but different report, work just fine: 现在,从相似但不同的报告中提取的以下键和数据就可以正常工作:

:Employee_SSN "999-99-9999"

That is I can extract the value of the key. 那就是我可以提取键的值。

There must be something wrong with the keys, and I can certainly correct those, like removing spaces and so on, but I am not sure what is wrong. 键肯定有问题,我当然可以纠正这些错误,例如删除空格等,但是我不确定什么地方出错了。

Thanks. 谢谢。

Edit: 编辑:

The answer to my question is to trim spaces like this: 我的问题的答案是像这样修剪空间:

(:require [clojure.string :as cstr])
.
.
.
(def zm2 (zipmap (map #(keyword (cstr/trim %1)) gic-csv-cols) 
(first gic-csv-data)))

Trimming spaces does work 修剪空间确实有效

(def zm2 (zipmap (map #(keyword (re-find #"[^\s]*" %1)) gic-csv-cols) (first gic-csv-data)))

=> (zm2 :GIC-ID)
"999-99-9999"

[^\\s]* being a regexp to match all non-whitespace characters [^ \\ s] *是一个正则表达式,可匹配所有非空白字符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM