如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2008年4月13日星期日

Add External Library to SunSPOT Host Application

To use External JAR library in Sun SPOT Host Application, you need to do 2 steps.

  1. Add it to Java Source Classpath. Right click the host application which you want to include external JAR in NetBeans. Select Properties at the bottom of popup menu. Select Java Source Classpath and Add JAR/Folder...
  2. Add classpath to build.properties. The build.properties file is located at the root of every Sun SPOT Host Application. Please use normal text editor to open it and add class path of target JAR to user.classpath.

Attention: You should use different seperator! Please use / instead of \.

The modified user.classpath should looks like this one below.

user.classpath=C:\Program Files\NetBeans 6.0.1\platform7\modules\ext\swing-layout-1.0.3.jar:C:\Documents and Settings\Administrator\.netbeans\6.0\modules\ext\AbsoluteLayout.jar:D:/TheJARFileYouWantToAdd.jar

Digest: Starting with Sun SPOT using NetBeans 6.1

Digested from http://weblogs.java.net/blog/brunogh/archive/2008/04/starting_with_s.html from  Bruno Ghisi's Blog.

 

If you do not have a Sun SPOT (Figure 1), do not be bored, you can still have a lot of fun! In this entry, I gonna explain how to start programming the world using NetBeans 6.1!

sun_spot2.jpg
Figure 1: Sun SPOT rulez!!!

Downloading NetBeans IDE 6.1


1. Download NetBeans IDE 6.1 (currently in the RC 1). A lot of new nice features, take a look in the New and Noteworthy and in the release page for a detailed list.

Installing Sun SPOT plugin


2. Install Sun SPOT plugin into NetBeans. Download com-sun-sunspot-updatecenter.nbm. Now, in NetBeans, go to:
2.1 Tools menu -> Plugin.
2.2 Click on Downloaded tab.
2.3 Click on Add Plugins button and select the file. Then, confirm the installation clicking on Install button and accept the license agreement.
2.4 Finally, go to the Available Plugins tab, mark SunSPOTApplicationTemplate, SunSPOTHostApplicationTemplate and Sun SPOT Info, click on Install button and accept the license agreement.
2.5 You can check that everything is installed going to Installed tab (Figure 2).
netbeans_spot1.png
Figure 2: Installed tab.

PS: David Simmons has blogged about these steps before.

Getting Sun SPOT SDK 3.0 Beta


3. Get the Sun SPOT SDK 3.0 Beta emailing David Simmons, more details here. You will receive a link to download SPOTManager tool, that is a jar that installs the SDK and can run the emulator. Be sure you have at least JDK 1.5 and at least Ant 1.6.5 installed and configured in your system.

Creating the Demo Application


4. Let's make the default demo application work. Go to:
4.1 File menu -> New Project
4.2 Select Java category, select Sun SPOT project and then click Next.
4.3 Leave the default project name and package and click Finish.
4.4 Open org.sunspotworld.StartApplication.java. You can see it extends MIDlet and already has some code. If you are familiar with Java ME, you will not have big problems. But, basically, Sun SPOT arquitecture is CLDC (Connected Limited Device Profile) 1.1 and has IMP (Information Module Profile) in the top - which can be defined as a MIDP (Mobile Information Device Profile) without UI stuff. Also, it has some additional libraries and all this runs in a VM called Squawk, that is characterized by being most written in Java. So, StartApplication implements the abstract methods inherited from the MIDlet (startApp,pauseApp that Squawk never calls and destroyApp). It works in a sand box enviromnent.
The startApp code, in List 1, basically gets an object reference to the singleton eDemo Board and then make its LED blink red for a quarter of second each second. As you, can see, the code is pretty high level and easy to understand.

    protected void startApp() throws MIDletStateChangeException {
System.out.println("Hello, world");
new BootloaderListener().start(); // monitor the USB (if connected) and recognize commands from host

long ourAddr = Spot.getInstance().getRadioPolicyManager().getIEEEAddress();
System.out.println("Our radio address = " + IEEEAddress.toDottedHex(ourAddr));

ISwitch sw1 = EDemoBoard.getInstance().getSwitches()[EDemoBoard.SW1];
leds[0].setRGB(100,0,0); // set color to moderate red
while (sw1.isOpen()) { // done when switch is pressed
leds[0].setOn(); // Blink LED
Utils.sleep(250); // wait 1/4 seconds
leds[0].setOff();
Utils.sleep(1000); // wait 1 second
}
notifyDestroyed(); // cause the MIDlet to exit
}
List 1: startApp code.


Running the Demo Application in the emulator




5. Put this application to run in the emulator.


