serendipitous 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 924fcfe7190071fd1934174311cd28817fa222b3
|
|
4
|
+
data.tar.gz: a2e34f897f4bd225acd9a963d3eb60616cfc7231
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 66823a02df2cdd1f6481a6fb213b70ba263565dd29008265f160b55cf96a2de386aa624cf4bed3a811f12297fa0e15feab388df4435befd71ba6bed961bc77ef
|
|
7
|
+
data.tar.gz: be0075a156ef6ef1c7e25282782248ea3f5a584578eff26a8c3bf7ddf44f38e416a918ed163b63e669d44649b113eb9ee772a64d69d416ad1b5def7422b185bb
|
data/lib/serendipitous.rb
CHANGED
|
@@ -4,17 +4,15 @@ class Content
|
|
|
4
4
|
|
|
5
5
|
def initialize fields={}
|
|
6
6
|
defaults = {
|
|
7
|
-
|
|
8
|
-
title: '',
|
|
9
|
-
description: ''
|
|
7
|
+
'source' => 'serendipitous'
|
|
10
8
|
}
|
|
11
9
|
@data = defaults.merge(fields)
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
# TODO: find jesus
|
|
15
|
-
def method_missing method
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
13
|
+
#def method_missing method
|
|
14
|
+
# # TODO: Does this let you data[method][some_list][some_value]
|
|
15
|
+
# data[method]
|
|
16
|
+
#end
|
|
19
17
|
|
|
20
18
|
end
|
|
@@ -11,12 +11,12 @@ class ContentService
|
|
|
11
11
|
|
|
12
12
|
def self.unanswered?(field)
|
|
13
13
|
# TODO: Compare against defaults
|
|
14
|
-
field.length == 0
|
|
14
|
+
field.nil? || field.length == 0
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# TODO: make this smarter
|
|
18
18
|
def self.whitelisted_fields
|
|
19
|
-
@whitelisted_fields ||= %w(
|
|
19
|
+
@whitelisted_fields ||= %w(name description)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
# TODO: make this smarter
|
|
@@ -5,8 +5,11 @@ class QuestionService
|
|
|
5
5
|
# TODO: Make "What is" a token based on content type + field
|
|
6
6
|
# e.g. location-reference --> "Where is _____?""
|
|
7
7
|
field_to_answer = answerable_fields_for(content).keys.sample
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
{
|
|
10
|
+
field: field_to_answer,
|
|
11
|
+
question: build_question(content, field_to_answer)
|
|
12
|
+
}
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def self.answerable_fields_for(content)
|
|
@@ -25,7 +28,6 @@ class QuestionService
|
|
|
25
28
|
|
|
26
29
|
def self.field_type value
|
|
27
30
|
# TODO: piggyback on Watson NLC
|
|
28
|
-
puts "Looking at [#{value.inspect}]"
|
|
29
31
|
case value
|
|
30
32
|
when :best_friend, :mother
|
|
31
33
|
'Character'
|
|
@@ -41,17 +43,17 @@ class QuestionService
|
|
|
41
43
|
when 'Character'
|
|
42
44
|
[
|
|
43
45
|
# e.g. field=best_friend -> "Who is Alice's best friend?"
|
|
44
|
-
"Who is [[
|
|
46
|
+
"Who is [[name]]'s <<field>>?"
|
|
45
47
|
]
|
|
46
48
|
when 'Location'
|
|
47
49
|
[
|
|
48
50
|
# e.g. field=hometown -> "Where is Alice's home town?"
|
|
49
|
-
"Where is [[
|
|
51
|
+
"Where is [[name]]'s <<field>>?"
|
|
50
52
|
]
|
|
51
53
|
when 'Item'
|
|
52
54
|
[
|
|
53
55
|
# e.g. field=favorite_item -> "What is Alice's favorite item?"
|
|
54
|
-
"What is [[
|
|
56
|
+
"What is [[name]]'s <<field>>?"
|
|
55
57
|
]
|
|
56
58
|
when 'Data'
|
|
57
59
|
[
|
|
@@ -60,7 +62,7 @@ class QuestionService
|
|
|
60
62
|
# height -> "How tall is..."
|
|
61
63
|
# weight -> "How much does...weigh?"
|
|
62
64
|
# age -> "How old is..."
|
|
63
|
-
"What is [[
|
|
65
|
+
"What is [[name]]'s <<field>>?"
|
|
64
66
|
]
|
|
65
67
|
else
|
|
66
68
|
[
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
class TemplateService
|
|
3
3
|
# Regex to determine whether a word is in template replacement format
|
|
4
4
|
# e.g. [[user.name]] or [[day_of_week]]
|
|
5
|
-
TOKEN_REGEX =
|
|
5
|
+
TOKEN_REGEX = /(\[\[[^\]]+\]\])/
|
|
6
6
|
# TODO: Support nested template replacement [[e.g. another_user.title]] instead of [[title]]
|
|
7
7
|
|
|
8
8
|
# Regex to find symbolic reductions
|
|
@@ -25,8 +25,7 @@ class TemplateService
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def self.replacement_for token, content
|
|
28
|
-
|
|
29
|
-
content.send token
|
|
28
|
+
content.data[token]
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
private
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: serendipitous
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Brown
|
|
@@ -21,6 +21,7 @@ files:
|
|
|
21
21
|
- lib/serendipitous/content_service.rb
|
|
22
22
|
- lib/serendipitous/prompt_service.rb
|
|
23
23
|
- lib/serendipitous/question_service.rb
|
|
24
|
+
- lib/serendipitous/railtie.rb
|
|
24
25
|
- lib/serendipitous/suggestion_service.rb
|
|
25
26
|
- lib/serendipitous/template_service.rb
|
|
26
27
|
homepage: http://indentlabs.com/serendipitous
|