]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/metadata/metadata.factor
vocabs.metadata: add "vocab-resources" word to read list of deployable resource files...
[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-resources-path ( vocab -- string )
23     vocab-dir "resources.txt" append-path ;
24
25 : vocab-resources ( vocab -- patterns )
26     dup vocab-resources-path vocab-file-contents harvest ;
27
28 : set-vocab-resources ( patterns vocab -- )
29     dup vocab-resources-path set-vocab-file-contents ;
30
31 : vocab-summary-path ( vocab -- string )
32     vocab-dir "summary.txt" append-path ;
33
34 : vocab-summary ( vocab -- summary )
35     dup dup vocab-summary-path vocab-file-contents
36     [
37         vocab-name " vocabulary" append
38     ] [
39         nip first
40     ] if-empty ;
41
42 M: vocab summary
43     [
44         dup vocab-summary %
45         " (" %
46         words>> assoc-size #
47         " words)" %
48     ] "" make ;
49
50 M: vocab-link summary vocab-summary ;
51
52 : set-vocab-summary ( string vocab -- )
53     [ 1array ] dip
54     dup vocab-summary-path
55     set-vocab-file-contents ;
56
57 : vocab-tags-path ( vocab -- string )
58     vocab-dir "tags.txt" append-path ;
59
60 : vocab-tags ( vocab -- tags )
61     dup vocab-tags-path vocab-file-contents harvest ;
62
63 : set-vocab-tags ( tags vocab -- )
64     dup vocab-tags-path set-vocab-file-contents ;
65
66 : add-vocab-tags ( tags vocab -- )
67     [ vocab-tags append prune ] keep set-vocab-tags ;
68
69 : vocab-authors-path ( vocab -- string )
70     vocab-dir "authors.txt" append-path ;
71
72 : vocab-authors ( vocab -- authors )
73     dup vocab-authors-path vocab-file-contents harvest ;
74
75 : set-vocab-authors ( authors vocab -- )
76     dup vocab-authors-path set-vocab-file-contents ;
77
78 : unportable? ( vocab -- ? )
79     vocab-tags "unportable" swap member? ;