annotate cpack/dml/examples/c3examples.swinb @ 0:718306e29690 tip

commiting public release
author Daniel Wolff
date Tue, 09 Feb 2016 21:05:06 +0100
parents
children
rev   line source
Daniel@0 1 <div class="notebook">
Daniel@0 2
Daniel@0 3 <div class="nb-cell markdown">
Daniel@0 4 # C3 Rendering examples
Daniel@0 5
Daniel@0 6 This is an example of how to use C3 graphics to illustrate the content in the DML collection.
Daniel@0 7 </div>
Daniel@0 8
Daniel@0 9 <div class="nb-cell program">
Daniel@0 10 :- use_rendering(c3).
Daniel@0 11
Daniel@0 12 %% collection(-C:oneof([charm,bl]), -X:uri) is nondet.
Daniel@0 13 collection(charm,X) :- rdf(X,charm:file_name,_).
Daniel@0 14 collection(bl,X) :- rdf(X,rdf:type,mo:'Signal',bl_p2r).
Daniel@0 15
Daniel@0 16 collection_property_value_count(Collection,Property,Value,Count) :-
Daniel@0 17 aggregate(count, R^(collection(Collection,R), rdf_has(R,Property,Value)), Count).
Daniel@0 18
Daniel@0 19 % Unfortunately rdf_meta is not legal in sandbox yet.
Daniel@0 20 %:- rdf_meta collection_property_hist(+,r,+,-).
Daniel@0 21 %% collection_property_hist(+C:atom, +P:uri, +Min:nonneg, -Chart:dict) is det.
Daniel@0 22 collection_property_hist(Coll,P,Min,c3{data:_{columns:Pairs, type:pie}}) :-
Daniel@0 23 rdf_global_id(P,Prop), % expand Namespace:Local resource representation
Daniel@0 24 setof( [C,N], (collection_property_value_count(Coll,Prop,literal(C),N),N&gt;Min), Pairs).
Daniel@0 25 </div>
Daniel@0 26
Daniel@0 27 <div class="nb-cell markdown">
Daniel@0 28 Next a little test that we can use this to get pairs of composer and count.
Daniel@0 29 </div>
Daniel@0 30
Daniel@0 31 <div class="nb-cell query" data-tabled="true">
Daniel@0 32 aggregate(count, X^(collection(charm,X), rdf_has(X,dml:composer,C)), N).
Daniel@0 33 </div>
Daniel@0 34
Daniel@0 35 <div class="nb-cell markdown">
Daniel@0 36 Next a pie chart showing the proportions of different composers in the CHARM collection. (This query should run automatically when this notebook loads). If you click on the labels in the legend, that segment is removed and the pie redrawn.
Daniel@0 37 </div>
Daniel@0 38
Daniel@0 39 <div class="nb-cell query" data-run="onload">
Daniel@0 40 collection_property_hist(charm,dml:composer,25,Pairs).
Daniel@0 41 </div>
Daniel@0 42
Daniel@0 43 <div class="nb-cell markdown">
Daniel@0 44 Finally, a couple more distributions over language and composer in the BL collection. Press the white-on-green arrow to run the query.
Daniel@0 45 </div>
Daniel@0 46
Daniel@0 47 <div class="nb-cell query">
Daniel@0 48 collection_property_hist(bl,dc:language,150,Pairs).
Daniel@0 49 </div>
Daniel@0 50
Daniel@0 51 <div class="nb-cell query">
Daniel@0 52 % top 20 composers
Daniel@0 53 collection_property_hist(bl,dml:composer,20,Pairs).
Daniel@0 54 </div>
Daniel@0 55
Daniel@0 56 </div>