csv_to_rdf 0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/csv_to_rdf.rb +45 -0
  3. metadata +72 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58c947332d7c9e5cd502eca82b890b41deae5496
4
+ data.tar.gz: d34b8c52221f91c04cc2aaa7f49a473742532a68
5
+ SHA512:
6
+ metadata.gz: a20c590192fa30937d3965e92374230e10ff49c8f0571bf234757f1f61c532901db7aad1700af2fae164e3f8596238761ae6827d0fa916849f76484361dda150
7
+ data.tar.gz: 2f9e522a668b4c8850666f664246dceea443f2b1631d8915680883296387b9a797cb410b9c291f49869cc93b9e7fe7172032f885911c5bef927f8326c5f04648
@@ -0,0 +1,45 @@
1
+ require 'csv'
2
+ # Require 'linkeddata' gem
3
+ require 'linkeddata'
4
+
5
+
6
+ class CsvToRdf
7
+
8
+ ##
9
+ # Build graph object from csv file
10
+ # @param [String] csv
11
+ # @param [Hash{Symbol => Object}] csv_options - default = { :col_sep => ';', :headers => true}
12
+ # @option csv_options [String] :col_sep - default = ';'
13
+ # @option csv_options [Boolean] :headers - default = true
14
+ # @return [RDF::Graph] - RDF graph contain information from csv file
15
+ #
16
+
17
+ def csv_to_rdf(csv, csv_options = nil)
18
+ #{ :col_sep => ';', :headers => true}
19
+ csv_options ||= { :col_sep => ';', :headers => true}
20
+ graph = RDF::Graph.new
21
+ wd = RDF::Vocabulary.new("http://vieslav.pl/csv/0.1/")
22
+ table = RDF::Node.new
23
+ graph << [table, RDF.type, wd['table']]
24
+ /.+\/(.+\.csv)$/.match(csv)
25
+ #puts $1, "xxx"
26
+ graph << [table, RDF::RDFS.label, $1]
27
+ CSV.foreach(csv, csv_options ) do |row|
28
+ puts row.inspect
29
+
30
+ bnode = RDF::Node.new
31
+ graph << [table, RDF::RDFS.member, bnode]
32
+ # graph << [bnode, RDF::RDFS.label, row['header1']]
33
+ graph << [bnode, RDF.type, wd.row]
34
+
35
+ row.each() do |header, value|
36
+
37
+ if value != nil then
38
+ graph << [bnode, wd[header.strip], value]
39
+ end
40
+ end
41
+ end
42
+ graph
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv_to_rdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - WiDu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: linkeddata
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sparql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Converts CSV data to RDF graph
42
+ email: wdulek@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/csv_to_rdf.rb
48
+ homepage: https://github.com/widu/csv_to_rdf
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.6.7
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Converts CSV data to RDF graph
72
+ test_files: []