rdf_schema_generator 1.0.0
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.
- data/USAGE +15 -0
- data/rdf_schema_generator.rb +52 -0
- data/templates/schema.rb +14 -0
- metadata +49 -0
data/USAGE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Description:
|
2
|
+
The rdf schema generator creates a class containing constants for
|
3
|
+
properties and classes defined in an rdf schema.
|
4
|
+
|
5
|
+
The generator takes a namespace prefix and a url of a
|
6
|
+
RDF schema as arguments.
|
7
|
+
|
8
|
+
The generator creates a schema class in lib/rdf.
|
9
|
+
|
10
|
+
For an RDF Schema to be properly parsed, it needs to have labels
|
11
|
+
for each class and property and it needs to use the XML-ABBREV
|
12
|
+
syntax. Most RDFS documents will work given these constraints.
|
13
|
+
|
14
|
+
Example:
|
15
|
+
./script/generate rdf_schema RDF http://www.w3.org/1999/02/22-rdf-syntax-ns
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
class RdfSchemaGenerator < Rails::Generator::NamedBase
|
5
|
+
attr_reader :url, :properties, :classes
|
6
|
+
|
7
|
+
def initialize(runtime_args, options)
|
8
|
+
@url = runtime_args[1]
|
9
|
+
@classes = {}
|
10
|
+
@properties = {}
|
11
|
+
|
12
|
+
super
|
13
|
+
setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
content = Net::HTTP.get URI.parse(@url)
|
18
|
+
document = REXML::Document.new(content)
|
19
|
+
|
20
|
+
document.root.each_element('rdfs:Class') do |clazz|
|
21
|
+
get_entry_for(clazz, @classes)
|
22
|
+
end
|
23
|
+
|
24
|
+
document.root.each_element('rdf:Property') do |prop|
|
25
|
+
get_entry_for(prop, @properties)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_entry_for(e, hash)
|
30
|
+
if label = e.elements['rdfs:label'].text
|
31
|
+
if id = e.attributes['rdf:about'] or e.attributes['rdf:ID']
|
32
|
+
hash[id] = label
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def manifest
|
38
|
+
record do |m|
|
39
|
+
# Check for class naming collisions.
|
40
|
+
m.class_collisions class_path, "#{class_name}"
|
41
|
+
|
42
|
+
# Controller, helper, views, and test directories.
|
43
|
+
m.directory File.join('lib/rdf', class_path)
|
44
|
+
|
45
|
+
# Controller class, functional test, and helper class.
|
46
|
+
m.template 'schema.rb',
|
47
|
+
File.join('lib/rdf',
|
48
|
+
class_path,
|
49
|
+
"#{file_name}.rb")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/templates/schema.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
Namespace = '<%= url %>'.freeze unless const_defined? :Namespace
|
3
|
+
|
4
|
+
# Classes
|
5
|
+
<%for id, label in classes%>
|
6
|
+
<%=label.capitalize%> = '<%=id%>'.freeze unless const_defined? :<%=label.capitalize%>
|
7
|
+
<%end%>
|
8
|
+
|
9
|
+
# Properties
|
10
|
+
<%for id, label in properties%>
|
11
|
+
<%=label.capitalize%> = '<%=id%>'.freeze unless const_defined? :<%=label.capitalize%>
|
12
|
+
<%end%>
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: rdf_schema_generator
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2006-02-12
|
8
|
+
summary: "[Rails] RDF Schema generator."
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: seangeo@gmail.com
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description: RDF Schema Generator for Rails
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
authors:
|
28
|
+
- Sean Geoghegan
|
29
|
+
files:
|
30
|
+
- USAGE
|
31
|
+
- rdf_schema_generator.rb
|
32
|
+
- templates/schema.rb
|
33
|
+
test_files: []
|
34
|
+
rdoc_options: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
requirements: []
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rails
|
42
|
+
version_requirement:
|
43
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
44
|
+
requirements:
|
45
|
+
-
|
46
|
+
- ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.10.0
|
49
|
+
version:
|