顯示具有 chinese 標籤的文章。 顯示所有文章
顯示具有 chinese 標籤的文章。 顯示所有文章

how to install chinese and japanese fonts for matplotlib and seaborn plots

### Jupyter Notebook Python Code for Displaying CJK Unicode
import matplotlib
from matplotlib.font_manager import FontProperties

### 下載日中字型檔
### install japanese font
!apt-get -y install fonts-ipafont-gothic
font_jp = FontProperties(fname=r'/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf',size=20)
print(font_jp.get_family())
print(font_jp.get_name())

### install chinese font
!apt-get -y install fonts-moe-standard-kai 
font_tw = FontProperties(fname=r'/usr/share/fonts/truetype/moe/MoeStandardKai.ttf',size=20)
print(font_tw.get_family())
print(font_tw.get_name())

### install chinese,japanese,korean font
#!apt-get install fonts-noto-cjk  ## .ttc
#font_cjk = FontProperties(fname=r'/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc',size=20)
#print(font_cjk.get_family())
#print(font_cjk.get_name())

!apt-get install ttf-unifont
font_uni = FontProperties(fname=r'/usr/share/fonts/truetype/unifont/unifont.ttf',size=20)
print(font_uni.get_family())
print(font_uni.get_name())

### 設定畫圖啟用 sans-serif 系列字型
!grep font.family /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc
!sed -i "s/#font.family/font.family/" /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc
!grep font.family /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc

### 設定屬於 sans-serif 系列字型包含日中字型
!grep font.sans-serif /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc
!sed -i "s/#font.sans-serif.*DejaVu Sans/font.sans-serif     : IPAPGothic, TW-MOE-Std-Kai, Unifont, DejaVu Sans/" /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc
#!sed -i "s/font.sans-serif.*DejaVu Sans/font.sans-serif     : IPAPGothic, TW-MOE-Std-Kai, Unifont, DejaVu Sans/" /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc
!grep font.sans-serif /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc

### 連結日中字型檔到畫圖字型目錄
!ln -s /usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/
!ln -s /usr/share/fonts/truetype/moe/MoeStandardKai.ttf /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/
#!ln -s /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/
!ln -s /usr/share/fonts/truetype/unifont/unifont.ttf /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/
!ls /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf/[Miu]*

### 重建畫圖字型快取,納入日中字型檔
matplotlib.font_manager._rebuild()
flist = matplotlib.font_manager.get_fontconfig_fonts()
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
print(names)

### 確認sans-serif系列清單有日中字型
print(matplotlib.rcParams['font.sans-serif'])  ## 確認sans-serif系列清單是否有日中字型
if 'IPAPGothic' not in matplotlib.rcParams['font.sans-serif']:
  matplotlib.rcParams['font.sans-serif'] = ['IPAPGothic', 'TW-MOE-Std-Kai', 'Unifont'] + matplotlib.rcParams['font.sans-serif']
print(matplotlib.rcParams['font.sans-serif'])

### 測試畫圖字型顯示
#!!!!! 若X軸標示字型有誤,表示引擎快取仍未更新,請【重新啟動並運行所有單元格】
import matplotlib.pyplot as plt

testString = u"喜欢 海灘 散步 걷기 好き"   ## 簡中,繁中,日文,韓文,日文
plt.title(testString, fontproperties=font_uni)
plt.xlabel(testString)   # 利用sans-serif第一個字型顯示
plt.ylabel(testString, fontproperties=font_tw)
plt.show()
import seaborn as sns
emotion_counter = [('愉快', 200), ('高興', 180), ('開心', 160), ('歡喜', 140), ('生氣', 130), ('憤怒', 120), ('悲傷', 110), ('難過', 100), ('哀愁', 90), ('傷感', 80)]
sns.set_color_codes("pastel")
sns.barplot(x=[k for k, _ in emotion_counter], y=[v for _, v in emotion_counter])
參考: 解決Python 3 Matplotlib與Seaborn視覺化套件中文顯示問題 link

dataparksearch檢索系統安裝摘要


dataparksearch+mysql安裝摘要 2008.11.20.
----------------------------

http://www.dataparksearch.org/#download
http://www.dataparksearch.org/dpsearch-4.50.tar.bz2
http://www.dataparksearch.org/add-on/TraditionalChinese.freq.gz
http://www.appservnetwork.com/
http://prdownloads.sourceforge.net/appserv/appserv-win32-2.6.0.exe?download

1.解壓編譯佈署
# 解開壓縮及包裝
bunzip2 -c dpsearch-4.50.tar.bz2 | tar tvf -

#產生編譯指令檔Makefile
cd dpsearch-4.50/
perl install.pl
...
Enable support for extra charsets? yes
...

