view 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
line wrap: on
line source
<div class="notebook">

<div class="nb-cell markdown">
# C3 Rendering examples

This is an example of how to use C3 graphics to illustrate the content in the DML collection.
</div>

<div class="nb-cell program">
:- use_rendering(c3).

%% collection(-C:oneof([charm,bl]), -X:uri) is nondet.
collection(charm,X) :- rdf(X,charm:file_name,_).
collection(bl,X) :- rdf(X,rdf:type,mo:'Signal',bl_p2r).

collection_property_value_count(Collection,Property,Value,Count) :-
	aggregate(count, R^(collection(Collection,R), rdf_has(R,Property,Value)), Count).

% Unfortunately rdf_meta is not legal in sandbox yet.
%:- rdf_meta collection_property_hist(+,r,+,-).
%% collection_property_hist(+C:atom, +P:uri, +Min:nonneg, -Chart:dict) is det.
collection_property_hist(Coll,P,Min,c3{data:_{columns:Pairs, type:pie}}) :-
    rdf_global_id(P,Prop), % expand Namespace:Local resource representation 
    setof(	[C,N], (collection_property_value_count(Coll,Prop,literal(C),N),N&gt;Min), Pairs).
</div>

<div class="nb-cell markdown">
Next a little test that we can use this to get pairs of composer and count.
</div>

<div class="nb-cell query" data-tabled="true">
aggregate(count, X^(collection(charm,X), rdf_has(X,dml:composer,C)), N).
</div>

<div class="nb-cell markdown">
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.
</div>

<div class="nb-cell query" data-run="onload">
collection_property_hist(charm,dml:composer,25,Pairs).
</div>

<div class="nb-cell markdown">
Finally, a couple more distributions over language and composer in the BL collection. Press the white-on-green arrow to run the query.
</div>

<div class="nb-cell query">
collection_property_hist(bl,dc:language,150,Pairs).
</div>

<div class="nb-cell query">
% top 20 composers
collection_property_hist(bl,dml:composer,20,Pairs).
</div>

</div>