Search in sources :

Example 1 with XlayerClient

use of org.opensextant.xlayer.XlayerClient in project Xponents by OpenSextant.

the class XlayerClientTest method main.

public static void main(String[] args) {
    URL url;
    try {
        url = new URL(args[0]);
        /*
             * Create client.
             */
        XlayerClient c = new XlayerClient(url);
        try {
            /* 
                 * Prepare request.  Text must be UTF-8 encoded.
                 * Note -- readFile() here assumes the file is unicode content
                 * 
                 */
            String text = FileUtility.readFile(args[1]);
            String docid = args[1];
            /*
                 * Process the text and print results to console.
                 * Result is an array of TextMatch objects.  For each particular
                 * TextMatch (Xponents Basic API), you have some common fields related to the 
                 * text found, and then class-specific fields and objects you need to evaluate yourself.
                 * 
                 * The XlayerClient process() method makes use of Transforms helper class to 
                 * digest JSON annotations into Java API TextMatch objects of various flavors.
                 */
            List<TextMatch> results = c.process(docid, text);
            for (TextMatch m : results) {
                System.out.println(String.format("Found %s %s @ (%d:%d)", m.getType(), m.getText(), m.start, m.end));
            }
        } catch (Exception parseErr) {
            parseErr.printStackTrace();
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ConfigException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XlayerClient(org.opensextant.xlayer.XlayerClient) ConfigException(org.opensextant.ConfigException) TextMatch(org.opensextant.extraction.TextMatch) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) ConfigException(org.opensextant.ConfigException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ConfigException (org.opensextant.ConfigException)1 TextMatch (org.opensextant.extraction.TextMatch)1 XlayerClient (org.opensextant.xlayer.XlayerClient)1