:-use_module(library(rdf_db)). nt(S,P,O) :- rdf_db(C), nt(S,P,O,C). nt(S,P,O,C) :- rdf(S,P,O,C), ntriple(S,P,O,Result, _), write_ln(hi), checklist(write, Result), write_ln(''). ntriple(S,P,O)--> bracketed_uri(S), bracketed_uri(P), bracketed_uri(O), ['.']. bracketed_uri(Uri) --> ['<', Uri, '> ']. qname(this) --> [this]. qname(literal(L)) --> !,['"',L,'"']. qname(Uri) --> {rdf_db:ns(Prefix, Ns), atom_concat(Ns, Lname, Uri), concat_atom([Prefix,':',Lname], Qname)}, [Qname]. qname(Uri) --> {atom_concat(anon_, Var,Uri)}, ['_:_', Var]. qname(Uri) --> [Uri]. n3_context(Context) --> {findall([S,P,O], rdf(S,P,O,Context), Triples)}, n3_statements(Triples). n3_statements([]) --> []. n3_statements([[S, 'http://www.w3.org/2000/10/swap/log#implies',O]|Triples]) --> ['{'], n3_context(S), ['} \n\t'], qname('http://www.w3.org/2000/10/swap/log#implies'), [' {'], n3_context(O), ['}.\n\n'], n3_statements(Triples). n3_statements([[S,P,O]|Triples]) --> {Triples=[] -> Line_end = []; Line_end = ['\n']}, qname(S),[' '], qname(P), [' '], qname(O), ['.'], Line_end, n3_statements(Triples). n3_statement(S,P,O, Indent, Line_end) --> Indent, qname(S),[' '], qname(P), [' '], qname(O), ['.'], Line_end. n3_anon(Triples) --> ['['],n3_anon_clauses(Triples), ['].\n']. n3_anon_clauses([[_,P,O]|[]]) --> qname(P), [' '], qname(O). n3_anon_clauses([[_,P,O]|Triples]) --> qname(P), [' '], qname(O), [';\n'], n3_anon_clauses(Triples). n3(S,P,O) :- rdf_db(C), n3(S,P,O,C). n3(S,P,O,C) :- rdf(S,P,O,C), n3(S,P,O,C,Result, _). /*n3(Ant, 'http://www.w3.org/2000/10/swap/log#implies', Cons, C) --> {rdf(S1, P1, S n3(S,P,O,C) --> {P = } ntriple(S,P,O).*/ %formula(In_context) --> all_triples(Rdf_db, Triple_list) :- findall([S,P,O], rdf(S,P,O,Rdf_db), Triple_list). prefixes(Prefix_list) :- setof([Prefix, Uri], rdf_db:ns(Prefix, Uri), Prefix_list). prefix_block --> {prefixes(Prefix_list)}, prefix_list(Prefix_list). prefix_list([]) --> []. prefix_list([[Prefix, Uri] | Prefix_list]) --> {Prefix = 'default_' -> Pre = ''; Pre = Prefix}, ['@prefix ', Pre, ': '], bracketed_uri(Uri),['.\n'], prefix_list(Prefix_list). %same_S_P(S,P,[[S,P,O]|Init],[[S,P,O]|Result]) :- % same_S_P(S,P, Init, Result). %same_S_P(S,P,[],[]). %same_S(S, [[S,P,O]|Init],[[S,P,O]|Result]) :- % same_S(S,Init, Result). %same_S(S, [S, _, _],[S,_,_]). same_S_prefix(List,Result) :- [[S|_]|_] = List, same_S_prefix_1(S, List, Result). same_S_prefix_1(S, [H|T], Result) :- [S|_] = H -> (same_S_prefix_1(S, T, R), Result = [H|R]); Result=[]. same_SP_prefix(List, Result) :- [[S, P , _]|_] = List, same_SP_prefix_1(S,P,List, Result). same_SP_prefix_1(S,P, [H|T], Result) :- [S, P| _] = H -> (same_SP_prefix_1(S,P,T,R), Result=[H|R]); Result=[]. %prefix_of_S([SList, Result).