grom_native 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +79 -0
- data/Gopkg.lock +170 -0
- data/Gopkg.toml +49 -0
- data/GromNative.gemspec +35 -0
- data/LICENSE.txt +21 -0
- data/Makefile +40 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/gromnative.go +82 -0
- data/ext/gromnative_test.go +150 -0
- data/ext/net/net.go +63 -0
- data/ext/net/spec/methods_test.go +164 -0
- data/ext/net/spec/net_suite_test.go +31 -0
- data/ext/processor/processor.go +104 -0
- data/ext/processor/spec/methods_test.go +102 -0
- data/ext/processor/spec/processor_suite_test.go +16 -0
- data/ext/types/net.proto +25 -0
- data/ext/types/net/net.pb.go +207 -0
- data/lib/grom_native.rb +110 -0
- data/lib/grom_native/node.rb +105 -0
- data/lib/grom_native/version.rb +3 -0
- metadata +199 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
// Code generated by protoc-gen-go. DO NOT EDIT.
|
2
|
+
// source: ext/types/net.proto
|
3
|
+
|
4
|
+
package net
|
5
|
+
|
6
|
+
import (
|
7
|
+
fmt "fmt"
|
8
|
+
proto "github.com/golang/protobuf/proto"
|
9
|
+
math "math"
|
10
|
+
)
|
11
|
+
|
12
|
+
// Reference imports to suppress errors if they are not otherwise used.
|
13
|
+
var _ = proto.Marshal
|
14
|
+
var _ = fmt.Errorf
|
15
|
+
var _ = math.Inf
|
16
|
+
|
17
|
+
// This is a compile-time assertion to ensure that this generated file
|
18
|
+
// is compatible with the proto package it is being compiled against.
|
19
|
+
// A compilation error at this line likely means your copy of the
|
20
|
+
// proto package needs to be updated.
|
21
|
+
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
22
|
+
|
23
|
+
type GetInput struct {
|
24
|
+
Uri string `protobuf:"bytes,1,opt,name=uri,proto3" json:"uri,omitempty"`
|
25
|
+
Headers []*GetInput_Header `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty"`
|
26
|
+
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
27
|
+
XXX_unrecognized []byte `json:"-"`
|
28
|
+
XXX_sizecache int32 `json:"-"`
|
29
|
+
}
|
30
|
+
|
31
|
+
func (m *GetInput) Reset() { *m = GetInput{} }
|
32
|
+
func (m *GetInput) String() string { return proto.CompactTextString(m) }
|
33
|
+
func (*GetInput) ProtoMessage() {}
|
34
|
+
func (*GetInput) Descriptor() ([]byte, []int) {
|
35
|
+
return fileDescriptor_6a2e3e6b7e224274, []int{0}
|
36
|
+
}
|
37
|
+
|
38
|
+
func (m *GetInput) XXX_Unmarshal(b []byte) error {
|
39
|
+
return xxx_messageInfo_GetInput.Unmarshal(m, b)
|
40
|
+
}
|
41
|
+
func (m *GetInput) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
42
|
+
return xxx_messageInfo_GetInput.Marshal(b, m, deterministic)
|
43
|
+
}
|
44
|
+
func (m *GetInput) XXX_Merge(src proto.Message) {
|
45
|
+
xxx_messageInfo_GetInput.Merge(m, src)
|
46
|
+
}
|
47
|
+
func (m *GetInput) XXX_Size() int {
|
48
|
+
return xxx_messageInfo_GetInput.Size(m)
|
49
|
+
}
|
50
|
+
func (m *GetInput) XXX_DiscardUnknown() {
|
51
|
+
xxx_messageInfo_GetInput.DiscardUnknown(m)
|
52
|
+
}
|
53
|
+
|
54
|
+
var xxx_messageInfo_GetInput proto.InternalMessageInfo
|
55
|
+
|
56
|
+
func (m *GetInput) GetUri() string {
|
57
|
+
if m != nil {
|
58
|
+
return m.Uri
|
59
|
+
}
|
60
|
+
return ""
|
61
|
+
}
|
62
|
+
|
63
|
+
func (m *GetInput) GetHeaders() []*GetInput_Header {
|
64
|
+
if m != nil {
|
65
|
+
return m.Headers
|
66
|
+
}
|
67
|
+
return nil
|
68
|
+
}
|
69
|
+
|
70
|
+
type GetInput_Header struct {
|
71
|
+
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
72
|
+
Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
|
73
|
+
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
74
|
+
XXX_unrecognized []byte `json:"-"`
|
75
|
+
XXX_sizecache int32 `json:"-"`
|
76
|
+
}
|
77
|
+
|
78
|
+
func (m *GetInput_Header) Reset() { *m = GetInput_Header{} }
|
79
|
+
func (m *GetInput_Header) String() string { return proto.CompactTextString(m) }
|
80
|
+
func (*GetInput_Header) ProtoMessage() {}
|
81
|
+
func (*GetInput_Header) Descriptor() ([]byte, []int) {
|
82
|
+
return fileDescriptor_6a2e3e6b7e224274, []int{0, 0}
|
83
|
+
}
|
84
|
+
|
85
|
+
func (m *GetInput_Header) XXX_Unmarshal(b []byte) error {
|
86
|
+
return xxx_messageInfo_GetInput_Header.Unmarshal(m, b)
|
87
|
+
}
|
88
|
+
func (m *GetInput_Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
89
|
+
return xxx_messageInfo_GetInput_Header.Marshal(b, m, deterministic)
|
90
|
+
}
|
91
|
+
func (m *GetInput_Header) XXX_Merge(src proto.Message) {
|
92
|
+
xxx_messageInfo_GetInput_Header.Merge(m, src)
|
93
|
+
}
|
94
|
+
func (m *GetInput_Header) XXX_Size() int {
|
95
|
+
return xxx_messageInfo_GetInput_Header.Size(m)
|
96
|
+
}
|
97
|
+
func (m *GetInput_Header) XXX_DiscardUnknown() {
|
98
|
+
xxx_messageInfo_GetInput_Header.DiscardUnknown(m)
|
99
|
+
}
|
100
|
+
|
101
|
+
var xxx_messageInfo_GetInput_Header proto.InternalMessageInfo
|
102
|
+
|
103
|
+
func (m *GetInput_Header) GetKey() string {
|
104
|
+
if m != nil {
|
105
|
+
return m.Key
|
106
|
+
}
|
107
|
+
return ""
|
108
|
+
}
|
109
|
+
|
110
|
+
func (m *GetInput_Header) GetValue() string {
|
111
|
+
if m != nil {
|
112
|
+
return m.Value
|
113
|
+
}
|
114
|
+
return ""
|
115
|
+
}
|
116
|
+
|
117
|
+
type GetOutput struct {
|
118
|
+
Uri string `protobuf:"bytes,1,opt,name=uri,proto3" json:"uri,omitempty"`
|
119
|
+
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
120
|
+
StatusCode int32 `protobuf:"varint,3,opt,name=statusCode,proto3" json:"statusCode,omitempty"`
|
121
|
+
Error string `protobuf:"bytes,4,opt,name=error,proto3" json:"error,omitempty"`
|
122
|
+
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
123
|
+
XXX_unrecognized []byte `json:"-"`
|
124
|
+
XXX_sizecache int32 `json:"-"`
|
125
|
+
}
|
126
|
+
|
127
|
+
func (m *GetOutput) Reset() { *m = GetOutput{} }
|
128
|
+
func (m *GetOutput) String() string { return proto.CompactTextString(m) }
|
129
|
+
func (*GetOutput) ProtoMessage() {}
|
130
|
+
func (*GetOutput) Descriptor() ([]byte, []int) {
|
131
|
+
return fileDescriptor_6a2e3e6b7e224274, []int{1}
|
132
|
+
}
|
133
|
+
|
134
|
+
func (m *GetOutput) XXX_Unmarshal(b []byte) error {
|
135
|
+
return xxx_messageInfo_GetOutput.Unmarshal(m, b)
|
136
|
+
}
|
137
|
+
func (m *GetOutput) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
138
|
+
return xxx_messageInfo_GetOutput.Marshal(b, m, deterministic)
|
139
|
+
}
|
140
|
+
func (m *GetOutput) XXX_Merge(src proto.Message) {
|
141
|
+
xxx_messageInfo_GetOutput.Merge(m, src)
|
142
|
+
}
|
143
|
+
func (m *GetOutput) XXX_Size() int {
|
144
|
+
return xxx_messageInfo_GetOutput.Size(m)
|
145
|
+
}
|
146
|
+
func (m *GetOutput) XXX_DiscardUnknown() {
|
147
|
+
xxx_messageInfo_GetOutput.DiscardUnknown(m)
|
148
|
+
}
|
149
|
+
|
150
|
+
var xxx_messageInfo_GetOutput proto.InternalMessageInfo
|
151
|
+
|
152
|
+
func (m *GetOutput) GetUri() string {
|
153
|
+
if m != nil {
|
154
|
+
return m.Uri
|
155
|
+
}
|
156
|
+
return ""
|
157
|
+
}
|
158
|
+
|
159
|
+
func (m *GetOutput) GetBody() []byte {
|
160
|
+
if m != nil {
|
161
|
+
return m.Body
|
162
|
+
}
|
163
|
+
return nil
|
164
|
+
}
|
165
|
+
|
166
|
+
func (m *GetOutput) GetStatusCode() int32 {
|
167
|
+
if m != nil {
|
168
|
+
return m.StatusCode
|
169
|
+
}
|
170
|
+
return 0
|
171
|
+
}
|
172
|
+
|
173
|
+
func (m *GetOutput) GetError() string {
|
174
|
+
if m != nil {
|
175
|
+
return m.Error
|
176
|
+
}
|
177
|
+
return ""
|
178
|
+
}
|
179
|
+
|
180
|
+
func init() {
|
181
|
+
proto.RegisterType((*GetInput)(nil), "net.GetInput")
|
182
|
+
proto.RegisterType((*GetInput_Header)(nil), "net.GetInput.Header")
|
183
|
+
proto.RegisterType((*GetOutput)(nil), "net.GetOutput")
|
184
|
+
}
|
185
|
+
|
186
|
+
func init() { proto.RegisterFile("ext/types/net.proto", fileDescriptor_6a2e3e6b7e224274) }
|
187
|
+
|
188
|
+
var fileDescriptor_6a2e3e6b7e224274 = []byte{
|
189
|
+
// 260 bytes of a gzipped FileDescriptorProto
|
190
|
+
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x50, 0x4d, 0x4b, 0xc3, 0x40,
|
191
|
+
0x10, 0x25, 0xdd, 0xb6, 0xda, 0xf1, 0x03, 0x59, 0x7b, 0x08, 0x3d, 0x48, 0x28, 0x1e, 0x02, 0xc2,
|
192
|
+
0x6e, 0x89, 0xff, 0x40, 0x0f, 0xd1, 0x8b, 0x42, 0x8e, 0xde, 0x36, 0x66, 0x48, 0x43, 0x9a, 0xdd,
|
193
|
+
0xb0, 0x99, 0x2d, 0xe6, 0xe2, 0x6f, 0x97, 0x6c, 0x08, 0x58, 0xe8, 0x6d, 0xde, 0xdb, 0x7d, 0xf3,
|
194
|
+
0xde, 0x3c, 0xb8, 0xc7, 0x1f, 0x92, 0xd4, 0xb7, 0xd8, 0x49, 0x8d, 0x24, 0x5a, 0x6b, 0xc8, 0x70,
|
195
|
+
0xa6, 0x91, 0xb6, 0xbf, 0x70, 0x99, 0x22, 0xbd, 0xeb, 0xd6, 0x11, 0xbf, 0x03, 0xe6, 0x6c, 0x15,
|
196
|
+
0x06, 0x51, 0x10, 0xaf, 0xb2, 0x61, 0xe4, 0x02, 0x2e, 0xf6, 0xa8, 0x0a, 0xb4, 0x5d, 0x38, 0x8b,
|
197
|
+
0x58, 0x7c, 0x95, 0xac, 0xc5, 0xa0, 0x9f, 0x14, 0xe2, 0xcd, 0x3f, 0x66, 0xd3, 0xa7, 0xcd, 0x0e,
|
198
|
+
0x96, 0x23, 0x35, 0xec, 0xaa, 0xb1, 0x9f, 0x76, 0xd5, 0xd8, 0xf3, 0x35, 0x2c, 0x8e, 0xea, 0xe0,
|
199
|
+
0x30, 0x9c, 0x79, 0x6e, 0x04, 0xdb, 0x12, 0x56, 0x29, 0xd2, 0xa7, 0xa3, 0xf3, 0x01, 0x38, 0xcc,
|
200
|
+
0x73, 0x53, 0xf4, 0x5e, 0x73, 0x9d, 0xf9, 0x99, 0x3f, 0x00, 0x74, 0xa4, 0xc8, 0x75, 0xaf, 0xa6,
|
201
|
+
0xc0, 0x90, 0x45, 0x41, 0xbc, 0xc8, 0xfe, 0x31, 0x83, 0x11, 0x5a, 0x6b, 0x6c, 0x38, 0x1f, 0x8d,
|
202
|
+
0x3c, 0x48, 0x9e, 0x80, 0x7d, 0x20, 0xf1, 0x47, 0x60, 0x29, 0x12, 0xbf, 0x39, 0xb9, 0x63, 0x73,
|
203
|
+
0x3b, 0xc1, 0x31, 0xc8, 0x4b, 0xf2, 0xb5, 0x2b, 0x2b, 0xda, 0xbb, 0x5c, 0x7c, 0x9b, 0x46, 0xba,
|
204
|
+
0xba, 0x55, 0xf6, 0x50, 0xa9, 0x06, 0x35, 0xc9, 0xd2, 0x9a, 0x46, 0x2b, 0xaa, 0x8e, 0x28, 0x4f,
|
205
|
+
0x4a, 0xcd, 0x97, 0xbe, 0xd5, 0xe7, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x0e, 0xcb, 0xab,
|
206
|
+
0x6c, 0x01, 0x00, 0x00,
|
207
|
+
}
|
data/lib/grom_native.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'json'
|
3
|
+
require 'grom'
|
4
|
+
require 'grom_native/version'
|
5
|
+
require 'grom_native/node'
|
6
|
+
|
7
|
+
# Top level namespace for our gem
|
8
|
+
module GromNative
|
9
|
+
extend FFI::Library
|
10
|
+
ffi_lib File.expand_path("../ext/gromnative.so", File.dirname(__FILE__))
|
11
|
+
attach_function :get, [:string], :string
|
12
|
+
|
13
|
+
def self.fetch(uri:, headers: {}, filter: [], decorators: nil)
|
14
|
+
input = { uri: uri, headers: headers, filter: filter }
|
15
|
+
data_struct = JSON.parse(get(uri))
|
16
|
+
|
17
|
+
handle_errors(data_struct)
|
18
|
+
|
19
|
+
build_nodes(data_struct, filter, decorators)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.handle_errors(data_struct)
|
23
|
+
error = nil
|
24
|
+
status_code = data_struct.fetch('status_code', 0)
|
25
|
+
|
26
|
+
if status_code >= 500
|
27
|
+
error = "Server error: #{data_struct['error']}"
|
28
|
+
elsif status_code >= 300 && status_code < 500
|
29
|
+
error = "Client error: #{data_struct['error']}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# require 'irb'; binding.irb
|
33
|
+
error ||= data_struct['error']
|
34
|
+
|
35
|
+
raise StandardError, error if error != "" && error != nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.build_nodes(data_struct, filter, decorators)
|
39
|
+
nodes = []
|
40
|
+
nodes_by_subject = {}
|
41
|
+
filtered_nodes = Array.new(filter.size) { [] }
|
42
|
+
|
43
|
+
data_struct.fetch('statementsBySubject', []).each do |subject, statements|
|
44
|
+
node = GromNative::Node.new(statements, decorators)
|
45
|
+
|
46
|
+
nodes << node
|
47
|
+
nodes_by_subject[subject] = node
|
48
|
+
|
49
|
+
if !filter.empty? && node.respond_to?(:type)
|
50
|
+
node_types = node.blank? ? Array(::Grom::Node::BLANK) : Array(node.type)
|
51
|
+
indexes = node_types.reduce([]) do |memo, type|
|
52
|
+
index = filter.index(type)
|
53
|
+
memo << index if index
|
54
|
+
|
55
|
+
memo
|
56
|
+
end
|
57
|
+
|
58
|
+
indexes.each { |index| filtered_nodes[index] << node }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
link_nodes(nodes_by_subject, data_struct)
|
63
|
+
|
64
|
+
return filtered_nodes.first if filter && filter.size == 1
|
65
|
+
return filtered_nodes if filter
|
66
|
+
|
67
|
+
nodes
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.link_nodes(nodes_by_subject, data_struct)
|
71
|
+
data_struct.fetch('edgesBySubject', {}).each do |subject, predicates|
|
72
|
+
predicates.each do |predicate, object_uris|
|
73
|
+
raise NamingError if predicate == 'type'
|
74
|
+
|
75
|
+
current_node = nodes_by_subject[subject]
|
76
|
+
next if current_node.nil?
|
77
|
+
|
78
|
+
object_uris.each do |object_uri|
|
79
|
+
predicate_name_symbol = "@#{predicate}".to_sym
|
80
|
+
|
81
|
+
# Get the current value (if there is one)
|
82
|
+
current_value = current_node.instance_variable_get(predicate_name_symbol)
|
83
|
+
|
84
|
+
object = current_value
|
85
|
+
|
86
|
+
# If we have stored a string, and there are objects to link, create an empty array
|
87
|
+
current_value_is_string = current_value.is_a?(String)
|
88
|
+
object_is_array_of_strings = object.all? { |entry| entry.is_a?(String) } if object.is_a?(Array)
|
89
|
+
object_by_uri = nodes_by_subject[object_uri]
|
90
|
+
|
91
|
+
object = [] if (current_value_is_string || object_is_array_of_strings) && object_by_uri
|
92
|
+
|
93
|
+
# If the above is correct, and we have an array
|
94
|
+
if object.is_a?(Array)
|
95
|
+
# Insert the current value (only if this is a new array (prevents possible duplication),
|
96
|
+
# the current value is a string, and there are no linked objects to insert)
|
97
|
+
object << current_value if object.empty? && current_value_is_string && object_by_uri.nil?
|
98
|
+
|
99
|
+
# Insert linked objects, if there are any
|
100
|
+
object << object_by_uri if object_by_uri
|
101
|
+
end
|
102
|
+
|
103
|
+
current_node.instance_variable_set(predicate_name_symbol, object)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
self
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module GromNative
|
2
|
+
# A Ruby object populated with n-triple data.
|
3
|
+
#
|
4
|
+
# @since 0.1.0
|
5
|
+
# @attr_reader [Array] statements an array of n-triple statements.
|
6
|
+
class Node
|
7
|
+
BLANK = 'blank_node'.freeze
|
8
|
+
|
9
|
+
attr_reader :statements
|
10
|
+
|
11
|
+
# @param [Array] statements an array of n-triple statements.
|
12
|
+
def initialize(statements, decorators = nil)
|
13
|
+
populate(statements, decorators)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Allows the user to access instance variables as methods or raise an error if the variable is not defined.
|
17
|
+
#
|
18
|
+
# @param [Symbol] method name of method.
|
19
|
+
# @param [Array] *params extra arguments to pass to super.
|
20
|
+
# @param [Block] &block block to pass to super.
|
21
|
+
# @example Accessing instance variables populated from statements
|
22
|
+
# statements = [
|
23
|
+
# RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF.type, 'Person'),
|
24
|
+
# RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF::URI.new('http://example.com/forename'), 'Jane'),
|
25
|
+
# RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF::URI.new('http://example.com/surname'), 'Smith')
|
26
|
+
# ]
|
27
|
+
#
|
28
|
+
# node = Grom::Node.new(statements)
|
29
|
+
#
|
30
|
+
# node.forename #=> 'Jane'
|
31
|
+
#
|
32
|
+
# @example Accessing instance variables created on the fly
|
33
|
+
# statements = [RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF.type, 'Person')]
|
34
|
+
#
|
35
|
+
# node = Grom::Node.new(statements)
|
36
|
+
# node.instance_variable_set('@foo', 'bar')
|
37
|
+
#
|
38
|
+
# node.foo #=> 'bar'
|
39
|
+
#
|
40
|
+
# @raise [NoMethodError] raises error if the method does not exist.
|
41
|
+
def method_missing(method, *params, &block)
|
42
|
+
instance_variable_get("@#{method}".to_sym) || super
|
43
|
+
end
|
44
|
+
|
45
|
+
# Allows the user to check if a Grom::Node responds to an instance variable
|
46
|
+
#
|
47
|
+
# @param [Symbol] method name of method.
|
48
|
+
# @param [Boolean] include_all indicates whether to include private and protected methods (defaults to false).
|
49
|
+
# @example Using respond_to?
|
50
|
+
#
|
51
|
+
# statements = [
|
52
|
+
# RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF.type, 'Person'),
|
53
|
+
# RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF::URI.new('http://example.com/forename'), 'Jane'),
|
54
|
+
# RDF::Statement.new(RDF::URI.new('http://example.com/123'), RDF::URI.new('http://example.com/surname'), 'Smith')
|
55
|
+
# ]
|
56
|
+
|
57
|
+
# node = Grom::Node.new(statements)
|
58
|
+
#
|
59
|
+
# node.respond_to?(:forename) #=> 'Jane'
|
60
|
+
# node.respond_to?(:foo) #=> false
|
61
|
+
def respond_to_missing?(method, include_all = false)
|
62
|
+
instance_variable_get("@#{method}".to_sym) || super
|
63
|
+
end
|
64
|
+
|
65
|
+
# Checks if Grom::Node is a blank node
|
66
|
+
#
|
67
|
+
# @return [Boolean] a boolean depending on whether or not the Grom::Node is a blank node
|
68
|
+
def blank?
|
69
|
+
@graph_id.match(%r(^_:))
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def set_graph_id(statements)
|
75
|
+
graph_id = Grom::Helper.get_id(statements.first['subject'])
|
76
|
+
instance_variable_set('@graph_id'.to_sym, graph_id)
|
77
|
+
end
|
78
|
+
|
79
|
+
def populate(statements, decorators)
|
80
|
+
set_graph_id(statements)
|
81
|
+
statements.each do |statement|
|
82
|
+
predicate = Grom::Helper.get_id(statement['predicate']).to_sym
|
83
|
+
object = RDF::NTriples::Reader.parse_object(statement['object'])
|
84
|
+
|
85
|
+
object = if object.is_a? RDF::URI
|
86
|
+
object.to_s
|
87
|
+
else
|
88
|
+
object.object
|
89
|
+
end
|
90
|
+
|
91
|
+
instance_variable = instance_variable_get("@#{predicate}")
|
92
|
+
|
93
|
+
if instance_variable
|
94
|
+
instance_variable = instance_variable.is_a?(Array) ? instance_variable.flatten : [instance_variable]
|
95
|
+
instance_variable << object
|
96
|
+
instance_variable_set("@#{predicate}", instance_variable)
|
97
|
+
else
|
98
|
+
instance_variable_set("@#{predicate}", object)
|
99
|
+
end
|
100
|
+
|
101
|
+
decorators&.decorate_with_type(self, object) if statement['predicate'] == RDF.type && decorators
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grom_native
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Rayner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: grom
|
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: rdf
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: parliament-grom-decorators
|
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: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.16'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.4'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.4'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- m@rayner.io
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".ruby-version"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- Gopkg.lock
|
154
|
+
- Gopkg.toml
|
155
|
+
- GromNative.gemspec
|
156
|
+
- LICENSE.txt
|
157
|
+
- Makefile
|
158
|
+
- README.md
|
159
|
+
- Rakefile
|
160
|
+
- bin/console
|
161
|
+
- bin/setup
|
162
|
+
- ext/gromnative.go
|
163
|
+
- ext/gromnative_test.go
|
164
|
+
- ext/net/net.go
|
165
|
+
- ext/net/spec/methods_test.go
|
166
|
+
- ext/net/spec/net_suite_test.go
|
167
|
+
- ext/processor/processor.go
|
168
|
+
- ext/processor/spec/methods_test.go
|
169
|
+
- ext/processor/spec/processor_suite_test.go
|
170
|
+
- ext/types/net.proto
|
171
|
+
- ext/types/net/net.pb.go
|
172
|
+
- lib/grom_native.rb
|
173
|
+
- lib/grom_native/node.rb
|
174
|
+
- lib/grom_native/version.rb
|
175
|
+
homepage: https://github.com/mattrayner/nativegrom
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.7.7
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: A GROM implementation using a GO native extension for heavy lifting.
|
199
|
+
test_files: []
|