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