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-resources-path ( vocab -- string )
23 vocab-dir "resources.txt" append-path ;
25 : vocab-resources ( vocab -- patterns )
26 dup vocab-resources-path vocab-file-contents harvest ;
28 : set-vocab-resources ( patterns vocab -- )
29 dup vocab-resources-path set-vocab-file-contents ;
31 : vocab-summary-path ( vocab -- string )
32 vocab-dir "summary.txt" append-path ;
34 : vocab-summary ( vocab -- summary )
35 dup dup vocab-summary-path vocab-file-contents
37 vocab-name " vocabulary" append
50 M: vocab-link summary vocab-summary ;
52 : set-vocab-summary ( string vocab -- )
54 dup vocab-summary-path
55 set-vocab-file-contents ;
57 : vocab-tags-path ( vocab -- string )
58 vocab-dir "tags.txt" append-path ;
60 : vocab-tags ( vocab -- tags )
61 dup vocab-tags-path vocab-file-contents harvest ;
63 : set-vocab-tags ( tags vocab -- )
64 dup vocab-tags-path set-vocab-file-contents ;
66 : add-vocab-tags ( tags vocab -- )
67 [ vocab-tags append prune ] keep set-vocab-tags ;
69 : vocab-authors-path ( vocab -- string )
70 vocab-dir "authors.txt" append-path ;
72 : vocab-authors ( vocab -- authors )
73 dup vocab-authors-path vocab-file-contents harvest ;
75 : set-vocab-authors ( authors vocab -- )
76 dup vocab-authors-path set-vocab-file-contents ;
78 : unportable? ( vocab -- ? )
79 vocab-tags "unportable" swap member? ;