ontologist 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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjY2MTBhM2JhZjA4OTdkMWE5MGU3YzEyMTEwZGEzMTM0ZWI3NmI4ZA==
5
+ data.tar.gz: !binary |-
6
+ NjIxZTYwM2FjN2JkZjgzNTg5MGI2NTI5OGYxYTE5NTdjNTQ5NzdjYg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzQzMmQyMDg4Nzc1MTM0ZjRiOTU2YmFhZjlmN2NkMTU4Y2JmOTUxZTNlMTg1
10
+ NGExM2FjMmFkMTdiNTNkMjNiMjk2ZGNhMTA3Y2JhMjAxZjlkZTYyNWViODNk
11
+ ZDI4MDUyMWI0ZGQ0MGQyOGE5MzYyM2FmZTdlMGVkZjllOTAzMTI=
12
+ data.tar.gz: !binary |-
13
+ YTA1ODU1MmM4NzgzNjNhNzFlYWIwYmQ5YzlhZGVhYWIxY2U2MTc4ODgxZWYy
14
+ OTk4ZGU1N2Y0YWMwNmU5NDE2Y2NmOWMzY2IxYmRlMmE2YmUzZWQ4Y2NkMTJk
15
+ Yzg1MTdiOGI1YThmMDgwYjQ0ZGE5ZDI5NTAzNGVjZjM3NGZhMmQ=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ontologist.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 John Biesnecker
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
+ # Ontologist
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ontologist'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ontologist
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"
@@ -0,0 +1 @@
1
+ require 'ontologist'
data/lib/ontologist.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "middleman-core"
2
+ require "ontologist/version"
3
+
4
+ ::Middleman::Extensions.register(:ontologist) do
5
+ require "ontologist/extension"
6
+ ::Middleman::Ontologist
7
+ end
@@ -0,0 +1,90 @@
1
+ module Middleman
2
+ module Ontologist
3
+
4
+ class Options
5
+
6
+ KEYS = [
7
+ :uri_tag,
8
+ :date_tag,
9
+ :title_tag,
10
+ :ignore_list,
11
+ :namespaces,
12
+ :default_namespace,
13
+ :aliases,
14
+ :resource_extension_list,
15
+ :publish_future_dated,
16
+ :time_zone,
17
+ :strict
18
+ ]
19
+
20
+ KEYS.each do |name|
21
+ attr_accessor name
22
+ end
23
+
24
+ def initialize(options={})
25
+ options.each do |k,v|
26
+ self.send(:"#{k}=", v)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ class << self
33
+
34
+ def registered(app, options_hash = {}, &block)
35
+ require 'ontologist/ontology'
36
+ require 'ontologist/semantic_resource'
37
+ require 'active_support/core_ext/time/zones'
38
+
39
+ app.set :time_zone, 'UTC'
40
+ app.send :include, Helpers
41
+
42
+ options = Options.new(options_hash)
43
+ yield options if block_given?
44
+
45
+ options.uri_tag ||= "uri"
46
+ options.date_tag ||= "date"
47
+ options.title_tag ||= "title"
48
+ options.ignore_list ||= []
49
+ options.aliases ||= {}
50
+ options.namespaces ||= {}
51
+ options.default_namespace ||= "http://example.org/ns/1.0/"
52
+ options.resource_extension_list ||= ['.html']
53
+ options.publish_future_dated ||= false
54
+ options.time_zone ||= "UTC"
55
+ options.strict ||= true
56
+
57
+ app.after_configuration do
58
+
59
+ # Make sure timezone is set
60
+ zone_default = Time.find_zone!(options.time_zone)
61
+ unless zone_default
62
+ raise 'Value assigned to time_zone not recognized.'
63
+ end
64
+ Time.zone_default = zone_default
65
+
66
+ # initialize the ontology object
67
+ ontology(options)
68
+
69
+ sitemap.register_resource_list_manipulator(:ontology, ontology, false)
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+
78
+ # Template helpers
79
+ module Helpers
80
+ def ontology(options = nil)
81
+ @_ontology ||= Ontology.new(self, options)
82
+ end
83
+
84
+ end
85
+
86
+
87
+
88
+
89
+ end
90
+ end
@@ -0,0 +1,152 @@
1
+ require 'addressable/uri'
2
+ require 'rdf'
3
+ require 'set'
4
+
5
+ module Middleman
6
+
7
+ module Ontologist
8
+
9
+ module Utilities
10
+
11
+ def valid_url?(url)
12
+ parsed = Addressable::URI.parse(url) or return false
13
+ %w(http https).include?(parsed.scheme)
14
+ rescue Addressable::URI::InvalidURIError
15
+ false
16
+ end
17
+
18
+ def convert_predicate(predicate)
19
+
20
+ unless predicate.is_a? RDF::URI
21
+ predicate = RDF::URI.new(resolve_key(predicate))
22
+ end
23
+
24
+ predicate # return it
25
+
26
+ end
27
+
28
+ end
29
+
30
+ class Ontology
31
+
32
+ attr_reader :options
33
+ attr_reader :app
34
+ attr_reader :store
35
+
36
+ def initialize(app, options = {})
37
+ @app = app
38
+ @options = options
39
+
40
+ @_dated_resources = []
41
+ @_uri_map = Hash.new
42
+
43
+ @store = RDF::Graph.new
44
+
45
+ extend Utilities
46
+ end
47
+
48
+ # takes a string key that should resolve into a full URI and tries to resolve it
49
+ def resolve_key(key)
50
+ return nil if key.nil?
51
+
52
+ # is this tag an alias?
53
+ if alias_array = options.aliases.assoc(key)
54
+ key = alias_array[1]
55
+ end
56
+
57
+ # is this a fully formed url?
58
+ unless valid_url? key
59
+
60
+ # resolve the namespace
61
+ parts = key.split("/", 2)
62
+ if parts.count == 1
63
+ # default namespace
64
+ key = options.default_namespace + parts.first
65
+ else
66
+ # should be a predefined namespace
67
+ raise "Abbreviated namespace not found: #{parts.first}" unless options.namespaces.include? parts.first
68
+
69
+ key = options.namespaces[parts.first] + parts.last
70
+ end
71
+
72
+ end
73
+
74
+ key # return the final version
75
+ end
76
+
77
+ def manipulate_resource_list(resources)
78
+
79
+ encountered_uris = Set.new
80
+
81
+ resources.each do |resource|
82
+
83
+ next unless options.resource_extension_list.index(resource.ext)
84
+
85
+ if resource.data[options.uri_tag].nil?
86
+ if options.strict
87
+ raise "All resources with correct extensions must have a URI tag in their YAML frontmatter"
88
+ else
89
+ next
90
+ end
91
+ end
92
+
93
+ resource.extend Middleman::Ontologist::SemanticResource
94
+ resource.ontology = self
95
+ resource.uri = resolve_key(resource.data[options.uri_tag])
96
+
97
+ if encountered_uris.include? resource.uri
98
+ raise "All resources must have unique URIs (multiple resources using #{resource.uri} found)"
99
+ else
100
+ encountered_uris << resource.uri
101
+ end
102
+
103
+
104
+
105
+ resource.data.each do |element|
106
+ key = element.first
107
+ value = element.last
108
+
109
+ # we already have the uri
110
+ next if key == options.uri_tag
111
+
112
+ # should we ignore this key?
113
+ next if options.ignore_list.include? key
114
+
115
+ key = resolve_key(key)
116
+
117
+ processed_values = []
118
+
119
+ if value.is_a? Array
120
+ # value(s) are URIs
121
+ value.each do |v|
122
+ processed_values << RDF::URI.new(resolve_key(v))
123
+ end
124
+ elsif value.is_a? String
125
+ # value is a string literal
126
+ processed_values << RDF::Literal.new(value)
127
+ else
128
+ raise "Don't know how to handle value of class #{value.class.to_s}"
129
+ end
130
+
131
+ processed_values.each do |pv|
132
+ statement = [RDF::URI.new(resource.uri), RDF::URI.new(key), pv]
133
+ store << statement
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+ resources # return the now slightly modified list
141
+
142
+ end
143
+
144
+ def resource_for_uri(uri)
145
+ @_uri_map[uri]
146
+ end
147
+
148
+ end
149
+
150
+ end
151
+
152
+ end
@@ -0,0 +1,42 @@
1
+ require 'active_support/time_with_zone'
2
+ require 'active_support/core_ext/time/calculations'
3
+ require 'rdf'
4
+
5
+ module Middleman
6
+
7
+ module Ontologist
8
+
9
+ module SemanticResource
10
+
11
+ attr_accessor :ontology
12
+ attr_accessor :uri
13
+
14
+ # return all objects connected to self through this predicate
15
+ def objects_through_predicate(predicate)
16
+ predicate = ontology.convert_predicate(predicate)
17
+ ontology.store.query [RDF::URI.new(uri), predicate, nil]
18
+ end
19
+
20
+ # return all subjects connected to self through this predicate
21
+ def subjects_through_predicate(predicate)
22
+ predicate = ontology.convert_predicate(predicate)
23
+ ontology.store.query [nil, predicate, RDF::URI.new(uri)]
24
+ end
25
+
26
+ def objects_with_axis(predicate)
27
+ predicate = ontology.convert_predicate(predicate)
28
+ end
29
+
30
+ def subjects_with_axis(predicate)
31
+ predicate = ontology.convert_predicate(predicate)
32
+ end
33
+
34
+ def body
35
+ render(self, :layout => nil)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Ontologist
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ontologist/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ontologist"
8
+ gem.version = Middleman::Ontologist::VERSION
9
+ gem.authors = ["John Biesnecker"]
10
+ gem.email = ["jbiesnecker@gmail.com"]
11
+ gem.description = %q{Semantic Web/RDF toolkit for Middleman}
12
+ gem.summary = %q{Semantic Web/RDF toolkit for Middleman}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency("middleman-core", ["~> 3.0"])
21
+ gem.add_dependency("middleman-core", ["~> 3.0"])
22
+ gem.add_dependency("tzinfo", ["~> 0.3.0"])
23
+ gem.add_dependency("activesupport", ["~> 3.2.12"])
24
+ gem.add_dependency("rdf", ["~> 1.0.2"])
25
+ gem.add_dependency("addressable", ["~> 2.3.3"])
26
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ontologist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Biesnecker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: middleman-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tzinfo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.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: 0.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.12
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.12
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdf
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: addressable
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.3.3
97
+ description: Semantic Web/RDF toolkit for Middleman
98
+ email:
99
+ - jbiesnecker@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/middleman_extension.rb
110
+ - lib/ontologist.rb
111
+ - lib/ontologist/extension.rb
112
+ - lib/ontologist/ontology.rb
113
+ - lib/ontologist/semantic_resource.rb
114
+ - lib/ontologist/version.rb
115
+ - ontologist.gemspec
116
+ homepage: ''
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.0
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Semantic Web/RDF toolkit for Middleman
139
+ test_files: []