simple rdf export of maps
This commit is contained in:
parent
dc8d274487
commit
2fedbc0787
6 changed files with 111 additions and 0 deletions
|
@ -20,6 +20,7 @@ class MapsController < ApplicationController
|
||||||
end
|
end
|
||||||
format.json { render json: @map }
|
format.json { render json: @map }
|
||||||
format.csv { redirect_to action: :export, format: :csv }
|
format.csv { redirect_to action: :export, format: :csv }
|
||||||
|
format.rdf { redirect_to action: :export, format: :rdf }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ class MapsController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { render json: exporter.json }
|
format.json { render json: exporter.json }
|
||||||
format.csv { send_data exporter.csv }
|
format.csv { send_data exporter.csv }
|
||||||
|
format.ttl { render text: exporter.rdf }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,17 @@ class Synapse < ApplicationRecord
|
||||||
super(methods: [:user_name, :user_image, :collaborator_ids])
|
super(methods: [:user_name, :user_image, :collaborator_ids])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_rdf
|
||||||
|
output = ''
|
||||||
|
output += %(d:synapse_#{id} a mm:synapse ;\n)
|
||||||
|
output += %( mm:topic1 d:topic_#{topic1_id} ;\n)
|
||||||
|
output += %( mm:topic2 d:topic_#{topic2_id} ;\n)
|
||||||
|
output += %( mm:direction "#{category}" ;\n)
|
||||||
|
output[-2] = '.'
|
||||||
|
output += %(\n)
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
def after_updated
|
def after_updated
|
||||||
attrs = ['desc', 'category', 'permission', 'defer_to_map_id']
|
attrs = ['desc', 'category', 'permission', 'defer_to_map_id']
|
||||||
if attrs.any? {|k| changed_attributes.key?(k)}
|
if attrs.any? {|k| changed_attributes.key?(k)}
|
||||||
|
|
|
@ -82,6 +82,17 @@ class Topic < ApplicationRecord
|
||||||
map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user]))
|
map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_rdf
|
||||||
|
output = ''
|
||||||
|
output += %(d:topic_#{id} a mm:topic\n)
|
||||||
|
output += %( rdfs:label "#{name}";\n)
|
||||||
|
output += %( rdfs:comment "#{desc}";\n)
|
||||||
|
output += %( foaf:homepage <#{link}>;\n) if link.present?
|
||||||
|
output[-2] = '.' # change last ; to a .
|
||||||
|
output += %(\n)
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
def collaborator_ids
|
def collaborator_ids
|
||||||
if defer_to_map
|
if defer_to_map
|
||||||
defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
|
defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
|
||||||
|
|
|
@ -67,6 +67,16 @@ class User < ApplicationRecord
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_rdf
|
||||||
|
output = ''
|
||||||
|
output += %(d:mapper_#{id} a foaf:OnlineAccount ;\n)
|
||||||
|
output += %( foaf:accountName "#{name}";\n)
|
||||||
|
output += %( foaf:accountServiceHomepage "https://metamaps.cc/mapper/#{id}";\n)
|
||||||
|
output[-2] = '.' # change last ; to a .
|
||||||
|
output += %(\n)
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
def all_accessible_maps
|
def all_accessible_maps
|
||||||
maps + shared_maps
|
maps + shared_maps
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,15 @@ class MapExportService
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rdf
|
||||||
|
output = ''
|
||||||
|
output += rdf_header
|
||||||
|
output += rdf_mappers
|
||||||
|
output += rdf_topics
|
||||||
|
output += rdf_synapses
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def topic_headings
|
def topic_headings
|
||||||
|
@ -87,4 +96,38 @@ class MapExportService
|
||||||
|
|
||||||
spreadsheet
|
spreadsheet
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rdf_header
|
||||||
|
output = ''
|
||||||
|
output += "PREFIX d: <https://metamaps.cc/maps/#{map.id}>\n"
|
||||||
|
output += "PREFIX gr: <https://metamaps.cc/rdf/map.owl.ttl>\n"
|
||||||
|
output += "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
|
||||||
|
output += "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
|
||||||
|
output += "\n"
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def rdf_mappers
|
||||||
|
output = ''
|
||||||
|
map.contributors.each do |mapper|
|
||||||
|
output += mapper.as_rdf
|
||||||
|
end
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def rdf_topics
|
||||||
|
output = ''
|
||||||
|
map.topics.each do |topic|
|
||||||
|
output += topic.as_rdf
|
||||||
|
end
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def rdf_synapses
|
||||||
|
output = ''
|
||||||
|
map.synapses.each do |synapse|
|
||||||
|
output += synapse.as_rdf
|
||||||
|
end
|
||||||
|
output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
34
public/owl/map.owl.ttl
Normal file
34
public/owl/map.owl.ttl
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||||
|
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
||||||
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||||
|
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
||||||
|
|
||||||
|
@prefix : <http://metamaps.cc/owl/map.owl.ttl#> .
|
||||||
|
@prefix mm: <http://metamaps.cc/owl/map.owl.ttl#> .
|
||||||
|
|
||||||
|
: a owl:Ontology ;
|
||||||
|
rdfs:label "Metamaps Map"@en ;
|
||||||
|
|
||||||
|
mm:topic a owl:Class ;
|
||||||
|
rdfs:label "One concept on a metamap"@en .
|
||||||
|
|
||||||
|
mm:synapse a owl:Class ;
|
||||||
|
rdfs:label "Link between two topics on a metamap"@en .
|
||||||
|
|
||||||
|
mm:topic1 a owl:ObjectProperty ;
|
||||||
|
a owl:FunctionalProperty ;
|
||||||
|
rdfs:label "first topic of a synapse"@en ;
|
||||||
|
rdfs:domain mm:topic ;
|
||||||
|
rdfs:range owl:Thing .
|
||||||
|
|
||||||
|
mm:topic2 a owl:ObjectProperty ;
|
||||||
|
a owl:FunctionalProperty ;
|
||||||
|
rdfs:label "second topic of a synapse"@en ;
|
||||||
|
rdfs:domain mm:topic ;
|
||||||
|
rdfs:range owl:Thing .
|
||||||
|
|
||||||
|
mm:direction a owl:objectProprty ;
|
||||||
|
a owl:FunctionalProperty ;
|
||||||
|
rdfs:label "from-to, both, or none"@en ;
|
||||||
|
rdfs:domain mm:synapse ;
|
||||||
|
rdfs:range xsd:string .
|
Loading…
Add table
Reference in a new issue