aspen-cli 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.github/FUNDING.yml +12 -0
  3. data/.gitignore +16 -0
  4. data/.travis.yml +6 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +175 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +84 -0
  10. data/Rakefile +10 -0
  11. data/aspen.gemspec +48 -0
  12. data/bin/aspen +3 -0
  13. data/bin/console +22 -0
  14. data/bin/setup +8 -0
  15. data/lib/aspen/abstract_parser.rb +72 -0
  16. data/lib/aspen/abstract_statement.rb +34 -0
  17. data/lib/aspen/actions/compile.rb +31 -0
  18. data/lib/aspen/actions/push.rb +39 -0
  19. data/lib/aspen/actions/watch.rb +55 -0
  20. data/lib/aspen/actions.rb +8 -0
  21. data/lib/aspen/adapters.rb +38 -0
  22. data/lib/aspen/ast/nodes/attribute.rb +16 -0
  23. data/lib/aspen/ast/nodes/comment.rb +15 -0
  24. data/lib/aspen/ast/nodes/content.rb +17 -0
  25. data/lib/aspen/ast/nodes/custom_statement.rb +19 -0
  26. data/lib/aspen/ast/nodes/edge.rb +15 -0
  27. data/lib/aspen/ast/nodes/label.rb +15 -0
  28. data/lib/aspen/ast/nodes/narrative.rb +15 -0
  29. data/lib/aspen/ast/nodes/node.rb +20 -0
  30. data/lib/aspen/ast/nodes/statement.rb +17 -0
  31. data/lib/aspen/ast/nodes/type.rb +46 -0
  32. data/lib/aspen/ast.rb +18 -0
  33. data/lib/aspen/cli/commands/build.rb +26 -0
  34. data/lib/aspen/cli/commands/build_steps.rb +204 -0
  35. data/lib/aspen/cli/commands/compile.rb +27 -0
  36. data/lib/aspen/cli/commands/generate.rb +23 -0
  37. data/lib/aspen/cli/commands/new.rb +115 -0
  38. data/lib/aspen/cli/commands/push.rb +15 -0
  39. data/lib/aspen/cli/commands/version.rb +15 -0
  40. data/lib/aspen/cli/commands/watch.rb +30 -0
  41. data/lib/aspen/cli/commands.rb +28 -0
  42. data/lib/aspen/cli/templates/.gitignore +6 -0
  43. data/lib/aspen/cli/templates/airtable.yml +1 -0
  44. data/lib/aspen/cli/templates/convert +16 -0
  45. data/lib/aspen/cli/templates/db.yml.erb +22 -0
  46. data/lib/aspen/cli/templates/docker-compose.yml +23 -0
  47. data/lib/aspen/cli/templates/manifest.yml.erb +31 -0
  48. data/lib/aspen/cli.rb +9 -0
  49. data/lib/aspen/compiler.rb +209 -0
  50. data/lib/aspen/contracts/default_attribute_contract.rb +29 -0
  51. data/lib/aspen/contracts.rb +1 -0
  52. data/lib/aspen/conversion.rb +43 -0
  53. data/lib/aspen/custom_grammar/ast/nodes/bare.rb +17 -0
  54. data/lib/aspen/custom_grammar/ast/nodes/capture_segment.rb +19 -0
  55. data/lib/aspen/custom_grammar/ast/nodes/content.rb +17 -0
  56. data/lib/aspen/custom_grammar/ast/nodes/expression.rb +17 -0
  57. data/lib/aspen/custom_grammar/ast.rb +13 -0
  58. data/lib/aspen/custom_grammar/compiler.rb +80 -0
  59. data/lib/aspen/custom_grammar/grammar.rb +78 -0
  60. data/lib/aspen/custom_grammar/lexer.rb +76 -0
  61. data/lib/aspen/custom_grammar/matcher.rb +43 -0
  62. data/lib/aspen/custom_grammar/parser.rb +51 -0
  63. data/lib/aspen/custom_grammar.rb +23 -0
  64. data/lib/aspen/custom_statement.rb +35 -0
  65. data/lib/aspen/discourse.rb +122 -0
  66. data/lib/aspen/edge.rb +35 -0
  67. data/lib/aspen/errors.rb +158 -0
  68. data/lib/aspen/helpers.rb +17 -0
  69. data/lib/aspen/lexer.rb +195 -0
  70. data/lib/aspen/list.rb +19 -0
  71. data/lib/aspen/node.rb +53 -0
  72. data/lib/aspen/parser.rb +183 -0
  73. data/lib/aspen/renderers/abstract_renderer.rb +22 -0
  74. data/lib/aspen/renderers/cypher_base_renderer.rb +36 -0
  75. data/lib/aspen/renderers/cypher_batch_renderer.rb +55 -0
  76. data/lib/aspen/renderers/cypher_renderer.rb +18 -0
  77. data/lib/aspen/renderers/gexf_renderer.rb +47 -0
  78. data/lib/aspen/renderers/json_renderer.rb +40 -0
  79. data/lib/aspen/renderers.rb +9 -0
  80. data/lib/aspen/schemas/discourse_schema.rb +64 -0
  81. data/lib/aspen/schemas/grammar_schema.rb +24 -0
  82. data/lib/aspen/statement.rb +42 -0
  83. data/lib/aspen/system_default.rb +12 -0
  84. data/lib/aspen/version.rb +3 -0
  85. data/lib/aspen.rb +65 -0
  86. metadata +300 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 400c18c8445558b854ce7a15ba4d21918f65fbc63830a3f28146b67af00ec296
