]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/metadata/metadata.factor
04a0ea7546c0945e5f1f2ab89767b0cb02eecf40
[factor.git] / basis / vocabs / metadata / metadata.factor
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 ;
6 IN: vocabs.metadata
7
8 MEMO: vocab-file-contents ( vocab name -- seq )
9     vocab-append-path dup
10     [ dup exists? [ utf8 file-lines ] [ drop f ] if ] when ;
11
12 : set-vocab-file-contents ( seq vocab name -- )
13     dupd vocab-append-path [
14         utf8 set-file-lines
15         \ vocab-file-contents reset-memoized
16     ] [
17         "The " swap vocab-name
18         " vocabulary was not loaded from the file system"
19         3append throw
20     ] ?if ;
21
22 : vocab-windows-icon-path ( vocab -- string )
23     vocab-dir "icon.ico" append-path ;
24
25 : vocab-mac-icon-path ( vocab -- string )
26     vocab-dir "icon.icns" append-path ;
27
28 : vocab-resources-path ( vocab -- string )
29     vocab-dir "resources.txt" append-path ;
30
31 : vocab-resources ( vocab -- patterns )
32     dup vocab-resources-path vocab-file-contents harvest ;
33
34 : set-vocab-resources ( patterns vocab -- )
35     dup vocab-resources-path set-vocab-file-contents ;
36
37 : vocab-summary-path ( vocab -- string )
38     vocab-dir "summary.txt" append-path ;
39
40 : vocab-summary ( vocab -- summary )
41     dup dup vocab-summary-path vocab-file-contents
42     [
43         vocab-name " vocabulary" append
44     ] [
45         nip first
46     ] if-empty ;
47
48 M: vocab summary
49     [
50         dup vocab-summary %
51         " (" %
52         words>> assoc-size #
53         " words)" %
54     ] "" make ;
55
56 M: vocab-link summary vocab-summary ;
57
58 : set-vocab-summary ( string vocab -- )
59     [ 1array ] dip
60     dup vocab-summary-path
61     set-vocab-file-contents ;
62
63 : vocab-tags-path ( vocab -- string )
64     vocab-dir "tags.txt" append-path ;
65
66 : vocab-tags ( vocab -- tags )
67     dup vocab-tags-path vocab-file-contents harvest ;
68
69 : set-vocab-tags ( tags vocab -- )
70     dup vocab-tags-path set-vocab-file-contents ;
71
72 : add-vocab-tags ( tags vocab -- )
73     [ vocab-tags append prune ] keep set-vocab-tags ;
74
75 : vocab-authors-path ( vocab -- string )
76     vocab-dir "authors.txt" append-path ;
77
78 : vocab-authors ( vocab -- authors )
79     dup vocab-authors-path vocab-file-contents harvest ;
80
81 : set-vocab-authors ( authors vocab -- )
82     dup vocab-authors-path set-vocab-file-contents ;
83
84 : unportable? ( vocab -- ? )
85     vocab-tags "unportable" swap member? ;