sentence_interpreter 0.0.6 → 0.0.7
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 +4 -4
- data/.byebug_history +31 -0
- data/README.md +38 -0
- data/lib/lexicon/noun_lexicon.rb +3 -0
- data/lib/lexicon/verb_lexicon.rb +3 -0
- data/lib/sentence_interpreter.rb +2 -2
- data/lib/sentence_interpreter/nouns.rb +7 -0
- data/lib/sentence_interpreter/phrases.rb +23 -0
- data/lib/sentence_interpreter/verbs.rb +7 -0
- data/sentence_interpreter.gemspec +14 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc213715cef62da90246a4ef7cdba77a56fcca96
|
4
|
+
data.tar.gz: 2a595c63d6845ecd8c0310e8ddab361ffb4844fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c665e9989a22e2e35b2d847d79c4bbed9db311295503b7f3accf0a1fc1b61161f9709f6123f10a335063ccc724be3d2b556968b2c3543c99832d7890a90284f4
|
7
|
+
data.tar.gz: 6bc94725901194f8924864737cd6c73b1fe2da3f2d809757a0ced2ed1268cb6fb9bc7527f96428a6ad86ab4b755a963b1a560ddc38fc8d546d73b35005776315
|
data/.byebug_history
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
continue
|
2
|
+
next
|
3
|
+
continue
|
4
|
+
phrases
|
5
|
+
phrases[-1].class
|
6
|
+
next
|
7
|
+
Nouns.include?(word)
|
8
|
+
NounLexicon
|
9
|
+
continue
|
10
|
+
VerbLexicon
|
11
|
+
NounsLexicon
|
12
|
+
NounLexicon
|
13
|
+
Nouns.include?(word)
|
14
|
+
word
|
15
|
+
continue
|
16
|
+
next
|
17
|
+
word
|
18
|
+
sentence
|
19
|
+
continue
|
20
|
+
VerbLexicon
|
21
|
+
verbs
|
22
|
+
word
|
23
|
+
Verbs.include?(word)
|
24
|
+
sentence
|
25
|
+
continue
|
26
|
+
sentence
|
27
|
+
sentenc
|
28
|
+
continue
|
29
|
+
sentence
|
30
|
+
continue
|
31
|
+
sentence
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
## How to run:
|
2
|
+
|
3
|
+
This file can be run from the command line.
|
4
|
+
|
5
|
+
```shell
|
6
|
+
ruby sentence_interpreter.rb <sentence>
|
7
|
+
```
|
8
|
+
|
9
|
+
#### Rules
|
10
|
+
|
11
|
+
- Nouns must have a preceeding verb
|
12
|
+
- When a verb is found, it becomes the 'verb' for the phrase and the rest
|
13
|
+
of the nouns (until the next verb) become the nouns of the phrase
|
14
|
+
- `nouns` and `verbs` are defined as those included in `lexicon/`. All other words will be ignored.
|
15
|
+
|
16
|
+
#### Examples
|
17
|
+
|
18
|
+
```shell
|
19
|
+
Sentence="search google for roses"
|
20
|
+
ruby sentence_interpreter $Sentence
|
21
|
+
```
|
22
|
+
|
23
|
+
The sentence will be parsed into all Verb Noun phrases
|
24
|
+
given the definitions provided in lexicon/
|
25
|
+
|
26
|
+
Because of the verb-first rule, `"Visit website gmail"` is fine
|
27
|
+
but `"gmail visit"` is not ok.
|
28
|
+
|
29
|
+
`"Visit gmail inbox and visit Github inbox"` would be a valid example of a sentence with two Verb Noun phrases. The results would be:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
[
|
33
|
+
{ verb: "visit", nouns: ["gmail", "inbox"] },
|
34
|
+
{ verb: "visit", nouns: ["github", "inbox"]
|
35
|
+
]
|
36
|
+
```
|
37
|
+
|
38
|
+
The script will output this in JSON stringified form.
|
data/lib/sentence_interpreter.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative './verbs.rb'
|
2
|
+
require_relative './nouns.rb'
|
3
|
+
|
4
|
+
class NounBeforeVerbError < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class Phrases
|
8
|
+
def self.new(sentence='')
|
9
|
+
sentence.downcase.split(" ").reduce([]) do |phrases, word|
|
10
|
+
phrases.tap do |phrases|
|
11
|
+
if Verbs.include?(word)
|
12
|
+
phrases << {verb: word}
|
13
|
+
elsif Nouns.include?(word)
|
14
|
+
unless phrases[-1].is_a?(Hash) && phrases[-1][:verb].is_a?(String)
|
15
|
+
raise(NounBeforeVerbError, "This word needs a verb before it: #{word}")
|
16
|
+
end
|
17
|
+
phrases[-1][:nouns] ||= []
|
18
|
+
phrases[-1][:nouns] << word
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.files = `git ls-files -z`.split("\x0")
|
3
|
+
s.require_paths = ['lib', 'lib/sentence_interpreter', 'lib/lexicon']
|
4
|
+
s.name = 'sentence_interpreter'
|
5
|
+
s.version = '0.0.7'
|
6
|
+
s.date = '2016-07-03'
|
7
|
+
s.summary = "Parses a sentence into verb-noun phrases"
|
8
|
+
s.description = ""
|
9
|
+
s.authors = ["Max Pleaner"]
|
10
|
+
s.email = 'maxpleaner@gmail.com'
|
11
|
+
s.homepage =
|
12
|
+
'http://github.com/maxpleaner/sentence_interpreter'
|
13
|
+
s.license = 'MIT'
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentence_interpreter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Pleaner
|
@@ -16,7 +16,15 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- "
|
19
|
+
- ".byebug_history"
|
20
|
+
- README.md
|
21
|
+
- lib/lexicon/noun_lexicon.rb
|
22
|
+
- lib/lexicon/verb_lexicon.rb
|
23
|
+
- lib/sentence_interpreter.rb
|
24
|
+
- lib/sentence_interpreter/nouns.rb
|
25
|
+
- lib/sentence_interpreter/phrases.rb
|
26
|
+
- lib/sentence_interpreter/verbs.rb
|
27
|
+
- sentence_interpreter.gemspec
|
20
28
|
homepage: http://github.com/maxpleaner/sentence_interpreter
|
21
29
|
licenses:
|
22
30
|
- MIT
|