package org.linkgrammar;

/**
 * This class serves as a wrapper to the C Link Grammar Parser library.
 * It provides a simple public Java API to the equivalent public C API.
 *
 * Unfortunately, this class is not at all OOP in style; it operates on 
 * the single, current sentence and linkage.  This could be improved.
 */

public class LinkGrammar
{
    static
    {
        // On a linux system, the actual name of the library is prefixed 
        // with "lib" and suffixed with ".so" -- e.g. "liblink-grammar-java.so"
        System.loadLibrary("link-grammar-java");
    }

    // C functions for changing linkparser options
    public static native void setMaxParseSeconds(int maxParseSeconds);

    public static native void setMaxCost(int maxCost);

    // Defaults to /usr/local/share/link-grammar/
    public static native void setDictionariesPath(String path);
    
    // C functions in the linkparser API
    public static native void init();

    public static native void parse(String sent);

    public static native void close();

    // C sentence access functions
    public static native int getNumWords();

    public static native String getWord(int i);

    public static native int getNumSkippedWords();

    // C linkage access functions
    public static native int getNumLinkages();

    public static native void makeLinkage(int index);

    public static native int getLinkageNumViolations();

    public static native int getLinkageDisjunctCost();

    public static native int getNumLinks();

    public static native int getLinkLWord(int link);

    public static native int getLinkRWord(int link);

    public static native String getLinkLLabel(int link);

    public static native String getLinkRLabel(int link);

    public static native String getLinkLabel(int link);

    public static native String getConstituentString();

    public static native String getLinkString();

    // OTHER UTILITY C FUNCTIONS
    public static native boolean isPastTenseForm(String word);

    public static native boolean isEntity(String word);
}


@@ -241,18 +241,17 @@
 rates on
- 
 %0A
+
  * the s
@@ -377,17 +377,17 @@
 // On a 
-l
+L
 inux sys
@@ -421,16 +421,27 @@
  library
+%0A        //
  is pref
@@ -445,28 +445,16 @@
 refixed 
-%0A        // 
 with %22li
@@ -479,16 +479,27 @@
 th %22.so%22
+%0A        //
  -- e.g.
@@ -521,24 +521,427 @@
 ar-java.so%22%0A
+        // Windows looks for %22link-grammar-java.dll%22%0A        //%0A        // On a Windows system, we also need to load the prequisite%0A        // libraries first. (Linux loaders do this automatically).%0A        //%0A        String osname = System.getProperty(%22os.name%22);%0A        if (osname.indexOf(%22win%22) %3E -1 %7C%7C osname.indexOf(%22Win%22) %3E -1)%0A        %7B%0A            System.loadLibrary(%22link-grammar%22);%0A        %7D%0A
         Syst
@@ -1277,20 +1277,16 @@
  path);%0A
-    
 %0A    // 

load the pre-req libraries on Windows.