5.1 Right click the project and select Build. It will generate the jar in the /$PROJECT_HOME/suite/. If you have a spot device, you could send it directly by right clicking the project and selecting Build Project + Deploy to Sun SPOT , forgetting the next steps.


5.2 Open the emulator (in the ToolManager, go to Solarium tab and then click in the Solarium button). Then, in the emulator, click on the Emulator menu -> New virtual SPOT, you will notice that a Sun SPOT will appear in the squared right area.


5.3 Right click on the Sun SPOT picture, then click Specify application jar file... and select the application jar in /$PROJECT_HOME/suite/, which is the place that the application was built in step 5.1.


5.4 After that, click again on it, then Run MIDlet and StartApplication. Finally, you will see a red LED blinking!!! Wow!

netbeans_spot2.png



Figure 3: NetBeans 6.1, ToolManager, Emulator and the red LED blinking!



Where I go next?




In NetBeans, check the Sun SPOT Info, that you have installed with the plugin, by clicking in the Window menu.


David Simmons' Blog - http://blogs.sun.com/davidgs


Roger Meike's Blog - http://blogs.sun.com/roger


Sun SPOT Feeds (really nice aggregator with more cool blogs) - http://planets.sun.com/SunSPOT/group/SunSPOT


Project Sun SPOT - https://www.sunspotworld.com


Open source Sun SPOT - https://spots.dev.java.net (take a look in its subprojects as well).


Search for spaughts in youtube.com or subscribe the tag feed directly.


Recently, Aaron Houston has organized a conference call about Sun SPOT with Roger Meike and published the nice links we get during it in an email he sent. The links are available here too. Slides here.

2008年4月11日星期五

平可夫談西藏問題和中國網絡存在的偽造新聞問題

虽然我并不太赞同本文的有些部分,但总体来说,可以看到平可夫正在理性的重新思考自己,重新考虑一些问题。平可夫能够自省,而我们中有些人可以嘛?

本文摘自《汉和》http://www.kanwa.com/mrdt/showpl.php?id=575

 

問:關于偽造漢和新聞出現在中國報紙、網絡的事情能否進一步說明?

平可夫:從2001年開始,我們發現中國的網絡出現偽造漢和新聞、還有偽造其他西方國家媒體的“新聞”問題,2004年以后,情況越來越嚴重。開始我們總是耐心說明,后來實在是沒有辦法,只有采用“一刀切”的辦法,讓讀者小心全部中國網絡、報紙的報道。我們的確無法一條一條地分辨誰是真實的,誰是不真實的。

但是最近中國的媒體人士與我有過溝通,看來我們自己與中方溝通不夠,這是我們的錯誤,來自中國的說法認為,中國現在不是我們想象的那樣封閉。各種報紙競爭激烈,“漢和”的東西極具爭議性、可讀性,中國自己的媒體幾乎不敢涉足,因此別人愛用,批評的人也想看,一邊看、一邊罵。因此說官方媒體,諸如新華社、人民日報下屬的媒體主動偽造漢和新聞不是真實的,他們的記者從什么地方獲得“漢和”假新聞不得而知,自己都可能被騙了。與西方記者所不同的是,與境外媒體直接聯系,似乎不那么容易。尤其是軍事新聞。但是官方報紙幾乎不會主動去偽造漢和新聞。這種情況,不僅出現在偽造《漢和新聞》,其他新聞也同樣被偽造,官方媒體多次批判過這種錯誤行為。多半情況偽造新聞的結果,對中國自己的形象不利。

近來我與西方的軍事觀察家討論這些偽造軍事新聞時候,有意見認為是中國軍隊實施心理戰、宣傳戰的一部分。但是來自中國的意見認為要是這樣,偽造的水平就會高出許多,問題的實質是很多軍事偽造新聞,受損的是中國自己的軍隊形象。軍隊報紙也對此批判過。

我認為通過溝通,中方的意見今后應該考慮。現在有些明白了。

問:為什么中國網絡普通人對你經常進行漫罵攻擊?你如何感受?

平可夫:我先報告一下目前內心世界急需解決的一個信仰問題。我原本相信基督,去年開始進行嚴酷的禪修,每天進行。中國批判達賴喇嘛,正是大師的書讓我僅僅在數個月內內心世界消除了全部憎恨、憤怒、急躁。所有周圍的人,包括我兒子、妻子、友人都說我完全變成了另外的人。禪修過程中,有時是看住我的念頭,所謂佛法中的“注意當下”、有時是止觀達賴喇嘛或者其他宗教人物的像,或者我兒子小時候的樣子,后者主要用于“慈悲對景禪修”。另外才內觀過程中,我發現自己極度傲慢的一面,表面上謙虛、客氣。這可能是問題所在。

