2015年1月14日 星期三

R tm

when using



library(tm)
library(tm.plugin.mail)

#'corpus' folder in current path, 'SPAM' folder in 'corpus'
cname <- file.path(".", "corpus","SPAM")

# readMail from "tm.plugin.mail" can remove some heads of email
docs <- Corpus(DirSource(cname),readerControl = list(reader = readMail))

#docs <- Corpus(DirSource(cname)) #read mail as text

for (j in seq(docs))
{
    #change encoding from "iso-8859-1" to "UTF-8"
    docs[[j]]<- iconv(docs[[j]],"iso-8859-1","UTF-8")

    # Transforms
    docs[[j]] <- gsub("/", " ", docs[[j]])                      #transform "/" to " "
    docs[[j]] <- gsub("@", " ", docs[[j]])
    docs[[j]] <- gsub("\\|", " ", docs[[j]])
    docs[[j]] <- gsub("specific transform", "ST", docs[[j]])
    docs[[j]] <- gsub("other specific transform", "OST", docs[[j]])
}

docs <- tm_map(docs, tolower, iconv(enc2utf8(docs), sub = "byte"))  #lowercase
docs <- tm_map(docs, removeNumbers)
docs <- tm_map(docs, removePunctuation)
docs <- tm_map(docs, removeWords, stopwords("english"))
docs <- tm_map(docs, removeWords, c("own", "stop", "words", "oil"))
docs <- tm_map(docs, stripWhitespace)
docs <- tm_map(docs, stemDocument) #stemming
# Document term matrix.
dtm <- DocumentTermMatrix(docs) # documents as the rows,  terms as the columns
#dtm <- DocumentTermMatrix(docs, control=list(weighting = weightTfIdf))     # tfidf

opencv anaconda error

when import cv2, there is an error

ImportError: /anaconda/bin/../lib/libm.so.6: version `GLIBC_2.15' not found (required by /usr/lib/x86_64-linux-gnu/libxvidcore.so.4)

just copy libm.so.6 from '/usr/lib/x86_64-linux-gnu' to '/home/username/anaconda/lib/'
then it can work

2015年1月4日 星期日

install error on rnnlib

rnnlib source
http://sourceforge.net/p/rnnl/wiki/Home/

refer to
http://sourceforge.net/p/rnnl/discussion/1183966/thread/84f2025b/#742b/f9c9/c849/5687

error message:
Helpers.hpp:311:41: error: ‘range_min_size’ was not declared in this scope
Container.hpp:157:24: error: ‘resize’ was not declared in this scope

Helpers.hpp:
Moving the 4 templates for range_min_size to the top of the file fixed all the issues.

move line 532 ~ 547 to line 163

 template<class R1, class R2> static size_t range_min_size (const R1& a, const R2& b)
{
    return min(boost::size(a), boost::size(b));
}
template<class R1, class R2, class R3> static size_t range_min_size (const R1& a, const R2& b, const R3& c)
{
    return min(min(boost::size(a), boost::size(b)), boost::size(c));
}
template<class R1, class R2, class R3, class R4> static size_t range_min_size (const R1& a, const R2& b, const R3& c, const R4& d)
{
    return min(min(min(boost::size(a), boost::size(b)), boost::size(c)), boost::size(d));
}
template<class R1, class R2, class R3, class R4, class R5> static size_t range_min_size (const R1& a, const R2& b, const R3& c, const R4& d, const R5& e)
{
    return min(min(min(min(boost::size(a), boost::size(b)), boost::size(c)), boost::size(d)), boost::size(e));
}

Container.hpp:
On line 157, revise "resize" instead of "this->resize."


2014年12月7日 星期日

Installing UBUNTU without finding SATA HD

Installing UBUNTU without finding SATA HD
Reference from
http://www.pendrivelinux.com/ubuntu-installer-cant-find-my-sata-drive/

How I made Ubuntu Installer detect my SATA drive

Boot Ubuntu from a Live CD or Live USB
Open a Terminal (Applications > Accessories > Terminal) and type sudo su
Type fdisk -l (note which device is your SATA drive)
Type dmraid -E -r /dev/sdX
(Replacing X with your actual device found in step 3)
Confirm that yes, you wish to remove the dmraid information
Return to the desktop and proceed to run the Ubuntu Installer

2014年11月3日 星期一

install rce in ubuntu14.04+ROS indigo with Anaconda python

~/rce$ sudo ./install.sh
會將rce相關套件裝到 /usr/local/lib/python2.7/dist-packages中
如要使用安裝在~/anaconda中的python會找不到rce相關套件
所以
~/rce$ ./setup/provision all
會import不到RCE套件

因此可以用以下兩種方式(擇一即可):
1. 將/usr/local/lib/python2.7/dist-packages中的相關套件與.pth檔複製到
    ~/anaconda/lib/python2.7/site-packages中
2.修改或新增.pth檔到~/anaconda/lib/python2.7/site-packages將相關的RCE egg指到
/usr/local/lib/python2.7/dist-packages
如:
/usr/local/lib/python2.7/dist-packages/rce_util-0.3-py2.7.egg
/usr/local/lib/python2.7/dist-packages/rce_comm-0.3-py2.7.egg
/usr/local/lib/python2.7/dist-packages/autobahn_rce-0.6.0.5-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/dist-packages/Twisted-14.0.2-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/dist-packages/rce_core-0.3-py2.7.egg
/usr/local/lib/python2.7/dist-packages/python_iptables-0.5.0-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/dist-packages/rce_client-0.3-py2.7.egg
/usr/local/lib/python2.7/dist-packages/rce_console-0.3-py2.7.egg

如有缺少zope.interface套件
可用 pip install zope.interface安裝

而RCE只支援到UBUNTU 13.04 + ROS hydro
如要使用UBUNTU 14.04 + ROS indigo需要修改provision檔
可將版本改掉
in my case: 
using 'tursty' to substitute 'Raring'
using 'indigo' to substitute 'hydro'
remove openvswitch-brcompat in _HOST_PKGS , becouse it cannot find it in ubuntu 14.04 and some one say ubuntu 14.04 for OVS don't need that.

http://openvswitch.org/



2014年10月30日 星期四

VC++ 2012 opencv error "0xc0000005讀取位置0x00000000時發生存取違規"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv/cv.h>

using namespace cv;
using namespace std;

int main( int argc, char** argv ){
    Mat image;
    image = imread("1.jpg");
    namedWindow( "show window", CV_WINDOW_AUTOSIZE );
    imshow( "show window", image );
    waitKey(0);
    return 0;
}

應該是沒找到圖檔
建置VC++空專案時不要為方案建立目錄
將圖檔放在專案資料夾即可找到圖
x64系統
組態管理員->新增x64平台(來源複製Win32,勾選建立新專案平台

2014年10月15日 星期三

replace string in files

if we want to replace some strings in files of a folder, we can use find, xargs and sed.
for example, i want to change string '/opt/anaconda' to 'home/robot2/anaconda in many files of '/home/robot2/anaconda/bin'.
first, go to the folder
$ cd /home/robot2/anaconda/bin
then, find all files to replace the string
$ find * | xargs -i sed -i 's/\/opt\/anaconda/\/home\/robot2\/anaconda/g' {}
where '/' needs '\' to escape