triplifier 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/triplifier.rb +3 -0
- data/lib/triplifier/node.rb +148 -0
- data/lib/triplifier/simple_objects.rb +71 -0
- data/lib/triplifier/version.rb +3 -0
- data/triplifier.gemspec +23 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2e0e0d12e74f49a3ec93ce4d1cfc3a626afc48cf
|
|
4
|
+
data.tar.gz: 440cf49d88437b71b7beb27c86eb3287b4553e9b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 40282c808571e0fe8b07c80ca2951569660ea1678c716db8f5ab25f685d1eec05cccf6d1348a12bd927fec8699ae9f80c6fced87327dce5065b7a809b43723be
|
|
7
|
+
data.tar.gz: 6eb43766afe573a8168eab894d6586c434e566381135ce489244f97417d978ddf62d8b748ab6da79825bc6ad42a049334ef357917cd3364f69db0628a681f906
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Standa Fifik
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Triplifier
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'triplifier'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install triplifier
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/triplifier.rb
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
module Triplifier
|
|
2
|
+
|
|
3
|
+
module Node
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
def included(base)
|
|
7
|
+
base.extend(ClassMethods)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def uri(string)
|
|
12
|
+
self.class.uri(string)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_turtle
|
|
16
|
+
subject = resource
|
|
17
|
+
ttl = ""
|
|
18
|
+
predicates.each do |predicate|
|
|
19
|
+
objects(predicate).each do |object|
|
|
20
|
+
turtlified, extras = turtlify(object)
|
|
21
|
+
pred = predicate.to_s.split('@')
|
|
22
|
+
if pred.length == 2
|
|
23
|
+
predicate, suffix = pred
|
|
24
|
+
suffix = "@#{suffix}"
|
|
25
|
+
else
|
|
26
|
+
suffix = ''
|
|
27
|
+
end
|
|
28
|
+
pred = predicate.to_s.split('^^')
|
|
29
|
+
if pred.length == 2
|
|
30
|
+
predicate, suffix = pred
|
|
31
|
+
suffix = "^^#{suffix}"
|
|
32
|
+
else
|
|
33
|
+
suffix = ''
|
|
34
|
+
end
|
|
35
|
+
ttl += "#{subject} #{predicate} #{turtlified}#{suffix} .\n" unless turtlified.nil?
|
|
36
|
+
if !extras.nil? && extras.kind_of?(SimpleNode)
|
|
37
|
+
ttl += extras.to_turtle
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
self.class.defines.each do |klass|
|
|
42
|
+
object = klass.new(self)
|
|
43
|
+
ttl += object.to_turtle
|
|
44
|
+
end
|
|
45
|
+
ttl
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def resource
|
|
49
|
+
res = self.class.resource
|
|
50
|
+
if res.kind_of? Proc
|
|
51
|
+
res = instance_eval(&res)
|
|
52
|
+
end
|
|
53
|
+
res = Triplifier::URI.new(res) unless Triplifier::URI.is_uri?(res)
|
|
54
|
+
res
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def predicates
|
|
58
|
+
self.class.subjects.keys
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def objects(predicate = nil)
|
|
62
|
+
objs = []
|
|
63
|
+
if predicate.nil?
|
|
64
|
+
predicates.each do |pred|
|
|
65
|
+
objs.concat objects(pred)
|
|
66
|
+
end
|
|
67
|
+
else
|
|
68
|
+
self.class.subjects[predicate].each do |obj|
|
|
69
|
+
objs.concat(eval(obj))
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
objs
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def eval(object)
|
|
76
|
+
if object.kind_of? Proc
|
|
77
|
+
object = instance_eval(&object)
|
|
78
|
+
elsif object.kind_of? Class
|
|
79
|
+
object = object.new(self)
|
|
80
|
+
end
|
|
81
|
+
object = [object] unless object.kind_of? Array
|
|
82
|
+
object
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def turtlify(object)
|
|
86
|
+
if URI.is_uri? object
|
|
87
|
+
return [object.to_s]
|
|
88
|
+
elsif object.kind_of? Numeric
|
|
89
|
+
return [object.to_s]
|
|
90
|
+
elsif object.kind_of? String
|
|
91
|
+
object = object.gsub("\r","\n").gsub('\\','\\\\\\\\').gsub('"','\\"')
|
|
92
|
+
return nil if object.length == 0
|
|
93
|
+
return ["\"#{object}\""] if object.scan("\n").length == 0
|
|
94
|
+
return ["\"\"\"#{object}\"\"\""]
|
|
95
|
+
elsif object.kind_of?(TrueClass) || object.kind_of?(FalseClass)
|
|
96
|
+
["'#{object}'^^xsd:boolean"]
|
|
97
|
+
elsif object.kind_of? Date
|
|
98
|
+
["\"#{object.iso8601}\"^^xsd:date"]
|
|
99
|
+
elsif object.respond_to? :resource
|
|
100
|
+
[object.resource, object]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
module ClassMethods
|
|
106
|
+
|
|
107
|
+
attr_reader :subjects, :prefixes
|
|
108
|
+
|
|
109
|
+
def resource(string = nil, &block)
|
|
110
|
+
return @resource if string.nil? && !block_given?
|
|
111
|
+
@resource = string.nil? ? block : string
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def subject(predicate, object = nil, &block)
|
|
115
|
+
@subjects = {} if @subjects.nil?
|
|
116
|
+
@subjects[predicate] = [] if @subjects[predicate].nil?
|
|
117
|
+
@subjects[predicate] << (object.nil? ? block : object)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def prefix(ns, uri)
|
|
121
|
+
@prefixes = {} if @prefixes.nil?
|
|
122
|
+
@prefixes[ns] = uri.kind_of?(URI) ? uri : Triplifier::URI.new(uri)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def node(&block)
|
|
126
|
+
klass = Class.new(Triplifier::SimpleNode)
|
|
127
|
+
klass.eval(&block)
|
|
128
|
+
klass
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def defines(&block)
|
|
132
|
+
@defines = [] if @defines.nil?
|
|
133
|
+
return @defines unless block_given?
|
|
134
|
+
klass = Class.new(Triplifier::SimpleNode)
|
|
135
|
+
klass.eval(&block)
|
|
136
|
+
@defines << klass
|
|
137
|
+
klass
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def uri(string)
|
|
141
|
+
Triplifier::URI.new string
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Triplifier
|
|
2
|
+
|
|
3
|
+
class URI
|
|
4
|
+
|
|
5
|
+
def initialize(uri)
|
|
6
|
+
@uri = uri
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
"<#{@uri}>"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.is_uri? (uri)
|
|
14
|
+
uri.kind_of?(Symbol) || uri.kind_of?(URI)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class SimpleNode
|
|
20
|
+
|
|
21
|
+
include Triplifier::Node
|
|
22
|
+
attr_accessor :parent
|
|
23
|
+
|
|
24
|
+
def self.eval(&block)
|
|
25
|
+
instance_eval(&block)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def initialize(parent)
|
|
29
|
+
@parent = parent
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Graph
|
|
35
|
+
|
|
36
|
+
def initialize
|
|
37
|
+
@prefixes = {
|
|
38
|
+
:rdf => Triplifier::URI.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#'),
|
|
39
|
+
:rdfs => Triplifier::URI.new('http://www.w3.org/2000/01/rdf-schema#'),
|
|
40
|
+
:owl => Triplifier::URI.new('http://www.w3.org/2002/07/owl#'),
|
|
41
|
+
:xsd => Triplifier::URI.new('http://www.w3.org/2001/XMLSchema#')
|
|
42
|
+
}
|
|
43
|
+
@nodes = {}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def <<(node)
|
|
47
|
+
if node.kind_of? Array
|
|
48
|
+
node.each { |n| self << n}
|
|
49
|
+
return
|
|
50
|
+
end
|
|
51
|
+
node.class.prefixes.each do |ns, uri|
|
|
52
|
+
#TODO: validation
|
|
53
|
+
@prefixes[ns] = uri
|
|
54
|
+
end
|
|
55
|
+
@nodes[node.resource] = node
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def to_turtle
|
|
59
|
+
ttl = ""
|
|
60
|
+
@prefixes.each do |ns, uri|
|
|
61
|
+
ttl << "@prefix #{ns}: #{uri} . \n"
|
|
62
|
+
end
|
|
63
|
+
@nodes.each do |resource, node|
|
|
64
|
+
ttl << node.to_turtle
|
|
65
|
+
end
|
|
66
|
+
ttl
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
data/triplifier.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'triplifier/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "triplifier"
|
|
8
|
+
spec.version = Triplifier::VERSION
|
|
9
|
+
spec.authors = ["Standa Fifik"]
|
|
10
|
+
spec.email = ["standa.fifik@gmail.com"]
|
|
11
|
+
spec.description = %q{module to simplify conversion to RDF triplets}
|
|
12
|
+
spec.summary = %q{module to simplify conversion to RDF triplets}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: triplifier
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Standa Fifik
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: module to simplify conversion to RDF triplets
|
|
42
|
+
email:
|
|
43
|
+
- standa.fifik@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- .gitignore
|
|
49
|
+
- Gemfile
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- lib/triplifier.rb
|
|
54
|
+
- lib/triplifier/node.rb
|
|
55
|
+
- lib/triplifier/simple_objects.rb
|
|
56
|
+
- lib/triplifier/version.rb
|
|
57
|
+
- triplifier.gemspec
|
|
58
|
+
homepage: ''
|
|
59
|
+
licenses:
|
|
60
|
+
- MIT
|
|
61
|
+
metadata: {}
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - '>='
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubyforge_project:
|
|
78
|
+
rubygems_version: 2.1.9
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 4
|
|
81
|
+
summary: module to simplify conversion to RDF triplets
|
|
82
|
+
test_files: []
|