항목의 colluure지도 구문 분류 -> 카테고리 - 벡터 분류 된 목록으로
문제
키 문자열 항목이 들어있는 카테고리를 저장하는 항목 이름과 벡터의 벡터 이름과 벡터의 맵이 있습니다.이 맵을 구문 분석하려고 시도하고 있으므로 카테고리별로 구성 할 수 있습니다.
내가해야 할 일은 가능한 모든 카테고리와 하위 카테고리의 집합을 한 번 구문 분석하는 것입니다.일단 나는 그것을 반복하고 주요 맵에서 모든 일치를 필터링하여 적절한 키 문자열을 얻을 수 있습니다.
아래의지도에서 모든 주요 및 하위 카테고리의 세트로 어떻게 갈 수 있습니까?그 세트를 가지고 있으면 키가 아닌 값으로 원래지도를 쿼리하는 방법은 무엇입니까?
도움말셔서!
(def ITEM-CATEGORIES
{ "thingy" [["CatergoryA" "SubcategoryA"]]
"thingy2" [["FFT"]]
"thingy3" [["Generators" "Chaotic"]]
"thingy4" [["Analysis" "Pitch"] ["MachineListening"]]
"thingy5" [["Multichannel" "Ambisonics"]]
}
.
목표는 sudo 코드
(generate-hiccup-partial (create-set-of-unique-categories ITEM-CATEGORIES) ITEM-CATEGORIES)
....
(defpartial generate-hiccup-partial
[categories map]
;; hiccup code
(in-each-sub/main-category-get-keys-by-value categories map)) ;; return a list of all keys with the same categories
. 해결책
I do not know what a defpartial is, but this will transform that map:
(defn xform [ic]
(reduce (fn [result [k [vs]]]
(reduce (fn [r v]
(assoc r v (cons k (r v)))))
result vs))
{} ic))
user=> (xform ITEM-CATEGORIES)
{"SubcategoryA" ["thingy"], "CatergoryA" ["thingy"], "Ambisonics" ["thingy5"],
"Multichannel" ["thingy5"], "Pitch" ["thingy4"], "Analysis" ["thingy4"],
"Chaotic" ["thingy3"], "Generators" ["thingy3"], "FFT" ["thingy2"]}
다른 팁
When I find my self thinking about going up and down nested data structure my mind jumps to the zipper library you could take ITEM-CATECORIES and build a zipper of it then make any number of relations by 'zipping' up and down the tree.
제휴하지 않습니다 StackOverflow