diff options
author | Manuel Pégourié-Gonnard <mpg@elzevir.fr> | 2011-05-18 20:21:44 +0000 |
---|---|---|
committer | Manuel Pégourié-Gonnard <mpg@elzevir.fr> | 2011-05-18 20:21:44 +0000 |
commit | e71eaa026ac3384e0e25e3cae94a54be4fe69223 (patch) | |
tree | 44eaf7ef2af6da9e2d4f4599e391a29bf66f0c4e /Master/texmf/scripts/texdoc/score.tlu | |
parent | 0d6f6d802fc805abf007cdde14f242de7450c587 (diff) |
texdoc 0.80
git-svn-id: svn://tug.org/texlive/trunk@22522 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf/scripts/texdoc/score.tlu')
-rw-r--r-- | Master/texmf/scripts/texdoc/score.tlu | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/Master/texmf/scripts/texdoc/score.tlu b/Master/texmf/scripts/texdoc/score.tlu index b655f62e57f..75022e41288 100644 --- a/Master/texmf/scripts/texdoc/score.tlu +++ b/Master/texmf/scripts/texdoc/score.tlu @@ -61,6 +61,7 @@ function set_score(df, original_kw) if config.mode == 'regex' then df.score = 0 return end -- scoring is case-insenstitive (patterns are already lowercased) local name = string.lower(df.shortname) + deb_print('score', '----------') deb_print('score', 'Start scoring '..df.realpath) deb_print('score', 'Name used: '..name) -- get score from patterns @@ -71,16 +72,26 @@ function set_score(df, original_kw) if pat.original then s = df.tree > -1 and heuristic_score(name, p) or 1 elseif is_exact(name, p) then - s = pat.score or 10 -- default alias score + local bonus, msg = 0, '' + if pat.locale then + bonus, msg = 5, ', (language-based)' + end + s = (pat.score or 10) + bonus -- default alias score is 10 deb_print('score', string.format( - "Matching alias '%s', score: %g", pat.name, s)) + "Matching alias '%s', score: %g%s", pat.name, s, msg)) end if s > score then score = s end end deb_print('score', 'Max pattern score: '..tostring(score)) -- get score from tlp associations - if score == -10 and df.tlptodoc then score = -2 end - if score == -10 and df.runtodoc then score = -6 end + if score == -10 and df.tlptodoc then + score = -2 + deb_print('score', 'New score: -2 from package name association') + end + if score == -10 and df.runtodoc then + score = -6 + deb_print('score', 'New score: -6 from sty/cls association') + end -- bonus for metadata if df.details then if string.find(string.lower(df.details), 'readme') then @@ -88,6 +99,7 @@ function set_score(df, original_kw) else score = score + 2.5 end + deb_print('score', string.format('New score: %g from metadata', score)) end -- adjust from keyword-specific tables if df.tree > -1 and spec_adjscore[original_kw] then @@ -127,7 +139,9 @@ function heuristic_score(file, pat) end local slash = not not string.find(pat, '/', 1, true) -- look for exact or subword match - if is_exact(file, pat) then + if is_exact_locale(file, pat) then + upscore(5, 'exact match with correct locale') + elseif is_exact(file, pat) then upscore(4, 'exact match') elseif is_subword(file, pat) then upscore(1, 'subword match') @@ -176,6 +190,20 @@ function is_exact(file, pat) return false end +-- says if file is an exact match for pat and the current locale +function is_exact_locale(file, pat) + if string.match(pat, '%-%l%l%l?$') then + -- don't match if the pattern appears to include a language code + return false + end + local lang = config.lang + if lang then + return is_exact(file, pat .. '-' .. lang) + or is_exact(file, lang .. '-' .. pat) + end + return false +end + -- say if pat is a "subword" of str function is_subword(str, pat) local i, j = string.find(str, pat, 1, true) |