我認為正是達賴喇嘛的“利他”、“無常”、“悲心”思想完全可以用來改造中國社會的思想弊端。再加上臺灣的民主制度,和中國人民的勤勞,這就十全十美了。正是達賴喇嘛的書告訴我要關心中國,忘記小時候的苦難、積極看待她的進步一面,所謂的“無常中國”,中國每時每刻都在變化。有利中國(他),就有利于其他任何世界國家,包括加拿大(我)。

我堅決反對抵制奧運,必須把共產主義邪惡思想與普通善良的中國人民區分。根據佛法,人心都是中性的,負面的情緒,諸如憎惡、急躁不是人的本質。就像上海的天空,污染是外來的負面“情緒”,而不是上海天空的本質。它永遠是藍色的。因此,不能孤立中國!要堅決地和平演變。改變一些中國人的負面情緒,而不是他們的本質,人的本質是清澈的。

說到網絡對我的批評,我們必須看到中國網絡的巨大進步一面,比起10年前,網友的水準、鑒別能力越來越高,真正地高興。佛法主張堅忍,有些人的情緒是負面的,這些情緒不應鼓勵,至于一個一個的人,他們有可愛的一面。就是要爭論、批判,這才會進步。我自己對別人關心不夠,這才是問題。注意到沒有?中國的軍網BBS,有人過生日、有人悲傷的時候,一長串的祝賀、安慰致辭,可見他們的本性善良。這就是佛法所說的“大慈大悲”。人只要善良,就可以溝通。我過生日,怎么沒有這么多人祝賀?

曾經作出過測試,我的軍迷把平可夫的文章,刪去名字,粘貼到中國網絡上去,結果一片贊揚聲,后來加上名字,一片漫罵。可見臭名昭著的是“平可夫”的名字,而不是“平可夫的文章”。為什么?我認為是關于國家認同的問題。這一點,不能勉強,各自應該互相尊重。加拿大和中國都是偉大的國家。我反對的是中國政府的“ 負面思想、情緒”而不是普通的人民。

我絕對不恨批評甚至謾罵我的中國網友。希望我們肩并肩地共同進步。在禪修的過程中,我曾經把我兒子3歲時候的臉蛋,換成他們的臉,這樣來進行內觀。當然有時候,看到罵人的文章我也會反感一刻,但是似乎只是非常微妙的毫秒瞬間,比起修行佛法之前,這種反感時間大大縮短,然后即可恢復平靜。

是否可以同時相信基督耶穌和佛陀?

問:中國官方似乎也對你進行批判?

平可夫:以平常心看待,不必再作回應。孫子兵法研討會上有人對我說:我們高度重視你文章,很多平可夫英文文章的翻譯工作要求在很短時間完成。因此有批評是正常的。我過去不高興的是官方批評我的文章動不動把我的眼睛、頭髮顏色、種族問題扯進去。反對的是這種“情緒”,而不是那個人。

說到報道問題,的確環境不同。我再作說明,我們處在高度開放的社會,最終新聞自然是需要尋找熱點,諸如臺海問題,油、先進武器生產的能力等都是必須報道的話題,同樣的弱點也存在在臺灣軍隊中,我同樣進行了分析,為何臺灣軍人不說我制造“臺灣威脅論”?中國的媒體為何不報道我批評臺軍的弱點?不能一來就率先使用已經形成的定義、經驗評價平可夫的報道。這是就的“神經元鏈接”所起到的負面作用。必須修改。

現在必須說明的是,2007年之前,我們漢和的報道兼顧公正、平衡的立場,這是我們從來都必須嚴守的。2007年下半年開始,我們更多地報道出現了傾向性,出現更多批評中國的負面新聞,為什么?這是告訴中國官方的媒體,什么才是他們無端指責的“平可夫制造中國威脅”的狀況。因此請再閱讀一遍“水滸傳”,不要把更多的人推向對立面。現在有了“樣品”,今后請仔細鑒別。

當然這不是我們推行報道的準則,因此2008年4月開始,我們還是回到公正、平衡的報道原則上來。

問:你說到達賴喇嘛的書對你影響巨大,最近西方媒體有關西藏、西藏的事情如何看待?

平可夫:我的看法是中國政府可能錯看了西藏的局勢。我認為達賴的思想是真誠的。要研究佛法,佛教的思想,才能看到西藏的真實。我非常擔心的是:達賴的流亡政府有“巴解組織”化的趨向,達賴的思想、中道路線,可能面臨巨大的挑戰,西藏流亡政府內部正在出現“哈馬滋”勢力。達賴自己的狀況與后期阿拉法特非常相似(阿拉法特化)。當然這種比喻,多少不妥當,因為前期阿拉法特也是暴力派人物,而達賴一直主張和平手段。這一次的流血,恰恰說明達賴的政治影響力正在降低,而不是什么有組織的陰謀。因此需要對話。在達賴再世時候,真誠地對話。當年蔣經國在世時候如果對話,臺海問題比今天容易安定很多。這是“蔣經國教訓”!

