1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs io.encodings.utf8 io.files
4 io.pathnames kernel make math.parser memoize sequences sets
5 sorting summary vocabs vocabs.loader ;
8 MEMO: vocab-file-contents ( vocab name -- seq )
10 [ dup exists? [ utf8 file-lines ] [ drop f ] if ] when ;
12 : set-vocab-file-contents ( seq vocab name -- )
13 dupd vocab-append-path [
15 \ vocab-file-contents reset-memoized
17 "The " swap vocab-name
18 " vocabulary was not loaded from the file system"
22 : vocab-summary-path ( vocab -- string )
23 vocab-dir "summary.txt" append-path ;
25 : vocab-summary ( vocab -- summary )
26 dup dup vocab-summary-path vocab-file-contents
28 vocab-name " vocabulary" append
41 M: vocab-link summary vocab-summary ;
43 : set-vocab-summary ( string vocab -- )
45 dup vocab-summary-path
46 set-vocab-file-contents ;
48 : vocab-tags-path ( vocab -- string )
49 vocab-dir "tags.txt" append-path ;
51 : vocab-tags ( vocab -- tags )
52 dup vocab-tags-path vocab-file-contents harvest ;
54 : set-vocab-tags ( tags vocab -- )
55 dup vocab-tags-path set-vocab-file-contents ;
57 : add-vocab-tags ( tags vocab -- )
58 [ vocab-tags append prune ] keep set-vocab-tags ;
60 : vocab-authors-path ( vocab -- string )
61 vocab-dir "authors.txt" append-path ;
63 : vocab-authors ( vocab -- authors )
64 dup vocab-authors-path vocab-file-contents harvest ;
66 : set-vocab-authors ( authors vocab -- )
67 dup vocab-authors-path set-vocab-file-contents ;
69 : unportable? ( vocab -- ? )
70 vocab-tags "unportable" swap member? ;