summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2015-11-27 18:46:15 +0100
committerAlex Legler <alex@a3li.li>2015-11-27 18:46:15 +0100
commit8114c3fabf3bd4ddf6af09182befd4fe4da9df94 (patch)
treec2e72556a69adb1bde1b6973c9a0dc8c67554221
downloadsemantic-data-toolkit-8114c3fabf3bd4ddf6af09182befd4fe4da9df94.tar.gz
semantic-data-toolkit-8114c3fabf3bd4ddf6af09182befd4fe4da9df94.tar.bz2
semantic-data-toolkit-8114c3fabf3bd4ddf6af09182befd4fe4da9df94.zip
First set of utilities for exporting project data
-rw-r--r--.rubocop.yml2
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock31
-rw-r--r--lib/vocabulary.rb28
-rwxr-xr-xprojects.rb85
5 files changed, 148 insertions, 0 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..59b273c
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,2 @@
+Metrics/LineLength:
+ Max: 120
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..f22074b
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,2 @@
+gem 'rdf'
+gem 'rdf-rdfxml'
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..4312380
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,31 @@
+GEM
+ specs:
+ haml (4.0.7)
+ tilt
+ htmlentities (4.3.4)
+ link_header (0.0.8)
+ rdf (1.1.14)
+ link_header (~> 0.0, >= 0.0.8)
+ rdf-aggregate-repo (1.1.0)
+ rdf (>= 1.1)
+ rdf-rdfa (1.1.6)
+ haml (~> 4.0)
+ htmlentities (~> 4.3)
+ rdf (~> 1.1, >= 1.1.6)
+ rdf-aggregate-repo (~> 1.1)
+ rdf-xsd (~> 1.1)
+ rdf-rdfxml (1.1.4)
+ htmlentities (~> 4.3)
+ rdf (~> 1.1, >= 1.1.6)
+ rdf-rdfa (~> 1.1, >= 1.1.4.1)
+ rdf-xsd (~> 1.1)
+ rdf-xsd (1.1.4)
+ rdf (~> 1.1, >= 1.1.9)
+ tilt (1.4.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rdf
+ rdf-rdfxml
diff --git a/lib/vocabulary.rb b/lib/vocabulary.rb
new file mode 100644
index 0000000..b0e623c
--- /dev/null
+++ b/lib/vocabulary.rb
@@ -0,0 +1,28 @@
+require 'rdf'
+
+# Common vocabulary for Gentoo Wiki properties
+module GentooWiki
+ NS_WIKI = 'http://wiki.gentoo.org/id/'
+ NS_PROP = 'http://wiki.gentoo.org/id/Property-3A'
+ NS_SWIVT = 'http://semantic-mediawiki.org/swivt/1.0#'
+
+ SUBOBJECT = RDF::URI.new(NS_PROP + 'Has_subobject')
+
+ PROJ = RDF::URI.new(NS_WIKI + 'Category-3AGentoo_Projects')
+
+ PROP_NAME = RDF::URI.new(NS_PROP + 'Has_Name')
+ PROP_CONTACT = RDF::URI.new(NS_PROP + 'Has_Contact')
+ PROP_DESC = RDF::URI.new(NS_PROP + 'Has_Description')
+ PROP_IRC = RDF::URI.new(NS_PROP + 'Has_IRC_channel')
+ PROP_PARENT_PROJECT = RDF::URI.new(NS_PROP + 'Has_Parent_Project')
+ PROP_PROPAGATES_MEMBERS = RDF::URI.new(NS_PROP + 'Propagates_Members')
+
+ PROP_DEV = RDF::URI.new(NS_PROP + 'Has_Developer')
+ PROP_ROLE = RDF::URI.new(NS_PROP + 'Has_Role')
+ PROP_LEAD = RDF::URI.new(NS_PROP + 'Is_Project_Lead')
+
+ PROP_NICK = RDF::URI.new(NS_PROP + 'Has_Nickname')
+
+ # SWIVT properties
+ PROP_PAGE = RDF::URI.new(NS_SWIVT + 'page')
+end
diff --git a/projects.rb b/projects.rb
new file mode 100755
index 0000000..0668e07
--- /dev/null
+++ b/projects.rb
@@ -0,0 +1,85 @@
+#!/usr/bin/env ruby
+# Gathers project information from the RDF graph into a JSON file.
+# Alex Legler <a3li@gentoo.org>
+
+require_relative 'lib/vocabulary'
+require 'json'
+require 'rdf/rdfxml'
+include RDF
+
+abort "Usage: #{$PROGRAM_NAME} <RDF graph file or URL>" unless ARGV.first
+
+graph = RDF::Graph.load(ARGV.first)
+
+projects_q = Query.new do
+ # Base information about the project
+ pattern [:proj_uri, RDF.type, GentooWiki::PROJ]
+ pattern [:proj_uri, GentooWiki::PROP_NAME, :proj_name]
+ pattern [:proj_uri, GentooWiki::PROP_CONTACT, :proj_email]
+ pattern [:proj_uri, GentooWiki::PROP_DESC, :proj_desc]
+ pattern [:proj_uri, RDFS.label, :proj_title]
+ pattern [:proj_uri, GentooWiki::PROP_PAGE, :proj_href]
+
+ # Find parents
+ pattern [:proj_uri, GentooWiki::PROP_PARENT_PROJECT, :parent_uri]
+ pattern [:parent_uri, RDFS.label, :parent_title]
+
+ pattern [:proj_uri, GentooWiki::PROP_PROPAGATES_MEMBERS, :propagates_members], optional: true
+ pattern [:proj_uri, GentooWiki::PROP_IRC, :proj_irc], optional: true
+end
+
+def query_members(project_uri)
+ Query.new do
+ pattern [RDF::URI.new(project_uri), GentooWiki::SUBOBJECT, :member_subobj_uri]
+ pattern [:member_subobj_uri, GentooWiki::PROP_DEV, :member_uri]
+ pattern [:member_subobj_uri, GentooWiki::PROP_ROLE, :member_roles]
+ pattern [:member_subobj_uri, GentooWiki::PROP_LEAD, :member_is_lead]
+ pattern [:member_uri, GentooWiki::PROP_NICK, :member_nick]
+ pattern [:member_uri, GentooWiki::PROP_NAME, :member_name]
+ pattern [:member_uri, GentooWiki::PROP_CONTACT, :member_email]
+ end
+end
+
+def label_to_id(label)
+ label.to_s.gsub(/^Project:/, '')
+end
+
+def https(url)
+ url.gsub(%r{^//}, 'https://')
+end
+
+def email(uri)
+ uri.gsub(/^mailto:/, '')
+end
+
+projects = {}
+
+projects_q.execute(graph) do |result|
+ project_id = label_to_id result[:proj_title]
+
+ project = {}
+ project['name'] = result[:proj_name].to_s
+ project['email'] = email result[:proj_email].to_s
+ project['description'] = result[:proj_desc].to_s
+ project['irc'] = result[:proj_irc].to_s
+ project['href'] = https result[:proj_href].to_s
+ project['propagates_members'] = result[:propagates_members].to_s == 'true'
+
+ parent_id = label_to_id result[:parent_title].to_s
+ project['parent'] = parent_id unless parent_id == 'Gentoo'
+
+ project['members'] = []
+ query_members(result[:proj_uri]).execute(graph) do |member_result|
+ project['members'] << {
+ 'nickname' => member_result[:member_nick].to_s,
+ 'role' => member_result[:member_roles].to_s,
+ 'is_lead' => member_result[:member_is_lead].to_s == 'true',
+ 'email' => email(member_result[:member_email].to_s),
+ 'name' => member_result[:member_name].to_s
+ }
+ end
+
+ projects[project_id] = project
+end
+
+puts projects.sort.to_h.to_json