說到西藏人,我小時候生活在云南的民族地區,到蹲人(現在的廣通)這個地方坐火車時,看到過許多西藏人,他們總是微笑,毫無理由地微笑,尤其是女孩,非常可愛。我的感觸是兩面的:一方面在通往迪慶的公路上,漢人的大批援藏物資金源源不斷運送進去,當時極端地貧窮,漢人都吃不飽飯!另一方面,部分漢人對少數民族需要表現出更高的尊重。而不是趾高氣揚,這是真實的。70年代中期曾經發生了中國當局鎮壓云南穆斯林村莊事件,在沙店,回人居然被迫要求“學豬叫”!這是歷史事實。絕無夸張。后來動用重炮鎮壓。

說到CNN的報道,我有些失望。美國的精神就是公平、公正,這是我追逐多年的理念。現在看來的確是“雙重標準”,這是有觀眾不服的原因。我現在主要看BBC和Aljazeera。我特別推薦Aljazzeera,相當體現中性原則。

另外,對于中國的經濟成就,這主要歸咎于人民的勤勞,不要把它算到中國政府的功勞上。它充其量只推行了漢代以來溫和王朝政權所崇尚的“讓步政策”,偉大的是人民,而不是政府。人民的血汗,中國政府少貪污、腐敗一些,中國經濟的成就更加顯而易見。英國的學者告訴我:清代的GDP人均已經達到80美元,當時只要遵循自然發展的經濟準則,中國都會高速進步。多數情況下,中國的政治結構阻礙社會發展的力量遠遠大于促進經濟發展的力量。

這個政權丟盡中國人民和亞洲人民的臉面,看看奧運火炬。為什么同樣崛起的印度和中國,世界的看法大相徑庭?為什么所有西方國家、主要的文明社會都如此反感中國政府?進而讓中國人蒙受如此恥辱?“光榮孤立”孤立的確存在于任何一個崛起的國家,為什么日本與印度的崛起要一帆風順許多?

今后,這個政權所作的一切,只要對世界、中國人民有利,哪怕是一件事情,平可夫的文章就堅決支持、贊揚,反之,就絕不妥協地批評,諸如欺負西藏人、欺負小臺灣、推行文化霸權主義,向蘇丹(過去是柬埔寨,都是北京所為,為什么總是...)這樣的邪惡國家出口武器鎮壓人民,唯利是圖,毫無外交原則的古典帝國主義作風等。讀者需要的是一個任何時候都能夠說明真話的平可夫,而不是阿諛奉承、唯利是圖、見風使舵的人,這些古典中華思想、共產主義文化混合的垃圾部分,對平可夫沒有用。加拿大人崇尚的是正義與誠懇。

盡管如此,我們不打算在內心世界憎恨任何人、甚至包括這個邪惡政權,根據佛法,這些憎惡一旦在胸中燃燒,嚴重殺傷的是我們的內臟和情緒、血液將會快速凝固。而對這個政權,則秋毫無損。誘導她進行必要的和平變革,才是唯一的出路。

2008年4月10日星期四

Tutorial: Java Nimbus

Nimbus is the name of a look-and-feel designed by Sun for the Java Desktop System; it's implemented as a GTK theme in the latest Solaris 11 pre-release builds. In 2007, Sun's Swing Team and Ben Galbraith jointly launched an open-source project to implement the Nimbus specifications as a Swing look-and-feel. Jasper Potts, an experienced Swing developer with notable experience created high-quality Swing look-and-feels, was recently hired by Sun and provided the initial code for the project, including a baseline Nimbus Synth implementation of a large number of components.

Currently, the project is using Synth to implement Nimbus. This dovetails nicely with the Swing Team's goal to further refine Synth, but the primary reason for this decision is that using Synth does make many tasks easier. While Java 5 compatibility is a goal, this project will first implement Nimbus on Java 6 and will address Java 5 later, either through a Java 5 update or a stand-alone compatibility library.

There is a webstartable demo of SwingSet running Nimbus on Swing Labs.   Launch

https://nimbus.dev.java.net/

 

STEP 1:

Download Nimbus binary from https://nimbus.dev.java.net/servlets/ProjectDocumentList?folderID=7067&expandFolder=7067&folderID=0. In this tutorial I am using nimbus-2008_02_10.jar.

STEP 2:

Rigt click on your current project which you want to use Nimbus, choose Properties in NetBeans. Select Libraries and add nimbus-2008_02_10.jar to compile and runtime respectively.

STEP 3:

