rdf-yoda_triples 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 +1 -0
- data/Gemfile +3 -0
- data/README.md +26 -0
- data/lib/rdf/yoda_triples.rb +80 -0
- data/rdf-yoda_triples.gemspec +21 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0564290b0bb83103c6043b044a548f1472955d87
|
4
|
+
data.tar.gz: 28800303fc6063651a84b4a9b7bd54d049cc4f8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dba4b93687e57a1689cc2d2f3998e17f4bd9bd8f17ecc24a7ef2dc71890b46a3cb68f6e10e73a7a9545639fa865fee0a477850958dab6c6daf12f30a2e1e4d02
|
7
|
+
data.tar.gz: b76599a202fd7bb19cd1380ba64108b1bc814dcdfdec428dd05c0baee191b6a017f2dfea4448c4dce5ecd98cb670d48d0fee6d71ca79bd5f88352940ba2010b4
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*~
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Yoda Triples
|
2
|
+
============
|
3
|
+
|
4
|
+
Object Subject Predicate, mmgh?
|
5
|
+
|
6
|
+
This way Yoda speaks: <http://en.wikipedia.org/wiki/Object%E2%80%93subject%E2%80%93verb#Fictitious_languages>.
|
7
|
+
|
8
|
+
Usage
|
9
|
+
-----
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
graph = RDF::Graph.new
|
13
|
+
graph << RDF::Statement(RDF::URI('http://example.org/yoda'), RDF.type, RDF::URI('http://example.org/jedi'))
|
14
|
+
graph.dump :yodatriples
|
15
|
+
# => "<http://example.org/jedi> <http://example.org/yoda> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> mmgh?\n"
|
16
|
+
|
17
|
+
reader = RDF::Reader.for(:yodatriples)
|
18
|
+
reader.new(graph.dump(:yodatriples)).each_statement do |statement|
|
19
|
+
puts statement.inspect
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
Specification
|
24
|
+
--------------
|
25
|
+
|
26
|
+
For more information, see the [RDF 1.1 Y-Triples](http://azaroth42.github.io/rdflib-ytriples/docs/) draft specification.
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
|
3
|
+
module RDF::YodaTriples
|
4
|
+
def self.way_of_the_force
|
5
|
+
<<EOM
|
6
|
+
< If you choose the quick and easy path as
|
7
|
+
Vader did - you will become an agent of evil. >
|
8
|
+
\
|
9
|
+
\ ____
|
10
|
+
\ _.' : `._
|
11
|
+
.-.'`. ; .'`.-.
|
12
|
+
__ / : ___ ; /___ ; \ __
|
13
|
+
,'_ ""--.:__;".-.";: :".-.":__;.--"" _`,
|
14
|
+
:' `.t""--.. '<@.`;_ ',@>` ..--""j.' `;
|
15
|
+
`:-.._J '-.-'L__ `-- ' L_..-;'
|
16
|
+
"-.__ ; .-" "-. : __.-"
|
17
|
+
L ' /.------. ' J
|
18
|
+
"-. "--" .-"
|
19
|
+
__.l"-:_JL_;-";.__
|
20
|
+
.-j/'.; ;"""" / .'"-.
|
21
|
+
EOM
|
22
|
+
end
|
23
|
+
|
24
|
+
puts way_of_the_force
|
25
|
+
|
26
|
+
class Writer < RDF::NTriples::Writer
|
27
|
+
def format_triple(subject, predicate, object, options = {})
|
28
|
+
"%s %s %s mmgh?" % [object, subject, predicate].map { |value| format_term(value, options) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Reader < RDF::NTriples::Reader
|
33
|
+
def read_triple
|
34
|
+
loop do
|
35
|
+
readline.strip! # EOFError thrown on end of input
|
36
|
+
line = @line # for backtracking input in case of parse error
|
37
|
+
|
38
|
+
begin
|
39
|
+
unless blank? || read_comment
|
40
|
+
object = read_uriref || read_node || read_literal || fail_object
|
41
|
+
subject = read_uriref || read_node || fail_subject
|
42
|
+
predicate = read_uriref(:intern => true) || fail_predicate
|
43
|
+
|
44
|
+
if validate? && !read_eos
|
45
|
+
raise RDF::ReaderError.new("ERROR [line #{lineno}] Expected end of statement (found: #{current_line.inspect})",
|
46
|
+
lineno: lineno)
|
47
|
+
end
|
48
|
+
return [subject, predicate, object]
|
49
|
+
end
|
50
|
+
rescue RDF::ReaderError => e
|
51
|
+
@line = line # this allows #read_value to work
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Format < RDF::Format
|
59
|
+
content_type 'application/y-triples', :extension => :yt,
|
60
|
+
:alias => ['text/plain', 'application/prs.yoda-triples', 'application/prs.y-triples']
|
61
|
+
content_encoding 'utf-8'
|
62
|
+
|
63
|
+
reader { RDF::YodaTriples::Reader }
|
64
|
+
writer { RDF::YodaTriples::Writer }
|
65
|
+
|
66
|
+
def self.detect(sample)
|
67
|
+
!!sample.match(%r(
|
68
|
+
(?:(?:<[^>]*>) | (?:_:\w+) | (?:"[^"\n]*"(?:^^|@\S+)?)) # Object
|
69
|
+
\s*
|
70
|
+
(?:(?:<[^>]*>) | (?:_:\w+)) # Subject
|
71
|
+
\s*
|
72
|
+
(?:<[^>]*>) # Predicate
|
73
|
+
\s*mmgh?
|
74
|
+
)x)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Human readable name for this format
|
78
|
+
def self.name; "Yoda Triples"; end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rdf-yoda_triples"
|
6
|
+
s.version = '0.1.0'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Tom Johnson"]
|
9
|
+
s.homepage = 'https://github.com/no-reply/rdf-yoda_triples'
|
10
|
+
s.email = 'tom@dp.la'
|
11
|
+
s.summary = %q{An RDF serialization for Jedi.}
|
12
|
+
s.description = %q{Object Subject Predicate, mmgh?}
|
13
|
+
s.license = "Unlicense"
|
14
|
+
s.required_ruby_version = '>= 1.9.3'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
|
19
|
+
s.add_dependency('rdf', '>= 1.1')
|
20
|
+
s.add_development_dependency('pry')
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdf-yoda_triples
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Johnson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
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: Object Subject Predicate, mmgh?
|
42
|
+
email: tom@dp.la
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- lib/rdf/yoda_triples.rb
|
51
|
+
- rdf-yoda_triples.gemspec
|
52
|
+
homepage: https://github.com/no-reply/rdf-yoda_triples
|
53
|
+
licenses:
|
54
|
+
- Unlicense
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.9.3
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.2.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: An RDF serialization for Jedi.
|
76
|
+
test_files: []
|
77
|
+
has_rdoc:
|