4
+ data.tar.gz: f2f6d60d7b1ca2cdfb8d5ade61121d6cae332ad793d792a818ef3dc8b0f16008
5
+ SHA512:
6
+ metadata.gz: e6449be7bff4bf4e28f50e79a6783b56f1b59000c87c767a421777e8fabd2df866f7da9a02ed89aae6cbb9be10251d9d940d4b55c88e73b5398bb98d6d303816
7
+ data.tar.gz: c496e65c4b94e523bb294a35478933787582f0177c0303b729f4bf4fdab62bd5216ebfbe36c9ae3ce44f96161aae8ce6284a0dbd954238a1109f065f5f9ca4dc
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [beechnut]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /vendor/
11
+ /examples/
12
+
13
+ .DS_Store
14
+
15
+ # Ignore sample project
16
+ myproject/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at cloyd.matt@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in aspen.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "dry-schema", github: "beechnut/dry-schema", ref: "fix-array-validation"
data/Gemfile.lock ADDED
@@ -0,0 +1,175 @@
1
+ GIT
2
+ remote: https://github.com/beechnut/dry-schema.git
3
+ revision: 5192d5e7c4d21406ad087a992049ab9fb24ac6fa
4
+ ref: fix-array-validation
5
+ specs:
6
+ dry-schema (1.5.0)
7
+ concurrent-ruby (~> 1.0)
8
+ dry-configurable (~> 0.8, >= 0.8.3)
9
+ dry-core (~> 0.4)
10
+ dry-equalizer (~> 0.2)
11
+ dry-initializer (~> 3.0)
12
+ dry-logic (~> 1.0)
13
+ dry-types (~> 1.4)
14
+
15
+ PATH
16
+ remote: .
17
+ specs:
18
+ aspen-cli (0.1.0)
19
+ activesupport (~> 6.0)
20
+ airtable (~> 0.0)
21
+ dry-cli (= 0.6.0)
22
+ dry-container (~> 0.7)
23
+ dry-monads (~> 1.0)
24
+ dry-types (~> 1.0)
25
+ dry-validation (= 1.5.0)
26
+ listen (~> 3.0)
27
+ mustache (~> 1.0)
28
+ neo4j-core (= 9.0.0)
29
+
30
+ GEM
31
+ remote: https://rubygems.org/
32
+ specs:
33
+ activesupport (6.1.4.1)
34
+ concurrent-ruby (~> 1.0, >= 1.0.2)
35
+ i18n (>= 1.6, < 2)
36
+ minitest (>= 5.1)
37
+ tzinfo (~> 2.0)
38
+ zeitwerk (~> 2.3)
39
+ airtable (0.0.9)
40
+ httparty
41
+ coderay (1.1.2)
42
+ concurrent-ruby (1.1.6)
43
+ diff-lcs (1.3)
44
+ dry-cli (0.6.0)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-configurable (0.11.5)
47
+ concurrent-ruby (~> 1.0)
48
+ dry-core (~> 0.4, >= 0.4.7)
49
+ dry-equalizer (~> 0.2)
50
+ dry-container (0.7.2)
51
+ concurrent-ruby (~> 1.0)
52
+ dry-configurable (~> 0.1, >= 0.1.3)
53
+ dry-core (0.4.9)
54
+ concurrent-ruby (~> 1.0)
55
+ dry-equalizer (0.3.0)
56
+ dry-inflector (0.2.0)
57
+ dry-initializer (3.0.3)
58
+ dry-logic (1.0.6)
59
+ concurrent-ruby (~> 1.0)
60
+ dry-core (~> 0.2)
61
+ dry-equalizer (~> 0.2)
62
+ dry-monads (1.3.5)
63
+ concurrent-ruby (~> 1.0)
64
+ dry-core (~> 0.4, >= 0.4.4)
65
+ dry-equalizer
66
+ dry-types (1.4.0)
67
+ concurrent-ruby (~> 1.0)
68
+ dry-container (~> 0.3)
69
+ dry-core (~> 0.4, >= 0.4.4)
70
+ dry-equalizer (~> 0.3)
71
+ dry-inflector (~> 0.1, >= 0.1.2)
72
+ dry-logic (~> 1.0, >= 1.0.2)
73
+ dry-validation (1.5.0)
74
+ concurrent-ruby (~> 1.0)
75
+ dry-container (~> 0.7, >= 0.7.1)
76
+ dry-core (~> 0.4)
77
+ dry-equalizer (~> 0.2)
78
+ dry-initializer (~> 3.0)
79
+ dry-schema (~> 1.5)
80
+ ethon (0.14.0)
81
+ ffi (>= 1.15.0)
82
+ faraday (1.8.0)
83
+ faraday-em_http (~> 1.0)
84
+ faraday-em_synchrony (~> 1.0)
85
+ faraday-excon (~> 1.1)
86
+ faraday-httpclient (~> 1.0.1)
87
+ faraday-net_http (~> 1.0)
88
+ faraday-net_http_persistent (~> 1.1)
89
+ faraday-patron (~> 1.0)
90
+ faraday-rack (~> 1.0)
91
+ multipart-post (>= 1.2, < 3)
92
+ ruby2_keywords (>= 0.0.4)
93
+ faraday-em_http (1.0.0)
94
+ faraday-em_synchrony (1.0.0)
95
+ faraday-excon (1.1.0)
96
+ faraday-httpclient (1.0.1)
97
+ faraday-net_http (1.0.1)
98
+ faraday-net_http_persistent (1.2.0)
99
+ faraday-patron (1.0.0)
100
+ faraday-rack (1.0.0)
101
+ faraday_middleware (1.1.0)
102
+ faraday (~> 1.0)
103
+ faraday_middleware-multi_json (0.0.6)
104
+ faraday_middleware
105
+ multi_json
106
+ ffi (1.15.4)
107
+ httparty (0.20.0)
108
+ mime-types (~> 3.0)
109
+ multi_xml (>= 0.5.2)
110
+ httpclient (2.8.3)
111
+ i18n (1.8.10)
112
+ concurrent-ruby (~> 1.0)
113
+ json (2.5.1)
114
+ listen (3.7.0)
115
+ rb-fsevent (~> 0.10, >= 0.10.3)
116
+ rb-inotify (~> 0.9, >= 0.9.10)
117
+ method_source (0.9.2)
118
+ mime-types (3.3.1)
119
+ mime-types-data (~> 3.2015)
120
+ mime-types-data (3.2021.0901)
121
+ minitest (5.14.4)
122
+ multi_json (1.15.0)
123
+ multi_xml (0.6.0)
124
+ multipart-post (2.1.1)
125
+ mustache (1.1.1)
126
+ neo4j-core (9.0.0)
127
+ activesupport (>= 4.0)
128
+ faraday (>= 0.9.0)
129
+ faraday_middleware (>= 0.10.0)
130
+ faraday_middleware-multi_json
131
+ httpclient
132
+ json
133
+ multi_json
134
+ net_tcp_client (>= 2.0.1)
135
+ typhoeus (>= 1.1.2)
136
+ net_tcp_client (2.2.0)
137
+ pry (0.12.2)
138
+ coderay (~> 1.1.0)
139
+ method_source (~> 0.9.0)
140
+ rake (12.3.3)
141
+ rb-fsevent (0.11.0)
142
+ rb-inotify (0.10.1)
143
+ ffi (~> 1.0)
144
+ rspec (3.9.0)
145
+ rspec-core (~> 3.9.0)
146
+ rspec-expectations (~> 3.9.0)
147
+ rspec-mocks (~> 3.9.0)
148
+ rspec-core (3.9.1)
149
+ rspec-support (~> 3.9.1)
150
+ rspec-expectations (3.9.0)
151
+ diff-lcs (>= 1.2.0, < 2.0)
152
+ rspec-support (~> 3.9.0)
153
+ rspec-mocks (3.9.1)
154
+ diff-lcs (>= 1.2.0, < 2.0)
155
+ rspec-support (~> 3.9.0)
156
+ rspec-support (3.9.2)
157
+ ruby2_keywords (0.0.5)
158
+ typhoeus (1.4.0)
159
+ ethon (>= 0.9.0)
160
+ tzinfo (2.0.4)
161
+ concurrent-ruby (~> 1.0)
162
+ zeitwerk (2.4.2)
163
+
164
+ PLATFORMS
165
+ ruby
166
+
167
+ DEPENDENCIES
168
+ aspen-cli!
169
+ dry-schema!
170
+ pry (~> 0.12)
171
+ rake (~> 12.0)
172
+ rspec (~> 3.2)
173
+
174
+ BUNDLED WITH
175
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Matthew J Cloyd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Aspen
2
+
3
+ Aspen is a simple markup language that transforms simple narrative information into rich graph data for use in Neo4j.
4
+
5
+ To put it another way, Aspen transforms narrative text to Cypher, specifically for use in creating graph data.
6
+
7
+ In short, Aspen transforms this:
8
+
9
+ ```aspen
10
+ (Liz) [knows] (Jack)
11
+ ```
12
+
13
+ into (roughly) this
14
+
15
+ ```cypher
16
+ MERGE (:Entity { name: "Liz" })-[:KNOWS]->(:Entity { name: "Jack" })
17
+ ```
18
+
19
+ and can push it to a Neo4j database.
20
+
21
+ Want Liz and Jack to be nodes with a `:Person` label? Just add a little config.
22
+
23
+ ```aspen
24
+ default:
25
+ label: Person
26
+ ----
27
+ (Liz) [knows] (Jack)
28
+ ```
29
+
30
+ ```aspen
31
+ MERGE (:Person { name: "Liz" })-[:KNOWS]->(:Person { name: "Jack" })
32
+ ```
33
+
34
+
35
+ ### Installation
36
+
37
+ ```
38
+ $ gem install aspen-cli
39
+ ```
40
+
41
+ Start a new project:
42
+
43
+ ```
44
+ $ aspen new your_project_name_here
45
+ ```
46
+
47
+ ### Documentation
48
+
49
+ [Quickstart Guide](https://github.com/thepeergroup/aspen/wiki/Quickstart-Guide)
50
+
51
+ [Full documentation in the Wiki](https://github.com/thepeergroup/aspen/wiki)
52
+
53
+
54
+ ### Why use Aspen?
55
+
56
+ You need to turn notes and narratives into a network diagram or graph data.
57
+
58
+ You may also want to connect that data to other data, maybe graph data, maybe tabular data.
59
+
60
+ For what you want:
61
+
62
+ - Spreadsheets are too rigid,
63
+ - Machine learning and Natural Language Processing (NLP) are out of reach, and
64
+ - You're ok using command-line tools for now (we hope to offer a GUI soon)
65
+
66
+
67
+ ## Code of Conduct
68
+
69
+ We expect that anyone working on this project will be good and kind to each other. We're developing software about relationships, and anyone who works on this project is expected to have healthy relating skills.
70
+
71
+ Everyone interacting in the Aspen project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/beechnut/aspen/blob/master/CODE_OF_CONDUCT.md).
72
+
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/beechnut/aspen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/beechnut/aspen/blob/master/CODE_OF_CONDUCT.md).
77
+
78
+ If you'd like to see Aspen grow, please [get in touch](https://github.com/thepeergroup/aspen/discussions), whether you're a developer, user, or potential sponsor. We have ideas on ways to grow Aspen, and we need your help to do so, whatever form that help takes.
79
+
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/aspen.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ require_relative 'lib/aspen/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "aspen-cli"
5
+ spec.version = Aspen::VERSION
6
+ spec.authors = ["Matt Cloyd"]
7
+ spec.email = ["cloyd.matt@gmail.com"]
8
+
9
+ spec.summary = %q{
10
+ Aspen turns simple text into graph data, compiling it into Cypher for Neo4j graph databases.
11
+ }
12
+ spec.description = %q{
13
+ Aspen is a simple markup language that renders into Cypher. Write narrative data,
14
+ mark it up, and compile to Cypher.
15
+ }
16
+ spec.homepage = "https://github.com/beechnut/aspen"
17
+ spec.license = "MIT"
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
19
+
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "bin"
32
+ spec.executables = spec.files.grep(%r{^bin/aspen}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "rspec", "~> 3.2"
36
+ spec.add_development_dependency "pry", "~> 0.12"
37
+
38
+ spec.add_dependency "activesupport", "~> 6.0"
39
+ spec.add_dependency "airtable", "~> 0.0"
40
+ spec.add_dependency "dry-cli", "0.6.0"
41
+ spec.add_dependency "dry-container", "~> 0.7"
42
+ spec.add_dependency "dry-monads", "~> 1.0"
43
+ spec.add_dependency "dry-validation", "1.5.0"
44
+ spec.add_dependency "dry-types", "~> 1.0"
45
+ spec.add_dependency "listen", "~> 3.0"
46
+ spec.add_dependency "mustache", "~> 1.0"
47
+ spec.add_dependency "neo4j-core", "9.0.0"
48
+ end
data/bin/aspen ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'aspen/cli'
3
+ Dry::CLI.new(Aspen::CLI::Commands).call
data/bin/console ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['DEBUG'] = "true"
4
+
5
+ require "bundler/setup"
6
+ require "aspen"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ @code = "(Liz) [works at] (Employer, NBC)."
12
+ @tokens = Aspen::Lexer.tokenize(@code)
13
+ @ast = Aspen::Parser.parse(@tokens)
14
+ @compiler = Aspen::Compiler.new(@ast, {})
15
+
16
+ def go
17
+ @compiler.render
18
+ end
19
+
20
+ # (If you use this, don't forget to add pry to your Gemfile!)
21
+ require "pry"
22
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,72 @@
1
+ module Aspen
2
+ class AbstractParser
3
+
4
+ def self.parse(tokens, env={})
5
+ new(tokens).parse
6
+ end
7
+
8
+ # Convenience method
9
+ def self.parse_code(code, env={}, lexer=Aspen::Lexer)
10
+ tokens = lexer.tokenize(code, env)
11
+ parse(tokens, env)
12
+ end
13
+
14
+ attr_reader :tokens, :position
15
+
16
+ def initialize(tokens, env={})
17
+ @tokens = tokens
18
+ # Nothing is done with environment in the parser.
19
+ # Calling #next will start at 0
20
+ @position = 0
21
+ end
22
+
23
+ def expect(*expected_tokens)
24
+ upcoming = tokens[position, expected_tokens.size]
25
+
26
+ if upcoming.map(&:first) == expected_tokens
27
+ advance_by expected_tokens.size
28
+ upcoming
29
+ end
30
+ end
31
+
32
+ def need(*required_tokens)
33
+ upcoming = tokens[position, required_tokens.size]
34
+ expect(*required_tokens) or raise Aspen::ParseError, <<~ERROR
35
+ Unexpected tokens. Expected #{required_tokens.inspect} but got #{upcoming.inspect}
36
+ ERROR
37
+ end
38
+
39
+ def first
40
+ tokens.first
41
+ end
42
+
43
+ def last
44
+ tokens.last
45
+ end
46
+
47
+ def next_token
48
+ t = tokens[position]
49
+ advance
50
+ return t
51
+ end
52
+
53
+ def peek(offset = 0)
54
+ if offset > 0
55
+ tokens[position + 1..position + offset]
56
+ else
57
+ tokens[position]
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def advance
64
+ advance_by 1
65
+ end
66
+
67
+ def advance_by(offset = 1)
68
+ @position += offset
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,34 @@
1
+ module Aspen
2
+ class AbstractStatement
3
+
4
+ # In the abstract, Statements must:
5
+ # - return nodes ([Aspen::Node])
6
+ # - return a Cypher representation of an object (String)
7
+ # - report their type (custom, vanilla, etc.)
8
+
9
+ # @return [String] the type of statement (:vanilla, :custom)
10
+ def type
11
+ raise NotImplementedError, "Find me in #{__FILE__}"
12
+ end
13
+
14
+ # @return [String] a short description the relationship contained in the statement
15
+ # @example Company hired a Person
16
+ # (Company)-[HIRED]->(Person)
17
+ # @example Person knows Person, reciprocally
18
+ # (Person)-[KNOWS]-(Person)
19
+ def signature
20
+ raise NotImplementedError, "Find me in #{__FILE__}"
21
+ end
22
+
23
+ # @return [Array<Aspen::Node>] a list of nodes from the statement
24
+ def nodes
25
+ raise NotImplementedError, "Find me in #{__FILE__}"
26
+ end
27
+
28
+ # @return [String] the Cypher query from this particular statement
29
+ def to_cypher
30
+ raise NotImplementedError, "Find me in #{__FILE__}"
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ module Aspen
2
+ module Actions
3
+ class Compile
4
+
5
+ attr_reader :options
6
+
7
+ def initialize(path, options = {})
8
+ @path = path
9
+ @basename = File.basename(@path, ".aspen")
10
+ dir = File.dirname(@path)
11
+ @dest = File.expand_path("#{@basename}.cql", dir)
12
+ @options = options
13
+ end
14
+
15
+ def call
16
+ compile_to_file
17
+ send_to_database if options.fetch(:database, false)
18
+ end
19
+
20
+ private
21
+
22
+ def compile_to_file
23
+ @cypher ||= Aspen.compile_text(File.read(@path))
24
+ File.open(@dest, 'w') { |file| file << @cypher }
25
+ puts "Compiled #{@basename}.aspen to #{@basename}.cql."
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,39 @@
1
+ require 'neo4j/core'
2
+ require 'neo4j/core/cypher_session/adaptors/http'
3
+
4
+ module Aspen
5
+ module Actions
6
+ class Push
7
+
8
+ def initialize(path: nil, config_path: 'config/db.yml')
9
+ @path_to_cql = path || Dir["build/main-*.cql"].first
10
+ config = YAML::load_file(config_path)
11
+ url = config.fetch("url").strip
12
+ adapter = Neo4j::Core::CypherSession::Adaptors::HTTP.new(url, {})
13
+ @session = Neo4j::Core::CypherSession.new(adapter)
14
+ rescue => e
15
+ puts e.message
16
+ puts e.backtrace
17
+ end
18
+
19
+ def call
20
+ drop
21
+ push
22
+ end
23
+
24
+ def drop
25
+ print "Dropping data from database..."
26
+ @session.query("MATCH (n) DETACH DELETE n")
27
+ print "OK\n"
28
+ end
29
+
30
+ def push
31
+ file = File.read(@path_to_cql)
32
+ print "Pushing data to database from #{@path_to_cql}..."
33
+ @session.query(file)
34
+ print "OK\n"
35
+ end
36
+
37
+ end
38
+ end
39
+ end