ruby_qb101 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/data/ruby_qb101.txt +3 -5
- data/lib/ruby_qb101.rb +120 -5
- data.tar.gz.sig +0 -0
- metadata +2 -22
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f95ed43b8b9f7663bd62e4b6d6794ffef6ff2a3d88be2109c9efafc6e301ac01
|
4
|
+
data.tar.gz: 3a2055303a1d1be1428293ca0331b7096e82866a32e8fca7671f96854923bdf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a670add09644a3bca2aa189ca9732286667302a2da646d7a8dbee9f7fda5a03bae309e13ccfa43d144b123be33c4d94b694de3b6c8306934f0c285d848b0d517
|
7
|
+
data.tar.gz: f7e1f95db2e920ab696f78182578e90b76048b6ec71c22d0a41f09d0dd6ad7b6a2dba359103718e025764f0c021df0cd344bd3bb839bd79395d4c4fd2dc711d2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/data/ruby_qb101.txt
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
<?ph schema="book[title,tags]/section[x]"?>
|
2
2
|
|
3
3
|
title: Questions to ask when learning the programming language Ruby
|
4
|
-
tags: ruby learning book questions answers
|
4
|
+
tags: ruby learning book questions answers chatgpt
|
5
5
|
|
6
|
-
# Questions
|
6
|
+
# Ruby: Questions
|
7
7
|
|
8
8
|
## Introduction to Programming
|
9
9
|
|
10
10
|
Write a table of contents for a programming language
|
11
|
-
|
12
11
|
What is an expression in a programming language?
|
13
|
-
|
14
12
|
What is a statement in a programming language?
|
15
13
|
|
16
14
|
|
17
15
|
## Data types
|
18
16
|
|
17
|
+
What are the different data types in the programming language Ruby?
|
19
18
|
Give me an example of using an integer in the programming language Ruby.
|
20
|
-
|
21
19
|
Give me an example of using a boolean in the programming language Ruby.
|
22
20
|
|
data/lib/ruby_qb101.rb
CHANGED
@@ -3,11 +3,16 @@
|
|
3
3
|
# file: ruby_qb101.tb
|
4
4
|
|
5
5
|
# Description: Ruby related questions to ask Chat GPT. #experimental
|
6
|
+
# see https://github.com/jrobertson/ruby_qb101/blob/main/data/ruby_qb101.txt for questions used
|
6
7
|
|
7
8
|
require 'yatoc'
|
8
9
|
require 'polyrex-headings'
|
9
10
|
|
10
11
|
|
12
|
+
# This file contains 2 classes, the question book class and
|
13
|
+
# the answer book class.
|
14
|
+
|
15
|
+
|
11
16
|
class Ruby_Qb101
|
12
17
|
|
13
18
|
def initialize(questions_file=nil)
|
@@ -20,7 +25,7 @@ class Ruby_Qb101
|
|
20
25
|
@px = PolyrexHeadings.new(s, debug: false).to_polyrex
|
21
26
|
|
22
27
|
end
|
23
|
-
|
28
|
+
|
24
29
|
def question(id)
|
25
30
|
|
26
31
|
found = @px.find_by_id(id.to_s)
|
@@ -29,13 +34,38 @@ class Ruby_Qb101
|
|
29
34
|
end
|
30
35
|
|
31
36
|
alias q question
|
37
|
+
|
38
|
+
def questions()
|
39
|
+
doc = Rexle.new('<root>' + self.to_html + '</root>')
|
40
|
+
a = doc.root.xpath('//p/text()').map(&:to_s)
|
41
|
+
end
|
32
42
|
|
43
|
+
def tags()
|
44
|
+
@px.summary.tags
|
45
|
+
end
|
46
|
+
|
47
|
+
def title()
|
48
|
+
@px.summary.title
|
49
|
+
end
|
50
|
+
|
33
51
|
def to_md()
|
34
52
|
@questions
|
35
53
|
end
|
36
54
|
|
37
55
|
def to_html()
|
38
|
-
|
56
|
+
s = @questions.strip.gsub(/^([^\n#].[^\n]+)[\n]+/,'\1' + "\n\n")
|
57
|
+
Kramdown::Document.new(s).to_html
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_prompts()
|
61
|
+
|
62
|
+
# generates a Dynarex file for use with ChatAway class in ChaptGpt2023
|
63
|
+
dx = Dynarex.new('prompts/entry(prompt,type, redo)')
|
64
|
+
|
65
|
+
questions().each {|x| dx.create({prompt: x, type: 'completion'}) }
|
66
|
+
|
67
|
+
return dx
|
68
|
+
|
39
69
|
end
|
40
70
|
|
41
71
|
def to_toc()
|
@@ -48,6 +78,91 @@ class Ruby_Qb101
|
|
48
78
|
|
49
79
|
end
|
50
80
|
|
51
|
-
|
52
|
-
|
53
|
-
#
|
81
|
+
class Ruby_Ab101
|
82
|
+
|
83
|
+
# note: the ab_xml file can be in CGRecorder log XML format
|
84
|
+
|
85
|
+
def initialize(qb_txt, ab_xml=nil, filepath: '.', debug: false)
|
86
|
+
|
87
|
+
@debug = debug
|
88
|
+
|
89
|
+
@qb = Ruby_Qb101.new(qb_txt)
|
90
|
+
|
91
|
+
@dx = Dynarex.new('book[title, tags]/item(question, answer)')
|
92
|
+
@dx.title = @qb.title
|
93
|
+
@dx.tags = @qb.tags
|
94
|
+
|
95
|
+
@qb.questions.each {|q| @dx.create({question: q}) }
|
96
|
+
|
97
|
+
if ab_xml and File.exist?(ab_xml) then
|
98
|
+
|
99
|
+
dx = Dynarex.new(ab_xml)
|
100
|
+
|
101
|
+
# using each question, find the associated answer and
|
102
|
+
# add it the main record
|
103
|
+
|
104
|
+
@qb.questions.each do |q|
|
105
|
+
|
106
|
+
puts 'q: ' + q.inspect if @debug
|
107
|
+
|
108
|
+
# note: the find_by ... method is passing in a regex because passing
|
109
|
+
# in a String causes the xpath to execute which is known to have
|
110
|
+
# a serious bug when the value contains *and*.
|
111
|
+
if dx.schema =~ /question, answer/ then
|
112
|
+
|
113
|
+
found = dx.find_by_question /#{q}/
|
114
|
+
|
115
|
+
if found then
|
116
|
+
rx = @dx.find_by_question /#{q}/
|
117
|
+
rx.answer = found.answer
|
118
|
+
end
|
119
|
+
|
120
|
+
else
|
121
|
+
|
122
|
+
#puts 'dx: ' + dx.to_xml(pretty: true) if @debug
|
123
|
+
found = dx.find_by_prompt /#{q}/
|
124
|
+
puts 'found: ' + found.inspect if @debug
|
125
|
+
|
126
|
+
if found then
|
127
|
+
rx = @dx.find_by_question /#{q}/
|
128
|
+
rx.answer = found.result
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
#@dx.save ab_xml
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def save(filename)
|
142
|
+
@dx.save filename
|
143
|
+
end
|
144
|
+
|
145
|
+
def to_html()
|
146
|
+
|
147
|
+
doc = Rexle.new('<body>' + @qb.to_html.gsub(/<p>[^>]+>/,'<div>\0</div>') \
|
148
|
+
+ '</body>')
|
149
|
+
answers = @dx.all.map(&:answer)
|
150
|
+
|
151
|
+
puts 'answers: ' + answers.inspect if @debug
|
152
|
+
|
153
|
+
doc.root.xpath('//p').each.with_index do |para, i|
|
154
|
+
|
155
|
+
e = Rexle::Element.new('p', attributes: {class: 'answer'})\
|
156
|
+
.add_text answers[i]
|
157
|
+
para.insert_after e
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
doc.root.xml pretty: true
|
162
|
+
end
|
163
|
+
|
164
|
+
def to_xml()
|
165
|
+
@dx.to_xml(pretty: true)
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_qb101
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
bGVzx0RTtnomJUcww7L+cStXvNaGrg+DX+sCtqD5OMHyGROrZb0UHBgTZixAfZGU
|
37
37
|
zfFnOLNq11nlIwZsUbPNwuNZQVZuB+GhTGc=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2023-02-
|
39
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: yatoc
|
@@ -58,26 +58,6 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 0.3.5
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: polyrex-headings
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0.3'
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 0.3.0
|
71
|
-
type: :runtime
|
72
|
-
prerelease: false
|
73
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - "~>"
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0.3'
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 0.3.0
|
81
61
|
description:
|
82
62
|
email: digital.robertson@gmail.com
|
83
63
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|