./configure
--prefix=/home/me/dataparksearch
--bindir=/usr/local/dpsearch/bin
--sbindir=/usr/local/dpsearch/sbin
--sysconfdir=/usr/local/dpsearch/etc
--localstatedir=/usr/local/dpsearch/var
--libdir=/usr/local/dpsearch/lib
--includedir=/usr/local/dpsearch/include
--mandir=/usr/local/dpsearch/man
--enable-shared
--disable-syslog
--enable-pthreads
--enable-parser
--enable-mp3
--without-aspell
--with-extra-charsets=all
--enable-file
--enable-http
--enable-ftp
--enable-htdb
--enable-news
--with-mysql=/usr/local/mysql/include

#產生執行檔indexer,search.cgi等
dpsearch-4.50/make

#佈署組態檔.conf及執行檔indexer,search.cgi等
dpsearch-4.50/make install

#解壓佈署字典檔
gunzip TraditionalChinese.freq.gz #解開壓縮
cp TraditionalChinese.freq /usr/local/dpsearch/etc/ #安裝中文字典

2.設定索引組態檔
cd /usr/loca/dpsearch/etc/
cp indexer.conf-dist indexer.conf #indexer使用
vi indexer.conf
DBAddr mysql://username:password@localhost/dpsearch/?dbmode=single
LocalCharset BIG5 #資料庫字集
RemoteCharset BIG5 #索引來源網站字集
LoadChineseList BIG5 TraditionalChinese.freq #中文字典位置
#Include langmap.conf #載入太多字集,可能識別錯誤,宜用下行,只載入單一字集
LangMapFile langmap/zh.big5.lm
Server site http://your.server.name/path 索引網站下所有網頁
Server path http://your.server.name/path 索引路徑下所有網頁
Server page http://your.server.name/path 索引單一網頁

#cp langmap.conf-dist langmap.conf
#vi langmap.conf
# LangMapFile langmap/zh.big5.lm

cp search.htm-dist search.htm #search.cgi使用
vi search.htm
DBAddr mysql://user:password@localhost/dpsearch/?dbmode=single
LocalCharset big5 #資料庫字集
BrowserCharset big5 #顯示用字集

cp stopwords.conf-dist stopwords.conf
cp sections.conf-dist sections.conf

3.建立空白索引資料庫
#啟動mysql資料庫服務
service mysql start

#建立dpsearch資料庫
/usr/bin/mysqladmin -u root -p create dpsearch
Enter password:

#設定dpsearch資料庫供用戶user及密碼password使用
/usr/bin/mysql -u root -p dpsearch
Enter password:
mysql> grant all privileges on dpsearch.* to user@localhost identified by 'password';
mysql> flush privileges;
mysql> quit

4.建立索引資料表大綱及內容
/usr/local/dpsearch/sbin/indexer -Edrop #清除舊大綱
/usr/local/dpsearch/sbin/indexer -Ecreate #建立新大綱
/usr/local/dpsearch/sbin/indexer -a #建立索引
/usr/local/dpsearch/sbin/indexer -S #索引狀態

5.耙取網頁建立索引資料庫
/usr/local/dpsearch/sbin/indexer -Edrop #清除舊大綱
/usr/local/dpsearch/sbin/indexer -Ecreate #建立新大綱
#依據index.conf的Server指示起始位置,耗取網頁,建立索引
/usr/local/dpsearch/sbin/indexer -a -v 5 #詳細訊息顯示索引過程

6.利用索引資料庫檢索網頁
#啟動apache網頁伺服器服務
service http start

#建立檢索首頁,假設網頁伺服器首頁cgi路徑為/var/www/cgi-bin/
cp /usr/local/dpsearch/bin/search.cgi /var/www/cgi-bin/

#利用瀏覽器開啟檢索首頁
firefox http://localhost/cgi-bin/search.cgi

7.中文索引問題
a.網頁字集判別錯誤,可依下法知道是否判別錯誤,
/usr/local/dpsearch/sbin/dpguesser [-n maxhits] < web.htm
444h 214m zh Big5
58h 235m zh GB2312
118h 235m es ISO-8859-1
136h 235m ja UTF-8

/usr/local/dpsearch/sbin/indexer -v 5
indexer[16184]: {01} Guesser: Lang: zh, Charset: Big5

解決法為減少自動識別的字集,最好indexer.conf只用一種字集即可,如下,
#Include langmap.conf
LangMapFile langmap/zh.big5.lm

b.參考http://www.dataparksearch.org/dpsearch-international.en.html


註:
1.以上資料部份參考mikanagi-tku-06-search_engines gais and dataparksearch.ppt
2.dataparksearch計畫來自mnogosearch(www.mnogosearch.org)計畫,兩者差異如下,
dataparksearch: gpl, sql/cache, linux
mnogosearch: gpl, sql, windows, shareware

Disable UDP to solve frequent RDP disconnection

解決 RDP 遠端桌面經常斷線問題:「關閉 UDP 傳輸」 在使用 Windows 內建的 遠端桌面(RDP, Remote Desktop Protocol) 連線時,你是否也常遇到連線突然卡死、畫面凍結,或是頻繁跳出「連線已中...

總網頁瀏覽量