Last active
August 29, 2015 14:01
-
-
Save veer66/e86cc7fc7a8707820c2f to your computer and use it in GitHub Desktop.
reading expanded (Apertium) dix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LDIX | |
class Parser | |
def initialize | |
end | |
def parse_tag(raw) | |
if raw.nil? | |
[] | |
else | |
raw.map{|t| t[1..-2]} | |
.select{|t| not t.nil?} | |
end | |
end | |
def parse_col(col) | |
if col.empty? | |
nil | |
else | |
toks = col.split(/(<\w+>)/) | |
{headword: toks[0], | |
tags: parse_tag(toks[1..-1])} | |
end | |
end | |
def parse_line(line) | |
line | |
.chomp | |
.split(/:[<>]:|:/) | |
.map{|col| parse_col(col)} | |
end | |
end | |
end |
/:|:[<>]:/ didn't work
/:[<>]:|:/ do
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use /:|:[<>]:/ to split left and right as Unhammer recommended