annotate magnatune/sparql-archived/SeRQL/Triple20/src/rdf_ns.pl @ 27:d95e683fbd35 tip

Enable CORS on urispace redirects as well
author Chris Cannam
date Tue, 20 Feb 2018 14:52:02 +0000
parents df9685986338
children
rev   line source
Chris@0 1 /* $Id: rdf_ns.pl,v 1.9 2007/01/16 09:37:10 jan Exp $
Chris@0 2
Chris@0 3 Part of SWI-Prolog
Chris@0 4
Chris@0 5 Author: Jan Wielemaker
Chris@0 6 E-mail: jan@swi.psy.uva.nl
Chris@0 7 WWW: http://www.swi-prolog.org
Chris@0 8 Copyright (C): 1985-2002, University of Amsterdam
Chris@0 9
Chris@0 10 This program is free software; you can redistribute it and/or
Chris@0 11 modify it under the terms of the GNU General Public License
Chris@0 12 as published by the Free Software Foundation; either version 2
Chris@0 13 of the License, or (at your option) any later version.
Chris@0 14
Chris@0 15 This program is distributed in the hope that it will be useful,
Chris@0 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 18 GNU General Public License for more details.
Chris@0 19
Chris@0 20 You should have received a copy of the GNU Lesser General Public
Chris@0 21 License along with this library; if not, write to the Free Software
Chris@0 22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Chris@0 23
Chris@0 24 As a special exception, if you link this library with other files,
Chris@0 25 compiled with a Free Software compiler, to produce an executable, this
Chris@0 26 library does not by itself cause the resulting executable to be covered
Chris@0 27 by the GNU General Public License. This exception does not however
Chris@0 28 invalidate any other reasons why the executable file might be covered by
Chris@0 29 the GNU General Public License.
Chris@0 30 */
Chris@0 31
Chris@0 32
Chris@0 33 :- module(rdf_ns,
Chris@0 34 [
Chris@0 35 ]).
Chris@0 36 :- use_module(library(pce)).
Chris@0 37 :- use_module(library(persistent_frame)).
Chris@0 38 :- use_module(library(toolbar)).
Chris@0 39 :- use_module(library(pce_report)).
Chris@0 40 :- use_module(library(broadcast)).
Chris@0 41 :- use_module(library(lists)).
Chris@0 42 :- use_module(library('semweb/rdf_edit')).
Chris@0 43 :- use_module(rdf_util).
Chris@0 44
Chris@0 45 :- pce_autoload(identifier_item, library(pce_identifier_item)).
Chris@0 46
Chris@0 47 :- pce_begin_class(rdf_namespace_window, persistent_frame,
Chris@0 48 "Query/Create namespaces").
Chris@0 49
Chris@0 50 initialise(F) :->
Chris@0 51 send_super(F, initialise, 'RDF/XML namespaces'),
Chris@0 52 send(F, append, new(TD, tool_dialog)),
Chris@0 53 send(new(B, rdf_namespace_browser), below, TD),
Chris@0 54 send(new(report_dialog), below, B),
Chris@0 55 send(F, fill_dialog, TD).
Chris@0 56
Chris@0 57 fill_dialog(F, D:tool_dialog) :->
Chris@0 58 send(D, append, new(File, popup(file))),
Chris@0 59 send_list(File, append,
Chris@0 60 [ menu_item(new, message(F, new_namespace)),
Chris@0 61 gap,
Chris@0 62 menu_item(exit, message(F, destroy))
Chris@0 63 ]).
Chris@0 64
Chris@0 65 new_namespace(F) :->
Chris@0 66 "Prompt for a new namespace"::
Chris@0 67 send(t20_new_namespace_dialog(F), run).
Chris@0 68
Chris@0 69 :- pce_end_class(rdf_namespace_window).
Chris@0 70
Chris@0 71
Chris@0 72 :- pce_begin_class(rdf_namespace_browser, browser,
Chris@0 73 "Show defined namespaces").
Chris@0 74
Chris@0 75 class_variable(size, size, size(60, 10)).
Chris@0 76
Chris@0 77 initialise(B) :->
Chris@0 78 send_super(B, initialise, 'RDF Namespaces'),
Chris@0 79 send(B, tab_stops, vector(60)),
Chris@0 80 send(B, select_message,
Chris@0 81 message(B, copy_ns, @arg1)),
Chris@0 82 send(B, style, fallback, style(font := bold)),
Chris@0 83 send(B, update),
Chris@0 84 send(B, popup, new(P, popup)),
Chris@0 85 Item = ?(B, dict_item, @event),
Chris@0 86 HasItem = (condition := Item),
Chris@0 87 send_list(P, append,
Chris@0 88 [ menu_item(set_fallback,
Chris@0 89 message(B, set_fallback, Item?key),
Chris@0 90 HasItem)
Chris@0 91 ]),
Chris@0 92 listen(B, rdf_ns(_),
Chris@0 93 send(B, update)),
Chris@0 94 listen(B, rdf_default_ns(File, _NS),
Chris@0 95 ( var(File),
Chris@0 96 send(B, update_default_ns))).
Chris@0 97
Chris@0 98 unlink(B) :->
Chris@0 99 unlisten(B),
Chris@0 100 send_super(B, unlink).
Chris@0 101
Chris@0 102 copy_ns(_B, Di:dict_item) :->
Chris@0 103 "Copy namespace expansion"::
Chris@0 104 get(Di, object, NS),
Chris@0 105 send(@display, copy, NS).
Chris@0 106
Chris@0 107 update(B) :->
Chris@0 108 findall(ID, rdf_db:ns(ID, _), IDS0),
Chris@0 109 sort(IDS0, IDS),
Chris@0 110 send(B, clear),
Chris@0 111 forall(member(ID, IDS), send(B, append, ID)).
Chris@0 112
Chris@0 113 append(B, Id:name) :->
Chris@0 114 rdf_db:ns(Id, Name),
Chris@0 115 ( rdf_default_ns([], Id)
Chris@0 116 -> Style = fallback,
Chris@0 117 sformat(Label, '~w\t~w (fallback)', [Id, Name])
Chris@0 118 ; Style = @default,
Chris@0 119 sformat(Label, '~w\t~w', [Id, Name])
Chris@0 120 ),
Chris@0 121 send_super(B, append, dict_item(Id, Label, Name, Style)).
Chris@0 122
Chris@0 123 update_default_ns(B) :->
Chris@0 124 "Update indication of default namespace"::
Chris@0 125 get(B, dict, Dict),
Chris@0 126 send(Dict?members, for_all, message(B, update_default_ns1, @arg1)).
Chris@0 127
Chris@0 128 update_default_ns1(_B, DI:dict_item) :->
Chris@0 129 get(DI, key, Id),
Chris@0 130 get(DI, object, Name),
Chris@0 131 ( rdf_default_ns([], Id)
Chris@0 132 -> send(DI, style, fallback),
Chris@0 133 sformat(Label, '~w\t~w (fallback)', [Id, Name]),
Chris@0 134 send(DI, label, Label)
Chris@0 135 ; send(DI, style, @default),
Chris@0 136 sformat(Label, '~w\t~w', [Id, Name]),
Chris@0 137 send(DI, label, Label)
Chris@0 138 ).
Chris@0 139
Chris@0 140 :- pce_group(edit).
Chris@0 141
Chris@0 142 set_fallback(_B, NS:name) :->
Chris@0 143 "Make this the fallback default namespace"::
Chris@0 144 rdf_set_default_ns(_, NS).
Chris@0 145
Chris@0 146 :- pce_end_class(rdf_namespace_browser).