Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented escaping of dbpedia URIs.

  • Loading branch information...
commit d466b76bc57dc6f9a172c926e468000e2045ba3b 1 parent 13159b1
@njh authored
View
12 lib/base_model.rb
@@ -51,17 +51,15 @@ def doc_path(format=nil)
"/#{self.class.identifier_path}/#{pageid}#{format ? '.' + format.to_s : ''}"
end
- def escaped_title
+ def wikipedia_uri
unless title.nil?
- WikipediaApi.escape_title(title)
+ @wikipedia_uri ||= RDF::URI.parse("http://en.wikipedia.org/wiki/#{WikipediaApi.escape_title(title)}")
end
end
- def wikipedia_uri
- @wikipedia_uri ||= RDF::URI.parse("http://en.wikipedia.org/wiki/#{escaped_title}")
- end
-
def dbpedia_uri
- @dbpedia_uri ||= RDF::URI.parse("http://dbpedia.org/resource/#{escaped_title}")
+ unless title.nil?
+ @dbpedia_uri ||= RDF::URI.parse("http://dbpedia.org/resource/#{WikipediaApi.title_to_dbpedia_key(title)}")
+ end
end
end
View
2  lib/wikipedia_api.rb
@@ -33,7 +33,7 @@ def self.escape_query(str)
end
def self.escape_title(title)
- URI::escape(title.gsub(' ','_'), ' ?#%"+=()')
+ URI::escape(title.gsub(' ','_'), ' ?#%"+=')
end
def self.title_to_dbpedia_key(title)
View
26 spec/base_model_spec.rb
@@ -47,10 +47,6 @@
@obj.title.should == 'Ceres, Fife'
end
- it "should escape characters in the title" do
- @obj.escaped_title.should == 'Ceres,_Fife'
- end
-
it "should respond to 'wikipedia_uri' with the Wikipedia URI" do
@obj.wikipedia_uri.should == RDF::URI('http://en.wikipedia.org/wiki/Ceres,_Fife')
end
@@ -60,6 +56,28 @@
end
end
+ context "creating an object with brackets in the title" do
+ before :each do
+ @obj = BaseModel.new(:pageid => '192584', :ns => 0, :title => 'Keith Allen (actor)')
+ end
+
+ it "should respond to 'pageid' with its pageid" do
+ @obj.pageid.should == '192584'
+ end
+
+ it "should respond to 'title' with its title" do
+ @obj.title.should == 'Keith Allen (actor)'
+ end
+
+ it "should respond to 'wikipedia_uri' with the Wikipedia URI" do
+ @obj.wikipedia_uri.should == RDF::URI('http://en.wikipedia.org/wiki/Keith_Allen_(actor)')
+ end
+
+ it "should respond to 'dbpedia_uri' with the dbpedia URI" do
+ @obj.dbpedia_uri.should == RDF::URI('http://dbpedia.org/resource/Keith_Allen_%28actor%29')
+ end
+ end
+
context "updating an object with a hash" do
before :each do
@obj = BaseModel.new(934787)
View
4 spec/wikipedia_thing_spec.rb
@@ -137,10 +137,6 @@
@thing.longitude.should == -2.970134
end
- it "should escape titles correctly" do
- @thing.escaped_title.should == 'Ceres,_Fife'
- end
-
it "should encode the Wikipedia page URL correctly" do
@thing.wikipedia_uri.should == RDF::URI('http://en.wikipedia.org/wiki/Ceres,_Fife')
end
Please sign in to comment.
Something went wrong with that request. Please try again.