Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hiiwave/Tos-Translater
Browse files Browse the repository at this point in the history
  • Loading branch information
hiiwave committed Mar 21, 2018
2 parents 14b7b99 + 0d97d2a commit d7ae7c0
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ Theoretically, it's possible to support more languages without difficulty, inclu
Since I don't know if there is such demand, and I'm not familiar with those languages, the development of these language support is not done yet. Let me know if you're interested and want to contribute.


## Known Issues
* Market search function would lose effect while using a non-native language.
So switch to native language whenever you're going to do market search.


## Credits
This tool is open-sourced by player 波光粼粼 at guild [夏祭](https://forum.gamer.com.tw/C.php?bsn=19840&snA=29788) in tw-tos.

Expand Down
7 changes: 5 additions & 2 deletions mymain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@


matcher = Matcher(lang_en_path, lang_tw_path)
# matcher.export('tw', 'full', output_path / 'twtos-full')
matcher.export('tw', 'map', output_path / 'langmap')

# matcher.export('en', 'tw', output_path / 'itos-tw')
# matcher.export('tw', 'en-opt', output_path / 'twtos-en')
matcher.export('tw', 'en-opt', Path(r'C:\TreeOfSaviorTW\release\languageData\twtos-en'))
# matcher.export('tw', 'en-opt', Path(r'C:\TreeOfSaviorTW\release\languageData\twtos-en'))
# matcher.export('tw', 'dual1', output_path / 'twtos-dual1')
# matcher.export('tw', 'dual2', output_path / 'twtos-dual2')
matcher.export('tw', 'dual1', Path(r'C:\TreeOfSaviorTW\release\languageData\twtos-dual1'))
matcher.export('tw', 'dual2', Path(r'C:\TreeOfSaviorTW\release\languageData\twtos-dual2'))
matcher.export('tw', 'dual2', Path(r'C:\TreeOfSaviorTW\release\languageData\twtos-dual2'))
5 changes: 2 additions & 3 deletions tos_languagematcher/exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pandas as pd
import numpy as np
from abc import ABC, abstractmethod
import functools
from tos_languagematcher import TSVS


Expand Down Expand Up @@ -59,15 +58,15 @@ def _make_df_result(self, df, tsv):
class ExporterEnTw(Exporter):
def _get_df1(self, tsv):
return self.df_ens[tsv]

def _make_df_result(self, df, tsv):
return np.where(~df['tw'].isna(), df['tw'], df['en'])


class ExporterTwEn(Exporter):
def _get_df1(self, tsv):
return self.df_tws[tsv]

def _make_df_result(self, df, tsv):
return np.where(~df['en'].isna(), df['en'], df['tw'])

Expand Down
8 changes: 6 additions & 2 deletions tos_languagematcher/exporter/exporter_dual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .exporter import *
from .exporter import Exporter
import functools
from abc import abstractmethod
import pandas as pd
import numpy as np


class ExporterTwDualBase(Exporter):
Expand Down Expand Up @@ -57,4 +61,4 @@ def _make_df_initial(self, df):

def _make_df_dual(self, df):
res = pd.Series(np.where(~df['tw'].isna(), df.en + ' (' + df.tw + ')', df['en']))
return res
return res
9 changes: 7 additions & 2 deletions tos_languagematcher/exporter/exporter_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .exporter import *
from .exporter_dual import *
from .exporter import ExporterEnTw, ExporterTwEn, ExporterTwEnopt
from .exporter_dual import ExporterTwDual1, ExporterTwDual2
from .exporter_full import ExporterTwFull, ExporterLanguageMap


def ExporterFactory(langfrom, langto, output_path):
Expand All @@ -13,5 +14,9 @@ def ExporterFactory(langfrom, langto, output_path):
return ExporterTwDual1(output_path)
elif (langfrom, langto) == ('tw', 'dual2'):
return ExporterTwDual2(output_path)
elif (langfrom, langto) == ('tw', 'full'):
return ExporterTwFull(output_path)
elif (langfrom, langto) == ('tw', 'map'):
return ExporterLanguageMap(output_path)
else:
raise TypeError("Language Not support")
45 changes: 45 additions & 0 deletions tos_languagematcher/exporter/exporter_full.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from .exporter import Exporter
import functools
import numpy as np
import pandas as pd


class ExporterTwFull(Exporter):
''' Similar to ExporterTwEn but remaining zh-tw and korean
'''
def _get_df1(self, tsv):
return self.df_tws[tsv]

def _make_df_result(self, df, tsv):
return np.where(~df['en'].isna(), df['en'], df['tw'])

# Overwrite
def _prepare_df_tsv(self, tsv):
''' Prepare the dataframe of tsv
'''
df1 = self._get_df1(tsv)
dfm = self.tables[tsv]
df = pd.merge(df1, dfm, on='korean', how='left')
df['result'] = self._make_df_result(df, tsv)
self._custom_modify_result(df)
df = df[['no', 'tw', 'en', 'korean']]
return df


class ExporterLanguageMap(ExporterTwFull):
''' Export language mapping tables
'''
def _prepare_df_tsv(self, tsv):
df = super()._prepare_df_tsv(tsv)
cond = self._get_nospecialchars_condition(df)
df = df[cond]
df = df[['tw', 'en', 'korean']]
return df

def _get_nospecialchars_condition(self, df):
cond_short = df.tw.str.len() < 15
cond_short &= df.en.str.len() < 35
special_chars = [',', '.', '!', ':', '%', '{', '}']
cond_nospecialchars = functools.reduce(
lambda x, y: x & y, [df.en.str.find(c) == -1 for c in special_chars])
return cond_nospecialchars

0 comments on commit d7ae7c0

Please sign in to comment.