Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Side by Side Diff: utils/apidoc/mdn/util.dart

Issue 9360002: cleanup postProcess step and output obsolete.json file (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/apidoc/mdn/prettyPrint.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #library("util");
2
3 #import("../../../frog/lib/node/node.dart");
4 #import("dart:json");
5
6 // TODO(jacobr): this file conflates pretty printing of the JSON database with
7 // filtering the database to select the best matches per file.
nweiz 2012/02/08 01:18:40 This isn't true any more
Jacob 2012/02/08 01:20:32 Done.
8 // Separate out the two tasks as quick and dirty coding is correct for pretty
9 // printing but more carefully documented code is required for the code
10 // filtering the database.
11 Map<String, Map> _allProps;
12
13 Map<String, Map> get allProps() {
14 if (_allProps == null) {
15 // Database of expected property names for each type in WebKit.
16 _allProps = JSON.parse(fs.readFileSync('data/dartIdl.json', 'utf8'));
17 }
18 return _allProps;
19 }
20
21 Set<String> matchedTypes;
22
23 /** Returns whether the type has any member matching the specified name. */
24 bool hasAny(String type, String prop) {
25 final data = allProps[type];
26 return data['properties'].containsKey(prop) ||
27 data['methods'].containsKey(prop) ||
28 data['constants'].containsKey(prop);
29 }
30
31 /**
32 * Return the members from an [entry] as Map of member names to member
33 * objects.
34 */
35 Map getMembersMap(Map entry) {
36 List<Map> rawMembers = entry["members"];
37 final members = {};
38 for (final entry in rawMembers) {
39 members[entry['name']] = entry;
40 }
41 return members;
42 }
43
44 /**
45 * Score entries using similarity heuristics calculated from the observed and
46 * expected list of members. We could be much less naive and penalize spurious
47 * methods, prefer entries with class level comments, etc. This method is
48 * needed becase we extract entries for each of the top search results for
49 * each class name and rely on these scores to determine which entry was
50 * best. Typically all scores but one will be zero. Multiple pages have
51 * non-zero scores when MDN has multiple pages on the same class or pages on
52 * similar classes (e.g. HTMLElement and Element), or pages on Mozilla
53 * specific classes that are similar to DOM classes (Console).
54 */
55 num scoreEntry(Map entry, String type) {
56 num score = 0;
57 // TODO(jacobr): consider removing skipped entries completely instead of
58 // just giving them lower scores.
59 if (!entry.containsKey('skipped')) {
60 score++;
61 }
62 if (entry.containsKey("members")) {
63 Map members = getMembersMap(entry);
64 for (String name in members.getKeys()) {
65 if (hasAny(type, name)) {
66 score++;
67 }
68 }
69 }
70 return score;
71 }
72
73 /**
74 * Given a list of candidates for the documentation for a type, find the one
75 * that is the best.
76 */
77 Map pickBestEntry(List entries, String type) {
78 num bestScore = -1;
79 Map bestEntry;
80 for (Map entry in entries) {
81 if (entry != null) {
82 num score = scoreEntry(entry, type);
83 if (score > bestScore) {
84 bestScore = score;
85 bestEntry = entry;
86 }
87 }
88 }
89 return bestEntry;
90 }
OLDNEW
« no previous file with comments | « utils/apidoc/mdn/prettyPrint.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698