lightrdf 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/lightrdf/parser.rb +12 -7
- data/lib/lightrdf.rb +1 -1
- data/lightrdf.gemspec +1 -1
- metadata +2 -2
data/History.txt
CHANGED
data/lib/lightrdf/parser.rb
CHANGED
@@ -51,13 +51,13 @@ module RDF
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def self.parse format, text
|
54
|
+
def self.parse format, text, uri=nil
|
55
55
|
case format
|
56
56
|
when :ntriples
|
57
57
|
graph = RDF::Graph.new
|
58
58
|
graph.triples = text.split("\n").select{|l| l.strip!=''}.map do |l|
|
59
|
-
s, p, o = l.strip.match(/\A(<\S+>|".*"
|
60
|
-
[parse_chunk_ntriples(s), parse_chunk_ntriples(p), parse_chunk_ntriples(o)]
|
59
|
+
s, lang1, p, lang2, o, lang3 = l.strip.match(/\A(<\S+>|".*"(@\w+)?|_:\w+)\s+(<\S+>|".*"(@\w+)?|_:\w+)\s+(<\S+>|".*"(@\w+)?|_:\w+)\s+\.\Z/).captures
|
60
|
+
[parse_chunk_ntriples(s,uri), parse_chunk_ntriples(p,uri), parse_chunk_ntriples(o,uri)]
|
61
61
|
end
|
62
62
|
graph
|
63
63
|
when :yarf
|
@@ -83,7 +83,7 @@ module RDF
|
|
83
83
|
else
|
84
84
|
tempfile = new_tempfile
|
85
85
|
File.open(tempfile, 'w') { |f| f.write text }
|
86
|
-
parse :ntriples, %x[rapper -q -i #{format} -o ntriples #{tempfile} 2> /dev/null]
|
86
|
+
parse :ntriples, %x[rapper -q -i #{format} -o ntriples #{tempfile} 2> /dev/null], uri
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -215,12 +215,17 @@ module RDF
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
-
def self.parse_chunk_ntriples c
|
218
|
+
def self.parse_chunk_ntriples c, uri=nil
|
219
219
|
case c[0..0]
|
220
|
-
when '<' then
|
220
|
+
when '<' then
|
221
|
+
if uri
|
222
|
+
Node(URI::parse(uri).merge(c[1..-2]).to_s)
|
223
|
+
else
|
224
|
+
Node c[1..-2]
|
225
|
+
end
|
221
226
|
when '_' then Node c
|
222
227
|
when '"' then
|
223
|
-
ActiveSupport::JSON.decode(c)
|
228
|
+
ActiveSupport::JSON.decode(c.match(/\A(\".*\")(@\w+)?\Z/).captures.first)
|
224
229
|
else
|
225
230
|
raise Exception, "Parsing error: #{c}"
|
226
231
|
end
|
data/lib/lightrdf.rb
CHANGED
data/lightrdf.gemspec
CHANGED