Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greek seg #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/llt/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'llt/tokenizer/api'
require 'sinatra/base'
require 'sinatra/respond_with'
require 'cgi'

class Api < Sinatra::Base
helpers LLT::Core::Api::Helpers
Expand Down Expand Up @@ -36,7 +37,13 @@ def parse_request
# Have to go back in history to see when the error exactly occurs (sadly,
# Travis wasn't running in this repository...) and maybe use an older
# version of the causing gem.
sentences = seg.segment(text)

# Unescaping HTML chars: During work on greek segmenter it turned out that
# the parsed Herodotus xml file returned HTML characters instead of UTF-8,
# which caused problems in segmenting.
# CGI.unescapeHTML converts those into UTF-8.
unescaped_text = CGI.unescapeHTML(text)
sentences = seg.segment(unescaped_text)
sentences.each do |sentence|
tok.tokenize(sentence.to_s, add_to: sentence)
end
Expand Down
17 changes: 13 additions & 4 deletions spec/lib/llt/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def app
end

let(:text) {{text: "homo mittit. Marcus est."}}
let(:html_text) {{text: "&#954;&#945;&#953;."}}

context "with text as input" do
context "with accept header json" do
Expand All @@ -32,14 +33,22 @@ def app

context "with accept header xml" do
it "segtoks the given text" do
pending
get '/segtok', text,
{"HTTP_ACCEPT" => "application/xml"}
last_response.should be_ok
body = last_response.body
body.should =~ /<w>homo<\/w>/
body.should =~ /<w>mittit<\/w>/
body.should =~ /<pc>\.<\/pc>/
body.should =~ /<w n="1">homo<\/w>/
body.should =~ /<w n="2">mittit<\/w>/
body.should =~ /<pc n="3">\.<\/pc>/
end

it "segtoks the given greek texts with unescaping html entities" do
get '/segtok', html_text,
{"HTTP_ACCEPT" => "application/xml"}
last_response.should be_ok
body = last_response.body
body.should =~ /<w n="1">και<\/w>/
body.should =~ /<pc n="2">\.<\/pc>/
end

it "receives params for tokenization and markup" do
Expand Down