- minibuffer should show a title
- clean up listener's minibuffer-related code
- help search looks funny
+- vocab completer
+- vocab operations:
+ - browse
+ - insert IN: -- or just 'become in'
+ - insert USE: -- 'use'
+ ui:
drop
] if* ;
-: discard-irrelevant ( results -- newresults )
- #! Discard results in the low 33%
- dup 0 [ second max ] reduce
- swap [ first2 rot / 2array ] map-with
- [ second 1/3 > ] subset ;
-
: count-occurrences ( seq -- hash )
[
dup [ [ drop off ] hash-each ] each
: search-help ( phrase -- assoc )
tokenize [ term-index get hash ] map [ ] subset
- count-occurrences hash>alist
- [ first2 2array ] map
- [ [ second ] 2apply swap - ] sort discard-irrelevant ;
+ count-occurrences hash>alist rank-completions ;
: index-help ( -- )
term-index get [
over >r "help" set-word-prop r>
dup xref-article index-article ;
-: search-help. ( phrase -- )
- search-help [ first ] map help-outliner ;
-
! Definition protocol
M: link forget link-name remove-article ;
{ $description "Performs a full-text search in the term index for help topics relating to " { $snippet "phrase" } ". The result is an association list of topic names paired with scores, sorted by decreasing score." } ;
HELP: index-help
-{ $description "Updates the full-text search term index for use by " { $link search-help } " and " { $link search-help. } "." } ;
+{ $description "Updates the full-text search term index for use by " { $link search-help } "." } ;
HELP: search-help.
{ $values { "phrase" "a string" } }
"tools/memory.factor"
"tools/listener.factor"
"tools/inspector.factor"
- "tools/fuzzy.factor"
+ "tools/completion.factor"
"tools/word-tools.factor"
"tools/test.factor"
"test/generic.factor"
"test/help/porter-stemmer.factor"
"test/help/topics.factor"
+ "test/help/search.factor"
"test/inference.factor"
"test/init.factor"
"test/inspector.factor"
--- /dev/null
+IN: temporary
+USING: help sequences math test ;
+
+[ t ]
+[ "variables" search-help [ second number? ] all? ]
+unit-test
USING: tools ;
[ ] [ "" apropos ] unit-test
+[ ] [ "swp" apropos ] unit-test
--- /dev/null
+! Copyright (C) 2005, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: completion
+USING: kernel arrays sequences math namespaces strings io ;
+
+! Simple fuzzy search.
+
+: fuzzy ( full short -- indices )
+ 0 swap >array [ swap pick index* [ 1+ ] keep ] map 2nip
+ -1 over member? [ drop f ] when ;
+
+: (runs) ( n i seq -- )
+ 2dup length < [
+ 3dup nth [
+ number= [
+ >r >r 1+ r> r>
+ ] [
+ split-next,
+ rot drop [ nth 1+ ] 2keep
+ ] if >r 1+ r>
+ ] keep split, (runs)
+ ] [
+ 3drop
+ ] if ;
+
+: runs ( seq -- seq )
+ [
+ split-next,
+ dup first 0 rot (runs)
+ ] { } make ;
+
+: score-1 ( i full -- n )
+ {
+ { [ over zero? ] [ 2drop 10 ] }
+ { [ 2dup length 1- = ] [ 2drop 4 ] }
+ { [ 2dup >r 1- r> nth Letter? not ] [ 2drop 10 ] }
+ { [ 2dup >r 1+ r> nth Letter? not ] [ 2drop 4 ] }
+ { [ t ] [ 2drop 1 ] }
+ } cond ;
+
+: score ( full fuzzy -- n )
+ dup [
+ [ [ length ] 2apply - 15 swap [-] 3 / ] 2keep
+ runs [
+ [ swap score-1 ] map-with dup supremum swap length *
+ ] map-with sum +
+ ] [
+ 2drop 0
+ ] if ;
+
+: rank-completions ( results -- newresults )
+ #! Discard results in the low 33%
+ [ [ second ] 2apply swap - ] sort
+ [ 0 [ second max ] reduce ] keep
+ [ second swap > ] subset-with ;
+
+: completion ( str quot obj -- pair )
+ #! pair is { obj score }
+ [ swap call dup rot fuzzy score ] keep swap 2array ; inline
+
+: completions ( str candidates quot -- seq )
+ pick empty? [
+ 3drop f
+ ] [
+ [ >r 2dup r> completion ] map 2nip rank-completions
+ ] if ; inline
+
+: completion>string ( score str -- )
+ [ % " (score: " % >fixnum # ")" % ] "" make ;
+
+: string-completions ( str strs -- seq )
+ f swap completions ;
+++ /dev/null
-! Copyright (C) 2005, 2006 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-IN: tools
-USING: kernel arrays sequences math namespaces strings io ;
-
-! Simple fuzzy search.
-
-: fuzzy ( full short -- indices )
- 0 swap >array [ swap pick index* [ 1+ ] keep ] map 2nip
- -1 over member? [ drop f ] when ;
-
-: (runs) ( n i seq -- )
- 2dup length < [
- 3dup nth [
- number= [
- >r >r 1+ r> r>
- ] [
- split-next,
- rot drop [ nth 1+ ] 2keep
- ] if >r 1+ r>
- ] keep split, (runs)
- ] [
- 3drop
- ] if ;
-
-: runs ( seq -- seq )
- [
- split-next,
- dup first 0 rot (runs)
- ] { } make ;
-
-: score-1 ( i full -- n )
- {
- { [ over zero? ] [ 2drop 10 ] }
- { [ 2dup length 1- = ] [ 2drop 4 ] }
- { [ 2dup >r 1- r> nth Letter? not ] [ 2drop 10 ] }
- { [ 2dup >r 1+ r> nth Letter? not ] [ 2drop 4 ] }
- { [ t ] [ 2drop 1 ] }
- } cond ;
-
-: score ( full fuzzy -- n )
- dup [
- [ [ length ] 2apply - 15 swap [-] 3 / ] 2keep
- runs [
- [ swap score-1 ] map-with dup supremum swap length *
- ] map-with sum +
- ] [
- 2drop 0
- ] if ;
-
-: rank-completions ( seq -- seq )
- [ first zero? not ] subset
- [ [ first ] 2apply swap - ] sort
- dup length 20 min head ;
-
-: completion ( str quot obj -- pair )
- #! pair is { score obj }
- [ swap call dup rot fuzzy score ] keep 2array ; inline
-
-: completions ( str candidates quot -- seq )
- pick empty? [
- 3drop f
- ] [
- [ >r 2dup r> completion ] map 2nip rank-completions
- ] if ; inline
-
-: completion. ( score str obj -- )
- >r [ % " (score: " % >fixnum # ")" % ] "" make r>
- write-object terpri ; inline
-
-: string-completions ( str strs -- seq )
- f swap completions ;
IN: tools
USING: arrays definitions hashtables help tools io kernel
math namespaces prettyprint sequences strings styles words
-generic ;
+generic completion ;
: word-outliner ( seq -- )
natural-sort [
] annotate ;
: word-completion. ( pair -- )
- first2 [ summary ] keep completion. ;
+ first2 over summary completion>string swap write-object ;
: word-completions ( str words -- seq )
[ word-name ] swap completions ;
: apropos ( str -- )
- all-words word-completions [ word-completion. ] each ;
+ all-words word-completions
+ [ word-completion. terpri ] each ;
"test/commands.factor"
"test/panes.factor"
"test/editor.factor"
+ "test/search.factor"
"test/tracks.factor"
} ;
--- /dev/null
+IN: temporary
+USING: gadgets-search io test ;
+
+[ "hey man (score: 123)" ]
+[ [ { "hey man" 123 } file-completion. ] string-out ]
+unit-test
USING: arrays gadgets gadgets-frames gadgets-labels
gadgets-panes gadgets-scrolling gadgets-text gadgets-theme
generic help tools kernel models sequences words
-gadgets-borders gadgets-lists namespaces parser hashtables io ;
+gadgets-borders gadgets-lists namespaces parser hashtables io
+completion ;
TUPLE: live-search field list model producer action presenter ;
M: live-search focusable-child* live-search-field ;
: <word-search> ( string action -- gadget )
- \ second add*
+ \ first add*
all-words
[ word-completions ] curry
[ [ word-completion. ] make-pane ]
<live-search> ;
: file-completion. ( pair -- )
- first2 dup <pathname> completion. ;
+ first2 over completion>string swap <pathname> write-object ;
: <source-files-search> ( string action -- gadget )
- \ second add*
+ \ first add*
source-files get hash-keys natural-sort
[ string-completions ] curry
[ [ file-completion. ] make-pane ]