Add code below:

        try {
UIManager.setLookAndFeel("org.jdesktop.swingx.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}


It seems that Nimbus do not support Unicode at this time....


javaNimbus

2008年4月8日星期二

GART HelloWorld

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package garttest;

import edu.gatech.gart.library.Library;
import edu.gatech.gart.library.Sample;
import edu.gatech.gart.library.Tag;
import edu.gatech.gart.library.Vector;
import edu.gatech.gart.ml.htk.HTK;
import edu.gatech.gart.ml.htk.HTKOptions;
import edu.gatech.gart.ml.htk.HTK;
import edu.gatech.gart.sensor.Result;

/**
*
* @author pdeng
*/

public class Main {

public static void main(String[] args) {
new tester();
}
}

class tester {

tester() {
// <editor-fold defaultstate="collapsed" desc="Initial work space">
HTKOptions myOpt = null;
myOpt = new HTKOptions("opt");
myOpt.setPRJ_DIR("c:\\temp");

Library myLib = null;
myLib = new Library("lib");
myLib.setPath("c:\\temp\\" + "lib" + ".xml");

myOpt.setVectorSize(1);
HTK htk = new HTK(myOpt);

Tag t = new Tag("author", "pdeng");
Tag t2 = new Tag("date", "4/5/2008");
myLib.addTag(t);
myLib.addTag(t2);
//</editor-fold>

// <editor-fold defaultstate="collapsed" desc="Initial training data">
Double[] d1 = {1d};
Double[] d2 = {2d};
Double[] d3 = {3d};
Double[] d4 = {4d};
Double[] d5 = {5d};
Double[] d6 = {6d};
Double[] d7 = {7d};
Double[] d8 = {8d};
Double[] d9 = {9d};
Double[] d10 = {10d};
Double[] d11 = {11d};
Double[] d12 = {12d};
Double[] d13 = {13d};
Double[] d14 = {14d};
Double[] d15 = {15d};
Double[] d16 = {16d};
Double[] d17 = {17d};
Double[] d18 = {18d};
Double[] d19 = {19d};
Double[] d20 = {20d};
Vector<Number> v1 = new Vector<Number>(d1);
Vector<Number> v2 = new Vector<Number>(d2);
Vector<Number> v3 = new Vector<Number>(d3);
Vector<Number> v4 = new Vector<Number>(d4);
Vector<Number> v5 = new Vector<Number>(d5);
Vector<Number> v6 = new Vector<Number>(d6);
Vector<Number> v7 = new Vector<Number>(d7);
Vector<Number> v8 = new Vector<Number>(d8);
Vector<Number> v9 = new Vector<Number>(d9);
Vector<Number> v10 = new Vector<Number>(d10);
Vector<Number> v11 = new Vector<Number>(d11);
Vector<Number> v12 = new Vector<Number>(d12);
Vector<Number> v13 = new Vector<Number>(d13);
Vector<Number> v14 = new Vector<Number>(d14);
Vector<Number> v15 = new Vector<Number>(d15);
Vector<Number> v16 = new Vector<Number>(d16);
Vector<Number> v17 = new Vector<Number>(d17);
Vector<Number> v18 = new Vector<Number>(d18);
Vector<Number> v19 = new Vector<Number>(d19);
Vector<Number> v20 = new Vector<Number>(d20);

// <editor-fold defaultstate="collapsed" desc="Traning data set1: ascending ">
Sample sam1 = new Sample();
Tag tt1 = new Tag("label", "Hello", 0, 20);
sam1.addTag(tt1);
sam1.add(v1);
sam1.add(v2);
sam1.add(v3);
sam1.add(v4);
sam1.add(v5);
sam1.add(v6);
sam1.add(v7);
sam1.add(v8);
sam1.add(v9);
sam1.add(v10);
sam1.add(v11);
sam1.add(v12);
sam1.add(v13);
sam1.add(v14);
sam1.add(v15);
sam1.add(v16);
sam1.add(v17);
sam1.add(v18);
sam1.add(v19);
sam1.add(v20);

Sample sam2 = new Sample();
Tag tt2 = new Tag("label", "Hello", 0, 20);
sam2.addTag(tt2);
sam2.add(v1);
sam2.add(v2);
sam2.add(v3);
sam2.add(v4);
sam2.add(v5);
sam2.add(v6);
sam2.add(v7);
sam2.add(v8);
sam2.add(v9);
sam2.add(v10);
sam2.add(v11);
sam2.add(v12);
sam2.add(v13);
sam2.add(v14);
sam2.add(v15);
sam2.add(v16);
sam2.add(v17);
sam2.add(v18);
sam2.add(v19);
sam2.add(v20);

Sample sam3 = new Sample();
Tag tt3 = new Tag("label", "Hello", 0, 20);
sam3.addTag(tt3);
sam3.add(v1);
sam3.add(v2);
sam3.add(v3);
sam3.add(v4);
sam3.add(v5);
sam3.add(v6);
sam3.add(v7);
sam3.add(v8);
sam3.add(v9);
sam3.add(v10);
sam3.add(v11);
sam3.add(v12);
sam3.add(v13);
sam3.add(v14);
sam3.add(v15);
sam3.add(v16);
sam3.add(v17);
sam3.add(v18);
sam3.add(v19);
sam3.add(v20);

Sample sam4 = new Sample();
Tag tt4 = new Tag("label", "Hello", 0, 20);
sam4.addTag(tt4);
sam4.add(v1);
sam4.add(v2);
sam4.add(v3);
sam4.add(v4);
sam4.add(v5);
sam4.add(v6);
sam4.add(v7);
sam4.add(v8);
sam4.add(v9);
sam4.add(v10);
sam4.add(v11);
sam4.add(v12);
sam4.add(v13);
sam4.add(v14);
sam4.add(v15);
sam4.add(v16);
sam4.add(v17);
sam4.add(v18);
sam4.add(v19);
sam4.add(v20);

Sample sam5 = new Sample();
Tag tt5 = new Tag("label", "Hello", 0, 20);
sam5.addTag(tt5);
sam5.add(v1);
sam5.add(v2);
sam5.add(v3);
sam5.add(v4);
sam5.add(v5);
sam5.add(v6);
sam5.add(v7);
sam5.add(v8);
sam5.add(v9);
sam5.add(v10);
sam5.add(v11);
sam5.add(v12);
sam5.add(v13);
sam5.add(v14);
sam5.add(v15);
sam5.add(v16);
sam5.add(v17);
sam5.add(v18);
sam5.add(v19);
sam5.add(v20);
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Traning data set2: descending ">
Sample sam6 = new Sample();
Tag tt6 = new Tag("label", "World", 0, 20);
sam6.addTag(tt6);
sam6.add(v20);
sam6.add(v19);
sam6.add(v18);
sam6.add(v17);
sam6.add(v16);
sam6.add(v15);
sam6.add(v14);
sam6.add(v13);
sam6.add(v12);
sam6.add(v11);
sam6.add(v10);
sam6.add(v9);
sam6.add(v8);
sam6.add(v7);
sam6.add(v6);
sam6.add(v5);
sam6.add(v4);
sam6.add(v3);
sam6.add(v2);
sam6.add(v1);

Sample sam7 = new Sample();
Tag tt7 = new Tag("label", "World", 0, 20);
sam7.addTag(tt7);
sam7.add(v20);
sam7.add(v19);
sam7.add(v18);
sam7.add(v17);
sam7.add(v16);
sam7.add(v15);
sam7.add(v14);
sam7.add(v13);
sam7.add(v12);
sam7.add(v11);
sam7.add(v10);
sam7.add(v9);
sam7.add(v8);
sam7.add(v7);
sam7.add(v6);
sam7.add(v5);
sam7.add(v4);
sam7.add(v3);
sam7.add(v2);
sam7.add(v1);

Sample sam8 = new Sample();
Tag tt8 = new Tag("label", "World", 0, 20);
sam8.addTag(tt8);
sam8.add(v20);
sam8.add(v19);
sam8.add(v18);
sam8.add(v17);
sam8.add(v16);
sam8.add(v15);
sam8.add(v14);
sam8.add(v13);
sam8.add(v12);
sam8.add(v11);
sam8.add(v10);
sam8.add(v9);
sam8.add(v8);
sam8.add(v7);
sam8.add(v6);
sam8.add(v5);
sam8.add(v4);
sam8.add(v3);
sam8.add(v2);
sam8.add(v1);

Sample sam9 = new Sample();
Tag tt9 = new Tag("label", "World", 0, 20);
sam9.addTag(tt9);
sam9.add(v20);
sam9.add(v19);
sam9.add(v18);
sam9.add(v17);
sam9.add(v16);
sam9.add(v15);
sam9.add(v14);
sam9.add(v13);
sam9.add(v12);
sam9.add(v11);
sam9.add(v10);
sam9.add(v9);
sam9.add(v8);
sam9.add(v7);
sam9.add(v6);
sam9.add(v5);
sam9.add(v4);
sam9.add(v3);
sam9.add(v2);
sam9.add(v1);

Sample sam10 = new Sample();
Tag tt10 = new Tag("label", "World", 0, 20);
sam10.addTag(tt10);
sam10.add(v20);
sam10.add(v19);
sam10.add(v18);
sam10.add(v17);
sam10.add(v16);
sam10.add(v15);
sam10.add(v14);
sam10.add(v13);
sam10.add(v12);
sam10.add(v11);
sam10.add(v10);
sam10.add(v9);
sam10.add(v8);
sam10.add(v7);
sam10.add(v6);
sam10.add(v5);
sam10.add(v4);
sam10.add(v3);
sam10.add(v2);
sam10.add(v1);
// </editor-fold>

myLib.addSample(sam1);
myLib.addSample(sam2);
myLib.addSample(sam3);
myLib.addSample(sam4);
myLib.addSample(sam5);
myLib.addSample(sam6);
myLib.addSample(sam7);
myLib.addSample(sam8);
myLib.addSample(sam9);
myLib.addSample(sam10);
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Save sample files and start training">
try {
myLib.save(myLib.getPath());
String trainresults = htk.train(myLib, myOpt);
System.out.println(trainresults);
} catch (Exception ex) {
System.out.println(ex);
}
//</editor-fold>

// <editor-fold defaultstate="collapsed" desc="Load samples from disk">
Library lib = null;
HTKOptions opt = null;
try {
String libPath = "C:\\temp\\lib.xml";
lib = Library.load(libPath);
lib.setPath(libPath);

opt = HTKOptions.load("C:\\temp\\opt.xml");
opt.setPRJ_DIR(".");
} catch (Exception ex) {
ex.printStackTrace();
}

//</editor-fold>

// <editor-fold defaultstate="collapsed" desc="Start recognizing">
HTK htk2 = new HTK(opt);

// <editor-fold defaultstate="collapsed" desc="Initialize test data">
Sample testData = new Sample();
testData.add(v2);
testData.add(v3);
testData.add(v4);
testData.add(v5);
testData.add(v5);
testData.add(v6);
testData.add(v7);
testData.add(v8);
testData.add(v8);
testData.add(v8);
testData.add(v8);
testData.add(v9);
testData.add(v10);
testData.add(v11);
testData.add(v12);
testData.add(v12);
testData.add(v12);
testData.add(v12);
testData.add(v13);
testData.add(v14);
testData.add(v15);
testData.add(v16);
//</editor-fold>

Result result = htk2.recognize(testData);
System.out.println(result.getGestureResult());
//</editor-fold>
}
}

2008年4月6日星期日

Setting up Subversion on Windows

When it comes to readily available, free source control, I don't think you can do better than Subversion at the moment. I'm not necessarily advocating Subversion; there are plenty of other great source control systems out there -- but few can match the ubiquity and relative simplicity of Subversion. Beyond that, source control is source control, as long as you're not using Visual SourceSafe. And did I mention that Subversion is ... free?

Allow me to illustrate how straightforward it is to get a small Subversion server and client going on Windows. It'll take all of 30 minutes, tops, I promise. And that's assuming you read slowly.

The first thing we'll do is download the latest Subversion Windows binary installer. At the time of writing, that's 1.46. I recommend overriding the default install path and going with something shorter:

c:\svn\


Note that the installer adds c:\svn\bin to your path, so you can launch a command prompt and start working with it immediately. Let's create our first source repository, which is effectively a system path.



svnadmin create "c:\svn\repository"


Within that newly created folder, uncomment the following lines in the conf/svnserve.conf file by removing the pound character from the start of each line:



anon-access = none
auth-access = write
password-db = passwd


Next, add some users to the conf/passwd file. You can uncomment the default harry and sally users to play with, or add your own:



harry = harryssecret
sally = sallyssecret


As of Subversion 1.4, you can easily install Subversion as a Windows service, so it's always available. Just issue the following command:



sc create svnserver binpath= "c:\svn\bin\svnserve.exe --service -r c:\svn\repository" 
displayname= "Subversion" depend= Tcpip start= auto


It's set to auto-start so it will start up automatically when the server is rebooted, but it's not running yet. Let's fix that:



net start svnserver


Note that the service is running under the Local System account, which has extremely limited permissions. Normally, this is OK, but if you plan to implement any Subversion hook scripts later, you'll want to switch the service identity to another account with more permissions. This is easy enough to do through the traditional Windows services GUI.



Subversion service screenshot



Now let's verify that things are working locally by adding a root-level folder in source control for our new project, aptly named myproject.



set SVN_EDITOR=c:\windows\system32\notepad.exe
svn mkdir svn://localhost/myproject


It's a little weird when running locally on the server, as Subversion will pop up a copy of Notepad with a place for us to enter commit comments. Every good programmer always comments their source control actions, right?



Subversion local commit, notepad comment



Enter whatever comment you like, then save and close Notepad. You'll be prompted for credentials at this point; ignore the prompt for Administrator credentials and press enter. Use the credentials you set up earlier in the conf/passwd file. If everything goes to plan, you should be rewarded with a "committed revision 1" message.



svn mkdir svn://localhost/myproject
Authentication realm:
Password for 'Administrator': [enter]
Authentication realm:
Username: sally
Password for 'sally': ************

Committed revision 1.


Congratulations! You just checked your first change into source control!



We specified svn:// as the prefix to our source control path, which means we're using the native Subversion protocol. The Subversion protocol operates on TCP port 3690, so be sure to poke an appropriate hole in your server's firewall, otherwise clients won't be able to connect.



Now that the server's good to go, let's turn our attention to the client. Most people use TortoiseSVN to interact with Subversion. Download the latest 32-bit or 64-bit Windows client (1.4.8.12137 as of this writing) and install it. The installer will tell you to reboot, but you don't have to.



Now create a project folder somewhere on your drive. I used c:\myproject. Tortoise isn't a program so much as a shell extension. To interact with it, you right click in Explorer. Once you've created the project folder, right click in it and select "SVN Checkout..."



Tortoise 'SVN Checkout...'



Type svn://servername/myproject/ for the repository URL and click OK.



Tortoise checkout dialog



Tortoise now associates the c:\myproject folder with the svn://servername/myproject path in source control. Anything you do on your local filesystem path (well, most things-- there are some edge conditions that can get weird) can be checked back in to source control.



There's a standard convention in Subversion to start with the "TTB folders" at the root of any project:



Because Subversion uses regular directory copies for branching and tagging (see Chapter 4, Branching and Merging), the Subversion community recommends that you choose a repository location for each project root -- the "top-most" directory which contains data related to that project -- and then create three subdirectories beneath that root: trunk, meaning the directory under which the main project development occurs; branches, which is a directory in which to create various named branches of the main development line; tags, which is a collection of tree snapshots that are created, and perhaps destroyed, but never changed.


Of course, none of this means your developers will actually understand branching and merging, but as responsible Subversion users, let's dutifully add the TTB folders to our project. Note that we can batch up as many changes as we want and check them all in atomically as one unit. Once we're done, right click the folder and select "SVN Commit..."



Tortoise 'SVN Commit...'



In the commit dialog, indicate that yes, we do want to check in these files, and we always enter a checkin comment-- right? right?



Tortoise Commit dialog



You'll have to enter your server credentials here, but Tortoise will offer to conveniently cache them for you. Once the commit completes, note that the files show up in the shell with source control icon overlays:



Tortoise folder with source control icon overlays



And now we're done. Well, almost. There are a few settings in Tortoise you need to pay special attention to. Right click and select "TortoiseSVN, Settings".




  1. See that hidden ".svn" folder? These folders are where Subversion puts its hidden metadata schmutz so it can keep track of what you're doing in the local filesystem and resolve those changes with the server. The default naming convention of these folders unfortunately conflicts with some fundamental ASP.NET assumptions. If you're an ASP.NET developer, you need to switch the hidden folders from ".svn" to "_svn" format, which is on the General options page.


  2. I'll never understand why, but by default, Tortoise tries to apply source control overlays across every single folder and drive on your system. This can lead to some odd, frustrating file locking problems. Much better to let Tortoise know that it should only work its shell magic on specific folders. Set this via "Icon Overlays"; look for the exclude and include paths. I set the exclude path to everything, and the include path to only my project folder(s).

    tortoise exclude and include paths





Unfortunately, since Tortoise is a shell extension, setting changes may mean you need to reboot. You can try terminating and restarting explorer.exe, but I've had mixed results with that.



And with that, we're done. You've successfully set up a Subversion server and client. A modern client-server source control system inside 30 minutes -- not bad at all. As usual, this is only intended as the gentlest of introductions; I encourage you to check out the excellent Subversion documentation for more depth.



I find Subversion to be an excellent, modern source control system. Any minor deficiencies it has (and there are a few, to be clear) are more than made up by its ubiquity, relative simplicity, and robust community support. In the interests of equal time, however, I should mention that some influential developers -- most notably Linus Torvalds -- hate Subversion and view it as an actual evil. There's an emerging class of distributed revision control that could eventually supercede existing all the centralized source control systems like Subversion, Vault, Team System, and Perforce.



I'm skeptical. I've met precious few developers that really understood the versioning concepts in the simple centralized source control model. I have only the vaguest of hopes that these developers will be able to wrap their brains around the vastly more complicated and powerful model of distributed source control. It took fifteen years for centralized source control usage to become mainstream, so a little patience is always advisable.



[advertisement] Data Dynamics Reports: An easy-to-use reporting platform for .NET developers. Master Reports, Data Visualizers, Dashboard controls and more!



http://www.codinghorror.com/blog/archives/001093.html