diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 189ae550..b5c15635 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -20,6 +20,7 @@ class MapsController < ApplicationController end format.json { render json: @map } format.csv { redirect_to action: :export, format: :csv } + format.rdf { redirect_to action: :export, format: :rdf } end end @@ -94,6 +95,7 @@ class MapsController < ApplicationController respond_to do |format| format.json { render json: exporter.json } format.csv { send_data exporter.csv } + format.ttl { render text: exporter.rdf } end end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index be57dde1..68041e1e 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -51,6 +51,17 @@ class Synapse < ApplicationRecord super(methods: [:user_name, :user_image, :collaborator_ids]) 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 attrs = ['desc', 'category', 'permission', 'defer_to_map_id'] if attrs.any? {|k| changed_attributes.key?(k)} diff --git a/app/models/topic.rb b/app/models/topic.rb index 90443862..274256c3 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -82,6 +82,17 @@ class Topic < ApplicationRecord map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user])) 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 if defer_to_map defer_to_map.editors.select { |mapper| mapper != user }.map(&:id) diff --git a/app/models/user.rb b/app/models/user.rb index f6fcb60e..7ec2a032 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,6 +67,16 @@ class User < ApplicationRecord json 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 maps + shared_maps end diff --git a/app/services/map_export_service.rb b/app/services/map_export_service.rb index 3b76cea8..3b532ad5 100644 --- a/app/services/map_export_service.rb +++ b/app/services/map_export_service.rb @@ -22,6 +22,15 @@ class MapExportService end end + def rdf + output = '' + output += rdf_header + output += rdf_mappers + output += rdf_topics + output += rdf_synapses + output + end + private def topic_headings @@ -87,4 +96,38 @@ class MapExportService spreadsheet end + + def rdf_header + output = '' + output += "PREFIX d: \n" + output += "PREFIX gr: \n" + output += "PREFIX rdfs: \n" + output += "PREFIX foaf: \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 diff --git a/public/owl/map.owl.ttl b/public/owl/map.owl.ttl new file mode 100644 index 00000000..44391d54 --- /dev/null +++ b/public/owl/map.owl.ttl @@ -0,0 +1,34 @@ +@prefix owl: . +@prefix xsd: . +@prefix rdfs: . +@prefix foaf: . + +@prefix : . +@prefix mm: . + +: 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 .