Mercurial > octave
comparison scripts/pkg/private/get_forge_pkg.m @ 21246:101489515a70
get_forge_pkg.m: Fix bad nam similarity matching for -forge packages (bug #47102).
* get_forge_pkg.m: Use URL "list_packages.php" which contains machine-readable
list of Octave-Forge packages. Use new similarity matching algorithm based on
Huffman distance if name is not a valid package name.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 10 Feb 2016 17:42:51 -0800 |
parents | 516bb87ea72e |
children | b571fc85953f |
comparison
equal
deleted
inserted
replaced
21245:933083fee7ae | 21246:101489515a70 |
---|---|
59 endif | 59 endif |
60 endif | 60 endif |
61 endif | 61 endif |
62 else | 62 else |
63 ## Try get the list of all packages. | 63 ## Try get the list of all packages. |
64 [html, succ] = urlread ("http://packages.octave.org/packages.php"); | 64 [html, succ] = urlread ("http://packages.octave.org/list_packages.php"); |
65 if (succ) | 65 if (! succ) |
66 t = regexp (html, "<div class=""package"" id=""(\\w+)"">", "tokens"); | |
67 t = horzcat (t{:}); | |
68 if (any (strcmp (t, name))) | |
69 error ("get_forge_pkg: package NAME exists, but index page not available"); | |
70 else | |
71 ## Try a simplistic method to determine close names. | |
72 dist = cellfun (@(n) length (setdiff (name, n)), t); | |
73 [~, i] = min (dist); | |
74 error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", name, t{i}); | |
75 endif | |
76 else | |
77 error ("get_forge_pkg: could not read URL, please verify internet connection"); | 66 error ("get_forge_pkg: could not read URL, please verify internet connection"); |
78 endif | 67 endif |
68 t = strsplit (html); | |
69 if (any (strcmp (t, name))) | |
70 error ("get_forge_pkg: package NAME exists, but index page not available"); | |
71 endif | |
72 ## Try a simplistic method to determine similar names. | |
73 function d = fdist (x) | |
74 len1 = length (name); | |
75 len2 = length (x); | |
76 if (len1 <= len2) | |
77 d = sum (abs (name(1:len1) - x(1:len1))) + sum (x(len1+1:end)); | |
78 else | |
79 d = sum (abs (name(1:len2) - x(1:len2))) + sum (name(len2+1:end)); | |
80 endif | |
81 endfunction | |
82 dist = cellfun ("fdist", t); | |
83 [~, i] = min (dist); | |
84 error ("get_forge_pkg: package not found: ""%s"". Maybe you meant ""%s?""", | |
85 name, t{i}); | |
79 endif | 86 endif |
80 | 87 |
81 endfunction | 88 endfunction |
82 | 89 |