annotate cpack/dml/lib/mazurka_p2r.pl @ 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 /* Part of DML (Digital Music Laboratory)
Daniel@0 2 Copyright 2014-2015 Samer Abdallah, University of London
Daniel@0 3
Daniel@0 4 This program is free software; you can redistribute it and/or
Daniel@0 5 modify it under the terms of the GNU General Public License
Daniel@0 6 as published by the Free Software Foundation; either version 2
Daniel@0 7 of the License, or (at your option) any later version.
Daniel@0 8
Daniel@0 9 This program is distributed in the hope that it will be useful,
Daniel@0 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
Daniel@0 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Daniel@0 12 GNU General Public License for more details.
Daniel@0 13
Daniel@0 14 You should have received a copy of the GNU General Public
Daniel@0 15 License along with this library; if not, write to the Free Software
Daniel@0 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Daniel@0 17 */
Daniel@0 18
Daniel@0 19 :- module(mazurka_p2r, []).
Daniel@0 20
Daniel@0 21 /** <module> Access to beets database
Daniel@0 22 */
Daniel@0 23
Daniel@0 24
Daniel@0 25 % :- use_module(library(odbc)).
Daniel@0 26 :- use_module(library(csv)).
Daniel@0 27 :- use_module(library(musicbrainz)).
Daniel@0 28 :- use_module(library(semweb/rdf_db)).
Daniel@0 29 :- use_module(library(termutils)).
Daniel@0 30 :- use_module(library(rdfutils)).
Daniel@0 31 :- use_module(library(stringutils)).
Daniel@0 32 :- use_module(library(dcg/basics)).
Daniel@0 33 :- use_module(entailment(p2r)).
Daniel@0 34 :- use_module(library(memo)).
Daniel@0 35
Daniel@0 36 :- set_prolog_flag(double_quotes,string).
Daniel@0 37
Daniel@0 38 :- rdf_register_prefix(mazurka,'http://dml.org/mazurka/').
Daniel@0 39
Daniel@0 40 :- setting(csv_database,string,"~/lib/mazurka/mazurka-discography.txt","Location of Mazurka tab-separated-values").
Daniel@0 41 :- setting(audio_root,ground,nothing,"Location of Mazurka audio files").
Daniel@0 42
Daniel@0 43 % :- rdf_meta convert(+,+,o).
Daniel@0 44 % convert(string,X,literal(X)).
Daniel@0 45 % convert(atom,X,literal(Y)) :- atom_string(Y,X).
Daniel@0 46 % convert(number,X,literal(Y)) :- number_string(Y,X).
Daniel@0 47 % convert(date(E),X,literal(Date)) :- string_to_date(E,X,Date).
Daniel@0 48
Daniel@0 49 rdf(mazurka:title, rdfs:subPropertyOf, dc:title) <== true.
Daniel@0 50 rdf(mazurka:enc(Id), Prop, Obj) <==
Daniel@0 51 setting(csv_database,Pattern),
Daniel@0 52 expand_file_name(Pattern,[DBFile]),
Daniel@0 53 csv_to_rdf(DBFile,Id,Prop,Obj).
Daniel@0 54
Daniel@0 55 csv_to_rdf(DBFile,Id,Prop,Obj) :-
Daniel@0 56 once(csv_read_file_row(DBFile,Header,[convert(false),separator(0'\t), line(1)])),
Daniel@0 57 functor(Header,row,NumCols),
Daniel@0 58 functor(Row,row,NumCols),
Daniel@0 59 row_field(Header-Row,pid,Id),
Daniel@0 60 csv_read_file_row(DBFile,Row,[convert(false),separator(0'\t), line(L)]), L>1,
Daniel@0 61 status("Importing mazurka: ~w",[Id]),
Daniel@0 62 row_triple(Header-Row,Prop,Obj).
Daniel@0 63 % rdf_global_object(Obj1,Obj).
Daniel@0 64
Daniel@0 65 :- rdf_meta row_triple(+,r,o).
Daniel@0 66 row_triple(_,mazurka:composer,literal('Chopin')).
Daniel@0 67 row_triple(HR,mazurka:pid,literal(PID)) :- row_field(HR,pid,PID).
Daniel@0 68 row_triple(HR,Prop,Val) :-
Daniel@0 69 row_field(HR,opus,OpusNum),
Daniel@0 70 row_field(HR,key,Key),
Daniel@0 71 atomic_list_concat([Opus,Number],'.',OpusNum),
Daniel@0 72 work_triple(Key,Opus,Number,Prop,Val).
Daniel@0 73
Daniel@0 74 row_triple(HR,mazurka:performer,literal(Perf)) :- row_field(HR,performer,Perf).
Daniel@0 75 row_triple(HR,mazurka:recording_date,literal(type(T,Year))) :- row_field(HR,year,Year), rdf_global_id(xsd:gYear,T).
Daniel@0 76 row_triple(HR,mazurka:duration,literal(type(T,X))) :- row_field(HR,seconds,A), atom_number(A,X), rdf_global_id(xsd:int,T).
Daniel@0 77 row_triple(HR,mazurka:label,literal(Label)) :- row_field(HR,label,Label).
Daniel@0 78
Daniel@0 79 :- rdf_meta work_triple(+,+,+,r,o).
Daniel@0 80 work_triple(K,O,N,mazurka:title,literal(T)) :- format(atom(T),"Mazurka in ~w, op.~w, no.~w",[K,O,N]).
Daniel@0 81 work_triple(K,_,_,mazurka:key,literal(K)).
Daniel@0 82 work_triple(_,O,_,mazurka:opus,literal(O)).
Daniel@0 83 work_triple(_,_,N,mazurka:number,literal(N)).
Daniel@0 84 work_triple(_,O,N,mazurka:score,Score) :-
Daniel@0 85 format(atom(Score),"kern:/classical/chopin/mazurka/mazurka~|~`0t~w~2+-~w.krn",[O,N]).
Daniel@0 86
Daniel@0 87
Daniel@0 88 row_field(Header-Row,Name,Value) :- arg(N,Header,Name), arg(N,Row,Value).
Daniel@0 89 % null_value("-").
Daniel@0 90
Daniel@0 91 :- public import/0.
Daniel@0 92 import :- assert_all(mazurka_p2r).
Daniel@0 93
Daniel@0 94 :- public audio_file/3.
Daniel@0 95 audio_file(URI,Path,just(Fmt)) :-
Daniel@0 96 rdf(URI,mazurka:pid,literal(PID)),
Daniel@0 97 rdf(URI,mazurka:opus,literal(Opus)),
Daniel@0 98 rdf(URI,mazurka:number,literal(Number)),
Daniel@0 99 setting(audio_root,just(RootPatt)),
Daniel@0 100 expand_file_name(RootPatt,[Root]),
Daniel@0 101 member(Fmt-Ext,[aac-mp4,wav-wav]),
Daniel@0 102 format(atom(Path),"~w/mazurka~|~`0t~w~2+-~w/pid~w.~w",[Root,Opus,Number,PID,Ext]),
Daniel@0 103 exists_file(Path).
Daniel@0 104
Daniel@0 105 % audio_link(Type,URI,URL) :-
Daniel@0 106 % member(Type,[mp3,flac]),
Daniel@0 107 % rdf(URI,charm:file_name,literal(Filename)),
Daniel@0 108 % ( sub_atom(Filename,_,_,_,'£')
Daniel@0 109 % -> atom_codes(Filename,C1),
Daniel@0 110 % fix_url(C1,C2),
Daniel@0 111 % atom_codes(Filename2,C2)
Daniel@0 112 % ; Filename2=Filename
Daniel@0 113 % ),
Daniel@0 114 % format(atom(URL),'http://charm.cchcdn.net/audio/~w/~w.~w',[Type,Filename2,Type]).
Daniel@0 115