2013-04-02 23 views

回答

1

mbostock/d3 gallery有Carrot2輸出良好的視覺效果。

This carrot2-rb Carrot2的ruby客戶端返回一個帶有簇數組的對象。分數和短語屬性可以在簡單的圓環圖中使用。

像flare.json這樣的樹狀結構可以實現更多動態可視化,例如可擴展樹形圖。

這是根據Carrot2結果的zoomable wheel

這是我寫的使用文檔元素創建flare.json的咖啡代碼。

clusters = [{"id":0,"size":3,"phrases":["Coupon"],"score":0.06441151442396735,"documents":["0","1","2"],"attributes":{"score":0.06441151442396735}},{"id":1,"size":2,"phrases":["Exclusive"],"score":0.7044284368639101,"documents":["0","1"],"attributes":{"score":0.7044284368639101}},{"id":2,"size":1,"phrases":["Other Topics"],"score":0.0,"documents":["3"],"attributes":{"other-topics":true,"score":0.0}}] 

flare = get_flare clusters 

get_children = (index, index2, clusters, documents) ->unless index == (clusters.length - 1) # If not last cluster 
    orphans = {'name': ''} 
    intr = _.intersection(documents, clusters[index2].documents);  

    if intr.length > 0 # continue drilling 
    if index2 < (clusters.length - 1) # Up until last element. 
     # Get next layer of orphans 
     orphan_docs = _.difference(intr, clusters[index2 + 1].documents) 
     if orphan_docs.length > 0 
     orphans = {'name': orphan_docs, 'size': orphan_docs.length} 

     if _.intersection(intr, clusters[index2 + 1].documents).length > 0 
     return [orphans, {'name': clusters[index2+1].phrases[0], 'children': get_children(index, (index2 + 1), clusters, intr)}] 
     else 
     return [orphans] 
    else 
     # At second to last cluster, so terminate here 
     return [{'name': inter}] 
    else        # No intersection, so return bundle of current documents. 
    return [{'name': documents}] 

    return [{'name': _.intersection(clusters[index].documents, clusters[index2].documents)}] 



get_flare = (clusters) -> 
    # Make root object 
    flare = 
    name: "root" 
    children: [] 

    children = flare.children 
    _.each(clusters[0..(clusters.length - 2)], (cluster, index) -> # All clusters but the last. (It has already been compared to previous ones) 
    #All documents for all remaining clusters in array 
    remaining_documents = _.flatten(_.map clusters[(index + 1)..clusters.length], (c) -> 
     c.documents 
    ) 

    root_child = {'name': cluster.phrases[0], 'children': []} 

    # Get first layer of orphans 
    orphan_docs = _.difference(cluster.documents, remaining_documents) 

    if orphan_docs.length > 0 
     root_child.children.push {'name': orphan_docs, size: orphan_docs.length} 

    for index2 in [(index + 1)..(clusters.length - 1)] by 1 
     if _.intersection(cluster.documents, clusters[index2].documents).length > 0 
     root_child.children.push {'name': clusters[index2].phrases[0], 'children': get_children(index, (index2), clusters, cluster.documents)} 

    children.push root_child 
) 
    flare