forked from kristjan/cjvt-srl-tagging
Parser() class
This commit is contained in:
@@ -3,7 +3,7 @@ import pandas
|
||||
import sys
|
||||
|
||||
# msd mappings from slo to ang
|
||||
class Msdmap():
|
||||
class Msdmap:
|
||||
def __init__(self):
|
||||
# http://nl.ijs.si/ME/V4/msd/html/msd.categories-sl.html
|
||||
self.pos_slo_ang = [
|
||||
@@ -22,15 +22,20 @@ class Msdmap():
|
||||
]
|
||||
|
||||
table_name = "msd-human-sl.tbl"
|
||||
table_path = pkg_resources.resource_filename(__name__, "msd/" + table_name)
|
||||
self.msd_table = pandas.read_csv(
|
||||
table_name,
|
||||
"\t",
|
||||
names=["id", "eng_msd", "eng_long", "slo_msd", "slo_long", "slo_very_long"]
|
||||
)
|
||||
table_path = pkg_resources.resource_filename(__name__, table_name)
|
||||
with open(table_path, "rb") as fp:
|
||||
# TODO: pandas is awfully slow --- might need optimization
|
||||
self.msd_table = pandas.read_csv(
|
||||
fp,
|
||||
"\t",
|
||||
names=["id", "eng_msd", "eng_long", "slo_msd", "slo_long", "slo_very_long"]
|
||||
)
|
||||
self.msd_table.set_index('slo_msd')
|
||||
|
||||
def slo_msd_to_eng_long(self, slo_msd):
|
||||
return (self.msd_table[self.msd_table["slo_msd"] == slo_msd]["eng_long"]).values[0]
|
||||
# old, slow
|
||||
# return (self.msd_table[self.msd_table["slo_msd"] == slo_msd]["eng_long"]).values[0]
|
||||
return self.msd_table.query("slo_msd == '{}'".format(slo_msd))["eng_long"].values[0]
|
||||
|
||||
def slo_msd_to_eng_pos(self, slo_msd):
|
||||
# first letter in slo_msd == slo_pos
|
||||
|
||||
Reference in New Issue
Block a user