Sunday, December 9, 2012

Learning JNI(一):

one good webpage:
http://marakana.com/bookshelf/java_fundamentals_tutorial/_java_native_interface_jni.html


I'm using eclipse.
So first I need to add javah for eclipse.

run -> external tools - > external tools configuarations -> Program.
Add Name:javah_JNI_gen
Location: /usr/lib/jvm/java-1.6.0-openjdk/bin/javah
Working Directory:
${workspace_loc:/${project_name}/bin}
Arguments:
-classpath ${project_classpath} -v -d ${workspace_loc:/${project_name}/src} ${java_type_name}


Then write some java code, such as:


package simple;

public class Hello {

    public native void sayHi(String who, int times); //1

      static { System.loadLibrary("HelloImpl"); } //2

      public static void main (String[] args) {
        Hello hello = new Hello();
        hello.sayHi("Ying", 2); //3
      }

}


Choose Run -> external tools -> javah***, then it will create a file simple_Hello.h in bin/

Now you can write a simple_Hello.c

#include <stdio.h>
#include "simple_Hello.h"

JNIEXPORT void JNICALL Java_simple_Hello_sayHi(JNIEnv *env, jobject obj, jstring who, jint times) {
  jint i;
  jboolean iscopy;
  const char *name;
  name = (*env)->GetStringUTFChars(env, who, &iscopy);
  for (i = 0; i < times; i++) {
    printf("Hello %s\n", name);
  }
}

compile:

gcc -o libHelloImpl.so -lc -shared \
    -I/usr/lib/jvm/java-6-openjdk/include \
    -I/usr/lib/jvm/java-6-openjdk/include/linux simple_Hello.c  -fPIC

Note that in my case, nod adding -fPIC will have compile mistakes.

Now you can run the java program :)



When you use the *.so file for other project, add it into eclipse  Project -> Properties -> Libraries -> choose the bottom JRE System Library,

native library location -> Edit, add the path of the so file, such as:
/home/ying/study/tools/SVM-Light-1.5-to-be-released/jniLib




How to Load a Java Native/Shared Library (.so)

from http://www.chilkatsoft.com/java-loadLibrary-Linux.asp

There are several ways to make it possible for the Java runtime to find and load a native shared library (.so) at runtime. I will list them briefly here, followed by examples with more explanation below.
  1. Call System.load to load the .so from an explicitly specified absolute path.
  2. Copy the shared library to one of the paths already listed in java.library.path
  3. Modify the LD_LIBRARY_PATH environment variable to include the directory where the shared library is located.
  4. Specify the java.library.path on the command line by using the -D option.

1. Call System.load to load the shared library from an explicitly specified absolute path.

This choice removes all uncertainty, but embeds a hard-coded path within your Java application. Example:
import com.chilkatsoft.CkZip;

public class Test {
 
  static {
    try {
     System.load("/home/joe/chilkatJava/libchilkat.so");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[]) 
  {
    CkZip zip = new CkZip();
    System.out.println(zip.version());    
  }
}

2. Copy the shared library to one of the paths already listed in java.library.path

To view the paths listed in java.library.path, run this Java code:
String property = System.getProperty("java.library.path");
StringTokenizer parser = new StringTokenizer(property, ";");
while (parser.hasMoreTokens()) {
    System.err.println(parser.nextToken());
    }
Note: The java.library.path is initialized from the LD_LIBRARY_PATH environment variable.
The loadLibrary method may be used when the directory containing the shared library is in java.library.path. To load "libchilkat.so", call System.loadLibrary("chilkat"), as shown below.
import com.chilkatsoft.CkZip;

public class Test {
 
  static {
    try {
     
     System.loadLibrary("chilkat");
     
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }
 
  public static void main(String argv[])
   {
    CkZip zip = new CkZip();
    System.out.println(zip.version());
 }
  }

3. Modify the LD_LIBRARY_PATH environment variable to include the path where the Chilkat shared library is located.

For Bourne Shell, K Shell or Bash, type:
export LD_LIBRARY_PATH=/home/joe/chilkatJava-9.1.1-x86_64-linux:$LD_LIBRARY_PATH
For C Shell, type:
setenv LD_LIBRARY_PATH "/home/joe/chilkatJava-9.1.1-x86_64-linux:$LD_LIBRARY_PATH"

4. Specify the java.library.path on the command line by using the -D option.

For example:
java -Djava.library.path=".:/home/joe/chilkatJava-9.1.1-x86_64-linux" TestApp

Friday, November 23, 2012

Surdeanu_ACL11_customizing an information extraction system to a new domain

The paper implements a pipeline system for relation extraction. First NE, the RE. The RE system features are selected based on the ACE corpus. The test domain is the sports news.

They showed that gazetteer doesn't help that much.
 Identify the head of arguments is important. They proposed several heuristics for this:

1. append "It was" to the entity, then parse the entity by the Stanford parser.
2. remove dashes as it is not common in the Penn treebank.
3. Guide the Stanford parser such that the final tree contains a constituent with the same span. (Need the check how to do this.)


They show domain specific deterministic rules also helps. such as "teamFinalScore(G, S) :- teamInGame(T,G), teamScoringAll(T,S)"

Saturday, November 10, 2012

all kinds of steam buns

Making steam buns today.

The dough:
1 Table Spoon (T) active yeast.
1Cup (C) warm water.
4 C all purpose flour.
2 T sugar
1 t baking powder
1 t salt.

put ingredients into the bread machine. Found that my yeast is expired -_- Then I rush to Sobeys bought a new one. Came back, hope every thing will be OK.

stuffing:
three types.
1. ground pork: with ginger, garlic, cooking wine, white pepper. 15minutes steam.
2. sesame: with sugar. 1:1. 5 minutes steam.
3. red bean: mashed with red sugar. 10 minutes steam.

result:
OK, not enough water.... the ground pork tastes good, but sugar is not enough for sesame. The skin is not soft, too chewy... I guess it's because we left for 30 minutes for the yeast....

Try again next month. Too tired.

Thursday, October 25, 2012

learning dependency-based compositional semantics

just read half. Don't understand.... I don't know what are those symbols. Need more background.