lightmodels 0.1.2-java → 0.2.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +8 -0
- data/Rakefile +9 -0
- data/lib/lightmodels/info_extraction.rb +133 -0
- data/lib/lightmodels/jsonser_nav.rb +12 -12
- data/lib/lightmodels/model_building.rb +66 -1
- data/lib/lightmodels/monkey_patching.rb +30 -0
- data/lib/lightmodels/parsing.rb +186 -0
- data/lib/lightmodels/query_serialized.rb +81 -0
- data/lib/lightmodels/rgen_ext.rb +153 -0
- data/lib/lightmodels/serialization.rb +11 -28
- data/lib/lightmodels/version.rb +3 -0
- data/lightmodels.gemspec +29 -0
- data/test/data/node_setCompleted.json +443 -0
- data/test/test_helper.rb +8 -0
- data/test/test_info_extraction.rb +90 -0
- data/test/test_queryserialized.rb +40 -0
- data/test/test_serialization.rb +64 -0
- metadata +122 -32
- checksums.yaml +0 -7
- data/lib/lightmodels/model.rb +0 -11
- data/lib/lightmodels/query.rb +0 -36
- data/lib/lightmodels/stats.rb +0 -69
data/test/test_helper.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MyDummyLanguageSpecificLogic
|
4
|
+
|
5
|
+
def terms_containing_value?(value)
|
6
|
+
return true if ["ciao_come_stai","ciao_come"].include?(value)
|
7
|
+
return false if ["@@@","123.45"].include?(value)
|
8
|
+
raise "Error! invoked with #{value}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_words(value)
|
12
|
+
case value
|
13
|
+
when 'ciao_come_stai'
|
14
|
+
['ciao','come','stai']
|
15
|
+
when 'ciao_come'
|
16
|
+
['ciao','come']
|
17
|
+
else
|
18
|
+
raise "Error! invoked with #{value}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def concat(a,b)
|
23
|
+
"#{a}_#{b}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class MyMetaClass < RGen::MetamodelBuilder::MMBase
|
29
|
+
has_many_attr 'a',String
|
30
|
+
has_many_attr 'b',Float
|
31
|
+
end
|
32
|
+
|
33
|
+
class TestInfoExtaction < Test::Unit::TestCase
|
34
|
+
|
35
|
+
include LightModels::InfoExtraction
|
36
|
+
|
37
|
+
def test_breaker_void_context
|
38
|
+
tb = TermsBreaker.new(MyDummyLanguageSpecificLogic.new)
|
39
|
+
assert_equal ["ciao","come","stai"],tb.terms_in_value("ciao_come_stai")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_breaker_with_frequent_word
|
43
|
+
ctx = MyMetaClass.new
|
44
|
+
ctx.addA 'ciao_come'
|
45
|
+
tb = TermsBreaker.from_context(MyDummyLanguageSpecificLogic.new,ctx)
|
46
|
+
assert_equal ["ciao_come","stai"],tb.terms_in_value("ciao_come_stai")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_empty_values_map
|
50
|
+
ctx = MyMetaClass.new
|
51
|
+
assert_equal({},InfoExtraction.values_map(ctx))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_simple_values_map
|
55
|
+
ctx = MyMetaClass.new
|
56
|
+
ctx.addA 'ciao_come'
|
57
|
+
ctx.addA '@@@'
|
58
|
+
ctx.addB 123.45
|
59
|
+
assert_equal({'ciao_come'=>1,'@@@'=>1,123.45=>1},InfoExtraction.values_map(ctx))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_empty_terms_map
|
63
|
+
n = MyMetaClass.new
|
64
|
+
lsl = MyDummyLanguageSpecificLogic.new
|
65
|
+
tb = TermsBreaker.new lsl
|
66
|
+
assert_equal({},InfoExtraction.terms_map(tb,n))
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_simple_terms_map
|
70
|
+
ctx = MyMetaClass.new
|
71
|
+
n = MyMetaClass.new
|
72
|
+
n.addA 'ciao_come'
|
73
|
+
n.addA '@@@'
|
74
|
+
n.addB 123.45
|
75
|
+
lsl = MyDummyLanguageSpecificLogic.new
|
76
|
+
assert_equal({'ciao'=>1,'come'=>1,'@@@'=>1,'123.45'=>1},InfoExtraction.terms_map(lsl,n,ctx))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_terms_map_with_composition
|
80
|
+
ctx = MyMetaClass.new
|
81
|
+
ctx.addA 'ciao_come'
|
82
|
+
lsl = MyDummyLanguageSpecificLogic.new
|
83
|
+
n = MyMetaClass.new
|
84
|
+
n.addA 'ciao_come_stai'
|
85
|
+
n.addA '@@@'
|
86
|
+
n.addB 123.45
|
87
|
+
assert_equal({'ciao_come'=>1,'stai'=>1,'@@@'=>1,'123.45'=>1},InfoExtraction.terms_map(lsl,n,ctx))
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestQuerySerialized < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_rel_conts_on_complex_node
|
6
|
+
set_completed = JSON.parse(IO.read(File.dirname(__FILE__)+'/data/node_setCompleted.json'))
|
7
|
+
|
8
|
+
assert_equal [
|
9
|
+
'relcont_layoutInformations',
|
10
|
+
'relcont_typeReference',
|
11
|
+
'relcont_arrayDimensionsBefore',
|
12
|
+
'relcont_arrayDimensionsAfter',
|
13
|
+
'relcont_typeParameters',
|
14
|
+
'relcont_parameters',
|
15
|
+
'relcont_exceptions',
|
16
|
+
'relcont_annotationsAndModifiers',
|
17
|
+
'relcont_statements'],
|
18
|
+
LightModels::QuerySerialized.rel_conts(set_completed)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_rel_nonconts_on_complex_node
|
22
|
+
set_completed = JSON.parse(IO.read(File.dirname(__FILE__)+'/data/node_setCompleted.json'))
|
23
|
+
|
24
|
+
assert_equal [
|
25
|
+
'relnoncont_getterFor',
|
26
|
+
'relnoncont_setterFor'],
|
27
|
+
LightModels::QuerySerialized.rel_non_conts(set_completed)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_attrs_on_complex_node
|
31
|
+
set_completed = JSON.parse(IO.read(File.dirname(__FILE__)+'/data/node_setCompleted.json'))
|
32
|
+
|
33
|
+
assert_equal [
|
34
|
+
'attr_name',
|
35
|
+
'attr_getter',
|
36
|
+
'attr_setter'],
|
37
|
+
LightModels::QuerySerialized.attrs(set_completed)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestSerializationRgen < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class Person < RGen::MetamodelBuilder::MMBase
|
6
|
+
has_attr 'name', String
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_to_model_with_single_obj
|
10
|
+
p = Person.build 'pippo'
|
11
|
+
m = Serialization.rgenobject_to_model(p)
|
12
|
+
|
13
|
+
assert_equal 1,m['root']['id']
|
14
|
+
assert_equal 0,m['external_elements'].count
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_to_model_with_attr
|
18
|
+
p = Person.build 'pippo'
|
19
|
+
m = Serialization.rgenobject_to_model(p)
|
20
|
+
|
21
|
+
assert_equal 'pippo',m['root']['attr_name']
|
22
|
+
end
|
23
|
+
|
24
|
+
class Street < RGen::MetamodelBuilder::MMBase
|
25
|
+
has_attr 'name', String
|
26
|
+
end
|
27
|
+
|
28
|
+
class Address < RGen::MetamodelBuilder::MMBase
|
29
|
+
contains_one_uni 'street', Street
|
30
|
+
has_attr 'number', Integer
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_to_model_with_rel_cont_single
|
34
|
+
a = Address.build number: 11
|
35
|
+
a.street = Street.build 'via Cassini'
|
36
|
+
m = Serialization.rgenobject_to_model(a)
|
37
|
+
|
38
|
+
street_serialized = m['root']['relcont_street']
|
39
|
+
assert_not_nil street_serialized
|
40
|
+
assert_equal 'via Cassini',street_serialized['attr_name']
|
41
|
+
end
|
42
|
+
|
43
|
+
class Street < RGen::MetamodelBuilder::MMBase
|
44
|
+
has_attr 'name', String
|
45
|
+
end
|
46
|
+
|
47
|
+
class CityMap < RGen::MetamodelBuilder::MMBase
|
48
|
+
contains_many_uni 'streets', Street
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_to_model_with_rel_cont_multi
|
52
|
+
cm = CityMap.new
|
53
|
+
cm.streets = cm.streets << Street.build('via Cassini')
|
54
|
+
cm.streets = cm.streets << Street.build('piazza Emanuele Filiberto')
|
55
|
+
m = Serialization.rgenobject_to_model(cm)
|
56
|
+
|
57
|
+
streets_serialized = m['root']['relcont_streets']
|
58
|
+
assert_not_nil streets_serialized
|
59
|
+
assert_equal 2, streets_serialized.count
|
60
|
+
assert_equal 'via Cassini',streets_serialized[0]['attr_name']
|
61
|
+
assert_equal 'piazza Emanuele Filiberto',streets_serialized[1]['attr_name']
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
CHANGED
@@ -1,77 +1,167 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightmodels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.1
|
5
6
|
platform: java
|
6
7
|
authors:
|
7
8
|
- Federico Tomassetti
|
8
|
-
autorequire:
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
date: 2013-08-27 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: json
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: !binary |-
|
21
|
+
MA==
|
22
|
+
none: false
|
15
23
|
requirement: !ruby/object:Gem::Requirement
|
16
24
|
requirements:
|
17
|
-
- -
|
25
|
+
- - ">="
|
18
26
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
27
|
+
version: !binary |-
|
28
|
+
MA==
|
29
|
+
none: false
|
30
|
+
prerelease: false
|
20
31
|
type: :runtime
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rgen
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: !binary |-
|
39
|
+
MA==
|
40
|
+
none: false
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: !binary |-
|
46
|
+
MA==
|
47
|
+
none: false
|
21
48
|
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
22
52
|
version_requirements: !ruby/object:Gem::Requirement
|
23
53
|
requirements:
|
24
|
-
- -
|
54
|
+
- - "~>"
|
25
55
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
56
|
+
version: '1.3'
|
57
|
+
none: false
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.3'
|
63
|
+
none: false
|
64
|
+
prerelease: false
|
65
|
+
type: :development
|
27
66
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
67
|
+
name: rake
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: !binary |-
|
73
|
+
MA==
|
74
|
+
none: false
|
29
75
|
requirement: !ruby/object:Gem::Requirement
|
30
76
|
requirements:
|
31
|
-
- -
|
77
|
+
- - ">="
|
32
78
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
|
79
|
+
version: !binary |-
|
80
|
+
MA==
|
81
|
+
none: false
|
35
82
|
prerelease: false
|
83
|
+
type: :development
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: simplecov
|
36
86
|
version_requirements: !ruby/object:Gem::Requirement
|
37
87
|
requirements:
|
38
|
-
- -
|
88
|
+
- - ">="
|
39
89
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
90
|
+
version: !binary |-
|
91
|
+
MA==
|
92
|
+
none: false
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: !binary |-
|
98
|
+
MA==
|
99
|
+
none: false
|
100
|
+
prerelease: false
|
101
|
+
type: :development
|
41
102
|
description: Light format to store models. Mostly they are stored in Hash and Array.
|
42
103
|
email: f.tomassetti@gmail.com
|
43
104
|
executables: []
|
44
105
|
extensions: []
|
45
106
|
extra_rdoc_files: []
|
46
107
|
files:
|
108
|
+
- ".gitignore"
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
47
113
|
- lib/lightmodels.rb
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
114
|
+
- lib/lightmodels/info_extraction.rb
|
115
|
+
- lib/lightmodels/jsonser_nav.rb
|
116
|
+
- lib/lightmodels/model_building.rb
|
117
|
+
- lib/lightmodels/monkey_patching.rb
|
118
|
+
- lib/lightmodels/parsing.rb
|
119
|
+
- lib/lightmodels/query_serialized.rb
|
120
|
+
- lib/lightmodels/rgen_ext.rb
|
121
|
+
- lib/lightmodels/serialization.rb
|
122
|
+
- lib/lightmodels/version.rb
|
123
|
+
- lightmodels.gemspec
|
124
|
+
- test/data/node_setCompleted.json
|
125
|
+
- test/test_helper.rb
|
126
|
+
- test/test_info_extraction.rb
|
127
|
+
- test/test_queryserialized.rb
|
128
|
+
- test/test_serialization.rb
|
129
|
+
homepage: https://github.com/ftomassetti/lightmodels
|
130
|
+
licenses:
|
131
|
+
- APACHE2
|
132
|
+
post_install_message:
|
58
133
|
rdoc_options: []
|
59
134
|
require_paths:
|
60
135
|
- lib
|
61
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
137
|
requirements:
|
63
|
-
- -
|
138
|
+
- - ">="
|
64
139
|
- !ruby/object:Gem::Version
|
65
|
-
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
hash: 2
|
143
|
+
version: !binary |-
|
144
|
+
MA==
|
145
|
+
none: false
|
66
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
147
|
requirements:
|
68
|
-
- -
|
148
|
+
- - ">="
|
69
149
|
- !ruby/object:Gem::Version
|
70
|
-
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
hash: 2
|
153
|
+
version: !binary |-
|
154
|
+
MA==
|
155
|
+
none: false
|
71
156
|
requirements: []
|
72
|
-
rubyforge_project:
|
73
|
-
rubygems_version:
|
74
|
-
signing_key:
|
75
|
-
specification_version:
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 1.8.24
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
76
161
|
summary: Light format to store models
|
77
|
-
test_files:
|
162
|
+
test_files:
|
163
|
+
- test/data/node_setCompleted.json
|
164
|
+
- test/test_helper.rb
|
165
|
+
- test/test_info_extraction.rb
|
166
|
+
- test/test_queryserialized.rb
|
167
|
+
- test/test_serialization.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: e868ed9d49df684c24f6d46cf9d35cfce53799f6
|
4
|
-
data.tar.gz: de01a21493b5d2086f6c8541b5d0332af366b769
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 5107453b1cc675f8ddf165b09b27ece34c01c4f75d44a7379acbdc9f389047fe1e13c3e3897c7d8539492936bae32285e633cd55f781f17a89e98515929db447
|
7
|
-
data.tar.gz: 0fd9d3b21944811c6e73763c24b925b54e9b8edd5fd4879553489b5097592a77c71cb8304509e63c6ae3720890636ebfc6e1d9a0e6df715dccb62560e63ac5fd
|
data/lib/lightmodels/model.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module LightModels
|
2
|
-
|
3
|
-
# A light model. External objects contains a basic description (only type and attributes)
|
4
|
-
# of nodes referred by nodes in the proper model tree.
|
5
|
-
class Model
|
6
|
-
attr_accessor :root
|
7
|
-
attr_accessor :name
|
8
|
-
attr_accessor :external_objects
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
data/lib/lightmodels/query.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'lightmodels/jsonser_nav'
|
3
|
-
|
4
|
-
module LightModels
|
5
|
-
|
6
|
-
module Query
|
7
|
-
|
8
|
-
# the set of values appearing in the object and its children
|
9
|
-
def self.collect_values(el)
|
10
|
-
values = Set.new
|
11
|
-
rel_conts(el).each do |r|
|
12
|
-
values(el,r).each {|c| values.merge(collect_values(c))}
|
13
|
-
end
|
14
|
-
attrs(el).each do |a|
|
15
|
-
values(el,a).each {|v| values.add(v)}
|
16
|
-
end
|
17
|
-
values
|
18
|
-
end
|
19
|
-
|
20
|
-
# a counting map values appearing in the object and its children
|
21
|
-
def self.collect_values_with_count(el)
|
22
|
-
values = Hash.new {|h,k| h[k]=0}
|
23
|
-
rel_conts(el).each do |r|
|
24
|
-
LightModels::Query.values(el,r).each do |ch|
|
25
|
-
collect_values_with_count(ch).each {|v,count| values[v]+=count}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
attrs(el).each do |a|
|
29
|
-
LightModels::Query.values(el,a).each {|v| values[v]+=1 }
|
30
|
-
end
|
31
|
-
values
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|