foaf_user/commit
CLEANUP: Move computation to a library
author | Jan Wielemaker |
---|---|
Fri Nov 19 12:43:21 2010 +0100 | |
committer | Jan Wielemaker |
Fri Nov 19 12:43:21 2010 +0100 | |
commit | ee1e1e33f9fc729df90c8372cdfebb587d6363c9 |
tree | 1edcae4ef196220bd81b0817f4c22d865d4e5402 |
parent | ebe0a8292170d093857ad229d796aa68b239d22e |
Diff style: patch stat
diff --git a/applications/foaf_user_profile.pl b/applications/foaf_user_profile.pl index 369b614..77efab6 100644 --- a/applications/foaf_user_profile.pl +++ b/applications/foaf_user_profile.pl @@ -28,14 +28,12 @@ the GNU General Public License. */ -:- module(foaf_user_profile, - [ foaf_mbox_hash/2 % +MBOX, -Hash - ]). +:- module(foaf_user_profile, []). :- use_bundle(html_page). :- use_module(user(user_db)). :- use_module(library(error)). :- use_module(library(option)). -:- use_module(library(sha)). +:- use_module(library(semweb/rdf_foaf)). :- use_module(library(semweb/rdf_db)). :- use_module(library(semweb/rdfs)). :- use_module(library(semweb/rdf_label)). @@ -166,25 +164,3 @@ update_user(UserURI, P=Value) :- ). update_user(_, P=_) :- existence_error(foaf_property, P). - - -%% foaf_mbox_hash(+MBox, -Hash) is det. -% -% Create a FOAF compatible hash for the mailbox. Note that it -% seems http://www.ldodds.com/foaf/foaf-a-matic creates a -% case-sensitive hash. We create a case-insensative hash because -% E-mail addresses are cases-insensative. - -foaf_mbox_hash(Mbox, Hash) :- - downcase_atom(Mbox, Code), - sha_hash(Code, Bytes, []), - hex_codes(Bytes, Hex), - atom_codes(Hash, Hex). - -hex_codes([], []). -hex_codes([H|T0], [C1,C2|T]) :- - V1 is H >> 4, - V2 is H mod 0xf, - code_type(C1, xdigit(V1)), - code_type(C2, xdigit(V2)), - hex_codes(T0, T). diff --git a/lib/semweb/rdf_foaf.pl b/lib/semweb/rdf_foaf.pl new file mode 100644 index 0000000..681aa64 --- /dev/null +++ b/lib/semweb/rdf_foaf.pl @@ -0,0 +1,55 @@ +/* Part of ClioPatria SeRQL and SPARQL server + + Author: Jan Wielemaker + E-mail: J.Wielemaker@cs.vu.nl + WWW: http://www.swi-prolog.org + Copyright (C): 2010, University of Amsterdam, + VU University Amsterdam + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + As a special exception, if you link this library with other files, + compiled with a Free Software compiler, to produce an executable, this + library does not by itself cause the resulting executable to be covered + by the GNU General Public License. This exception does not however + invalidate any other reasons why the executable file might be covered by + the GNU General Public License. +*/ + +:- module(rdf_foaf, + [ foaf_mbox_hash/2 % +MBOX, -Hash + ]). +:- use_module(library(sha)). + +%% foaf_mbox_hash(+MBox, -Hash) is det. +% +% Create a FOAF compatible hash for the mailbox. Note that it +% seems http://www.ldodds.com/foaf/foaf-a-matic creates a +% case-sensitive hash. We create a case-insensative hash because +% E-mail addresses are cases-insensative. + +foaf_mbox_hash(Mbox, Hash) :- + downcase_atom(Mbox, Code), + sha_hash(Code, Bytes, []), + hex_codes(Bytes, Hex), + atom_codes(Hash, Hex). + +hex_codes([], []). +hex_codes([H|T0], [C1,C2|T]) :- + V1 is H >> 4, + V2 is H mod 0xf, + code_type(C1, xdigit(V1)), + code_type(C2, xdigit(V2)), + hex_codes(T0, T).