计算语言学基础

2020-07-26 04:11:57

(Defn Render-Vega([spec elem](When spec(让[spec(CLJ-&>;js spec)opts{:renderer";canvas";:mode";Vega";:action{:export true,:source true,:piled true,:Editor true}}])(->;(js/vegaEmbed elem spec(clj->;js opts))(.Th.Thration{:export true,:source true,:Editor true}}](->;(js/vegaEmbed elem spec(clj->;js opts))。Js/vegaToolTip(Vega(.-view res)spec)(.catch(fn[err](.log js/console err)(定义呈现Vega";[spec](r/create-class{:display-name";Vega";用法:component-DID-mount(fn[this](Render-Vega spec(r/dom-node this):component-will-update(fn[this[_new-spec]](Render-Vega new-spec(r/dom-node this):agent-Render(fn[spec][:div#vis])});从观测列表制作直方图(Defn list-to-hist-spec[l]";&#。获取列表并以正确格式返回织女星数据的记录,每个列表元素都将标签添加到名为';x';";";(defRecord rec[Element]){:Values(Into[](MAP-&>;rec l))}))(Defn Makehist[Data]{:$Schema";https://vega.github.io/schema/vega-lite/v4.json";,:Data Data,:mark";bar";,:Coding{:x{:field";element";,:type";序号";},:y{:Aggregate";count";,:type";Quantity";}})(Defn hist[l](Vega(makehist(list-to-hist-spec l);用于绘制条形图(Defn list-to-barlot-data[l m]";&#。获取一个列表并以正确格式返回织女星数据的记录,每个列表元素都将标签添加到名为';x';";";(defRecord rec[元素值]){:VALUES(INTO[](MAP-&>;rec l m))})})(Defn make barlot[Data]{:$Schema";https://vega.github.io/schema/vega-lite/v4.json";,:Data Data,:mark";Bar";,:coding{:x{:field";element";,:type";equal";},:y{:field";value";,:type";Quantity";})(Defn barlot[l m](Vega(makebarlot(list-to-barlot-data l m);现在,用于树的制作;(感谢Taylor Wood在此线程中的回答。Https://stackoverflow.com/questions/57911965)(Defn list-to-tree-spec[l]";";";";)获取列表并遍历它(使用clojure.zip库),并为Vega";";";(LOOP[loc(z/seq-zip l),Next-id0,Parent-IDs[],acc[]](cond(z/end?Loc)acc(和(z/节点loc)(不是(z/分支?Loc)(recur(z/next loc)(Inc next-id)(cond(某些->;(z/right loc)z/Branch?)。(conj Parent-IDs Next-id)(NOT(z/right loc))(ome->;Parent-ID非空POP):ELSE Parent-IDs)(conj acc{:id(str Next-id):name(str(z/node loc):Parent(When(seq Parent-IDs)(str(Peek Parent-ID))}):Else(recur(z/next loc)Next-id Parent-IDs acc。";";以正确的类似于json的格式";";";{:$Schema";https://vega.github.io/schema/vega/v5.json";:Data[{:名称";树";:Transform[{:Key";id";:ParentKey";Parent";:Type";Layfy";}{:AS[";X";";y";";深度";";子";]:方法{:信号";布局";}:大小[{:信号";宽度";}{:信号";高度";}]:类型";树";}]:值树规范}{:名称";链接";:源";树";:Transform[{:Type";TreeLinks";}{:Orient";Horizative";:Shape{:Signal";Links";}:Type";Linkpath";}]}]:Height h:Marks[{:Encode{:Update{:Path{:Field";Path";}:笔划{:Value";#ccc";}:来自{:Data";Links。}:类型";路径";}{:编码{:输入{:大小{:值50}:笔划{:值";#fff";}}:更新{:填充{:字段";深度";:比例";颜色";}:x{:字段";x";}:y{:字段";y";}:自{:数据";树";}:类型";Symbol";}{:Encode{:Enter{:Baseline{:Value";Bottom";}:font{:Value";Courier";}:FontSize{:Value 14}:角度{:Value 0}:Text{:Field";Name";}}:更新{:Align{:Signal";datum.Children?';center';:';中心';";}:dy{:信号";datum.Children?-6:-6";}:不透明度{:信号";标签?1:0";}:x{:field";x";}:y{:field";y";}:来自{:data";树";}:类型";文本";}]:padd5:比例尺[{:domain{:data";树";:字段";深度";}:名称";颜色";:范围{:方案";岩浆";}:类型";线性";:零真}]:信号[{:绑定{:输入";复选框";}:名称";标签";:值为真}{:绑定{:输入";单选";:选项[";整洁";";cluster";]}:名称";布局";:值";整齐";}{:名称";链接";:值";行";}]:宽度w})(Defn tree[w h list](Vega(maketree w h(list-to-tree-spec list)