TacTalk 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tactalk.rb +65 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf43332b8dd7e24efa5a79c0b5de3ec974d21034
|
4
|
+
data.tar.gz: 310ac4d5bff021cbef280828c47effbb4e9e0374
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c097b1aaf582d0bdd85532cd2f45645eebddad52758f40652aaea3b621ba23e9d0d997fd5369bbab6def18948c93db4a2c95bd26c80fd5fe7b7a4bafad8ff3a
|
7
|
+
data.tar.gz: ae20c00b65bb4a6166577dd811678167481d779de74bcad0f62a671bb6b9671ff676aaed1fe932cdf8859912013051d9d8a55126e295e182476561b72c6f1ebc
|
data/lib/tactalk.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'words_counted'
|
3
|
+
require 'tokenizer'
|
4
|
+
require 'fuzzy_tools'
|
5
|
+
require 'ruby-tf-idf'
|
6
|
+
require 'lingua/stemmer'
|
7
|
+
require 'pragmatic_segmenter'
|
8
|
+
|
9
|
+
# require 'net/http'
|
10
|
+
# require 'uri'
|
11
|
+
# require 'json'
|
12
|
+
# require 'sanitize'
|
13
|
+
|
14
|
+
class TacTalk
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@docs = []
|
18
|
+
@questions = []
|
19
|
+
|
20
|
+
@struct = Struct.new(:question, :answer, :method)
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_question_document doc
|
24
|
+
parsed = begin
|
25
|
+
YAML.load(File.open(doc))
|
26
|
+
rescue ArgumentError => e
|
27
|
+
puts "Could not parse YAML: #{e.message}"
|
28
|
+
end
|
29
|
+
|
30
|
+
@docs = @docs | parsed
|
31
|
+
@questions = @docs.map { |doc| @struct.new(doc["question"],doc["answer"], doc['method']) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def ask question
|
35
|
+
doc = @questions.fuzzy_find(:question => question)
|
36
|
+
|
37
|
+
return doc["answer"] if doc["method"].nil?
|
38
|
+
|
39
|
+
# doc['method'].constantize.new doc
|
40
|
+
klass = Object.const_get doc['method']
|
41
|
+
klass = klass.new doc
|
42
|
+
klass.run
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_wikipedia_page page
|
47
|
+
url = "http://en.wikipedia.org/w/api.php?format=json&action=parse&page=#{page}"
|
48
|
+
content = Net::HTTP.get(URI.parse(url))
|
49
|
+
|
50
|
+
result = JSON.load content
|
51
|
+
Sanitize.fragment result['parse']['text']['*']
|
52
|
+
end
|
53
|
+
|
54
|
+
# def distance(str1, str2)
|
55
|
+
# return str2.length if str1.empty?
|
56
|
+
# return str1.length if str2.empty?
|
57
|
+
#
|
58
|
+
# return distance(str1[1..-1], str2[1..-1]) if str1[0] == str2[0] # match
|
59
|
+
# l1 = distance(str1, str2[1..-1]) # deletion
|
60
|
+
# l2 = distance(str1[1..-1], str2) # insertion
|
61
|
+
# l3 = distance(str1[1..-1], str2[1..-1]) # substitution
|
62
|
+
# return 1 + [l1,l2,l3].min # increment cost
|
63
|
+
# end
|
64
|
+
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: TacTalk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tacnoman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: words_counted
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tokenizer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fuzzy_tools
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-tf-idf
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby-stemmer
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pragmatic_segmenter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sanitize
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: "....."
|
112
|
+
email: renatocassino@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- lib/tactalk.rb
|
118
|
+
homepage: https://github.com/tacnoman/tactalk
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.5
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Simple tool to create your Question Answer with methods.
|
142
|
+
test_files: []
|
143
|
+
has_rdoc:
|