History

Upgrade TensorFlow docs to v2.0

Lukas Geiger committed 6 years ago

Commit 02e4a381 parent 58c44bf7 files · +101 −48Browse files

Showing the changes to lib/docs (3 of 7 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/tensorflow/clean_html.rb +1 −1
  2. lib/docs/filters/tensorflow/entries.rb +94 −21
  3. lib/docs/scrapers/tensorflow.rb +6 −27
lib/docs/filters/tensorflow/clean_html.rb+1−1
@@ -4,7 +4,7 @@ module Docs · 3 unmodified lines
44 def call
55 @doc = at_css('.devsite-article-inner')
66
7− css('hr', '.devsite-nav', '.devsite-content-footer', '.devsite-article-body > br').remove
7+ css('hr', '.devsite-nav', '.devsite-content-footer', '.devsite-article-body > br', '.devsite-article-meta', 'devsite-nav-buttons').remove
88
99 css('aside.note').each do |node|
1010 node.name = 'blockquote'
lib/docs/filters/tensorflow/entries.rb+94−21
@@ -7,35 +7,108 @@ module Docs · 6 unmodified lines
77 name = at_css('h1').content.strip
88 name.remove! 'class '
99 name.remove! 'struct '
10− name.remove! 'module: '
10+ name.remove! 'Module: '
1111 name.remove! %r{ \(.+\)}
1212 name.sub! %r{(?<!\ )\(.+\)}, '()'
1313 name.remove! %r{\.\z}
14− name.sub! 'tf.contrib', 'contrib' unless version == 'Guide'
1514 name
1615 end
1716
18− TYPE_BY_DIR = {
19− 'get_started' => 'Get Started',
20− 'programmers_guide' => 'Guide',
21− 'tutorials' => 'Tutorials',
22− 'performance' => 'Performance',
23− 'deploy' => 'Deploy',
24− 'extend' => 'Extend'
25− }
26−
2717 def get_type
28− return 'Guides' if base_url.path.start_with?('/api_guides')
29−
30− if version == 'Guide'
31− TYPE_BY_DIR[subpath.split('/').first]
18+ if version == 'Guide' and base_url.path.start_with?('/guide')
19+ 'Guides'
20+ elsif version == 'Guide' and base_url.path.start_with?('/tutorials')
21+ 'Tutorials'
22+ elsif slug.start_with?('tf/audio')
23+ 'tf.audio'
24+ elsif slug.start_with?('tf/autograph')
25+ 'tf.autograph'
26+ elsif slug.start_with?('tf/bitwise')
27+ 'tf.bitwise'
28+ elsif slug.start_with?('tf/compat')
29+ 'tf.compat'
30+ elsif slug.start_with?('tf/config')
31+ 'tf.config'
32+ elsif slug.start_with?('tf/data')
33+ 'tf.data'
34+ elsif slug.start_with?('tf/debugging')
35+ 'tf.debugging'
36+ elsif slug.start_with?('tf/distribute')
37+ 'tf.distribute'
38+ elsif slug.start_with?('tf/dtypes')
39+ 'tf.dtypes'
40+ elsif slug.start_with?('tf/errors')
41+ 'tf.errors'
42+ elsif slug.start_with?('tf/estimator')
43+ 'tf.estimator'
44+ elsif slug.start_with?('tf/experimental')
45+ 'tf.experimental'
46+ elsif slug.start_with?('tf/feature_column')
47+ 'tf.feature_column'
48+ elsif slug.start_with?('tf/graph_util')
49+ 'tf.graph_util'
50+ elsif slug.start_with?('tf/image')
51+ 'tf.image'
52+ elsif slug.start_with?('tf/initializers')
53+ 'tf.initializers'
54+ elsif slug.start_with?('tf/io')
55+ 'tf.io'
56+ elsif slug.start_with?('tf/keras')
57+ 'tf.keras'
58+ elsif slug.start_with?('tf/linalg')
59+ 'tf.linalg'
60+ elsif slug.start_with?('tf/lite')
61+ 'tf.lite'
62+ elsif slug.start_with?('tf/lookup')
63+ 'tf.lookup'
64+ elsif slug.start_with?('tf/losses')
65+ 'tf.losses'
66+ elsif slug.start_with?('tf/math')
67+ 'tf.math'
68+ elsif slug.start_with?('tf/metrics')
69+ 'tf.metrics'
70+ elsif slug.start_with?('tf/nest')
71+ 'tf.nest'
72+ elsif slug.start_with?('tf/nn')
73+ 'tf.nn'
74+ elsif slug.start_with?('tf/optimizers')
75+ 'tf.optimizers'
76+ elsif slug.start_with?('tf/quantization')
77+ 'tf.quantization'
78+ elsif slug.start_with?('tf/queue')
79+ 'tf.queue'
80+ elsif slug.start_with?('tf/ragged')
81+ 'tf.ragged'
82+ elsif slug.start_with?('tf/random')
83+ 'tf.random'
84+ elsif slug.start_with?('tf/raw_ops')
85+ 'tf.raw_ops'
86+ elsif slug.start_with?('tf/saved_model')
87+ 'tf.saved_model'
88+ elsif slug.start_with?('tf/sets')
89+ 'tf.sets'
90+ elsif slug.start_with?('tf/signal')
91+ 'tf.signal'
92+ elsif slug.start_with?('tf/sparse')
93+ 'tf.sparse'
94+ elsif slug.start_with?('tf/strings')
95+ 'tf.strings'
96+ elsif slug.start_with?('tf/summary')
97+ 'tf.summary'
98+ elsif slug.start_with?('tf/sysconfig')
99+ 'tf.sysconfig'
100+ elsif slug.start_with?('tf/test')
101+ 'tf.test'
102+ elsif slug.start_with?('tf/tpu')
103+ 'tf.tpu'
104+ elsif slug.start_with?('tf/train')
105+ 'tf.train'
106+ elsif slug.start_with?('tf/version')
107+ 'tf.version'
108+ elsif slug.start_with?('tf/xla')
109+ 'tf.xla'
32110 else
33− node = at_css('.devsite-nav-item.devsite-nav-active')
34− node = node.ancestors('.devsite-nav-item').first.at_css('.devsite-nav-title')
35− type = node.content
36− type.remove! %r{\.\z}
37− type = 'tf.contrib' if type.start_with?('tf.contrib')
38− type
111+ 'tf'
39112 end
40113 end
41114 end
lib/docs/scrapers/tensorflow.rb+6−27
@@ -4,7 +4,7 @@ module Docs · 3 unmodified lines
44 class Tensorflow < UrlScraper
55 self.name = 'TensorFlow'
66 self.type = 'tensorflow'
7− self.release = '1.8'
7+ self.release = '2.0'
88 self.root_path = 'index.html'
99 self.links = {
1010 home: 'https://www.tensorflow.org/',
@@ -16,44 +16,23 @@ module Docs · 5 unmodified lines
1616 options[:max_image_size] = 300_000
1717 options[:container] = '.devsite-main-content'
1818
19− options[:fix_urls] = ->(url) do
20− url.sub! 'how_tos/../tutorials', 'tutorials'
21− url
22− end
23−
2419 options[:attribution] = <<-HTML
25− &copy; 2018 The TensorFlow Authors. All rights reserved.<br>
20+ &copy; 2019 The TensorFlow Authors. All rights reserved.<br>
2621 Licensed under the Creative Commons Attribution License 3.0.<br>
2722 Code samples licensed under the Apache 2.0 License.
2823 HTML
2924
3025 version 'Python' do
31− include MultipleBaseUrls
32− self.base_urls = ['https://www.tensorflow.org/api_docs/python/', 'https://www.tensorflow.org/api_guides/python/']
26+ self.base_url = 'https://www.tensorflow.org/api_docs/python/'
3327 end
3428
3529 version 'C++' do
36− include MultipleBaseUrls
37− self.base_urls = ['https://www.tensorflow.org/api_docs/cc/', 'https://www.tensorflow.org/api_guides/cc/']
30+ self.base_url = 'https://www.tensorflow.org/api_docs/cc/'
3831 end
3932
4033 version 'Guide' do
41− self.base_url = 'https://www.tensorflow.org/'
42− self.root_path = 'get_started/get_started'
43− self.initial_paths = %w(
44− programmers_guide/reading_data
45− tutorials/mandelbrot
46− performance/performance_guide
47− deploy/hadoop
48− extend/architecture)
49−
50− options[:only_patterns] = [
51− /\Aget_started/,
52− /\Aprogrammers_guide/,
53− /\Atutorials/,
54− /\Aperformance/,
55− /\Adeploy/,
56− /\Aextend/]
34+ include MultipleBaseUrls
35+ self.base_urls = ['https://www.tensorflow.org/guide/', 'https://www.tensorflow.org/tutorials/']
5736 end
5837
5938 def get_latest_version(opts)