Hi adam,
i feel happy if u give the steps to fallow. how to develop
UIMA as web application.
i will explain u till now what i have done.
1) have written on servlet with name test.java,
2)i have written one more class with main method
3)i put descriptors like aedescriptor.xml,type,input and out put under web
root and also in tomact folder.
i have run that project in eclipse console i got the result which is
raeding from the c:/tomacta/descriptor.
once this is over i opend IEBrowser given urlpattern here i got that error
which is there in previous reply.i will add my code it.plz don't mind
i hope u will get my point what i am trying to say
i was stuck up here
vijay
On 9/18/07, Adam Lally <[EMAIL PROTECTED]> wrote:
>
> On 9/18/07, vijay vijay <[EMAIL PROTECTED]> wrote:
> > And main problem is i am not getting in IEBrowser i
> > have given it as like thishttp://localhost:8000//UIMAWeb/servlet/Test
> > here i got error saying "com.ibm.uima.util.InvalidXMLException".invalid
> > descriptor file at"c://tomcat/descriptor/webanalysis.xml".i have tried
> in
> > google but didn't get relevent ones.
> >
>
> Please post the whole stack trace for the InvalidXMLException if you
> can get it. Usually further down in the stack trace it will say
> "caused by:", followed by a more detailed reason for why the
> descriptor was invalid.
>
>
> About the configuration parameter, you are saying that in your main
> program you call setConfigParameterValue followed by reconfigure(),
> and still your annotator does not get the correct value? You could
> put a println call in your annotator's initialize() method just to be
> sure the value is not being passed. Make sure the parameter name is
> spelled the same in all three places - in your main(), in the
> annotator code, and in your annotator's descriptor file. I'm running
> out of ideas here...
>
> -Adam
>
package com.iton.uima;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.uima.UIMAFramework;
import com.ibm.uima.analysis_engine.AnalysisEngine;
import com.ibm.uima.analysis_engine.AnalysisEngineProcessException;
import com.ibm.uima.cas.CAS;
import com.ibm.uima.examples.PrintAnnotations;
import com.ibm.uima.resource.ResourceSpecifier;
import com.ibm.uima.util.XMLInputSource;
import com.iton.uima.Clases.ExampleApplication;
public class Test extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintStream stream = new
PrintStream(response.getOutputStream());
try
{
File taeDescriptor = new File("descriptor\\aeDescriptor.xml");
File inputDir = new File("input");
String file1 = "output.txt";
String file2 = "package.html";
System.out.println("file is:"+file1);
System.out.println("file 2 is :"+file2);
//Read and validate command line arguments
boolean validArgs = false;
/*if (args.length == 2)
{
taeDescriptor = new File(file1);
inputDir = new File(file2);
validArgs = taeDescriptor.exists() &&
!taeDescriptor.isDirectory() &&
inputDir.isDirectory();
}*/
//System.out.println("length is:"+args.length);
{
//get Resource Specifier from XML file
XMLInputSource in = new XMLInputSource(taeDescriptor);
ResourceSpecifier specifier =
UIMAFramework.getXMLParser().parseResourceSpecifier(in);
//for debugging, output the Resource Specifier
//System.out.println(specifier);
//create Analysis Engine
AnalysisEngine ae =
UIMAFramework.produceAnalysisEngine(specifier);
ae.setConfigParameterValue("StringsToAnnotate", new
String[]
{"Michael","UIMA","Vijay"});
//create a CAS
CAS cas = ae.newCAS();
//get all files in the input directory
File[] files = inputDir.listFiles();
if (files == null)
{
System.out.println("No files to process");
}
else
{
//process documents
for(int i = 0; i < files.length; i++)
{
if (!files[i].isDirectory())
{
processFile(files[i], ae, cas, stream);
}
}
}
ae.destroy();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
private static void processFile( File aFile, AnalysisEngine aAE,
CAS aCAS, PrintStream out)
throws IOException, AnalysisEngineProcessException
{
System.out.println("Processing file " + aFile.getName());
FileInputStream fis = null;
try
{
//read file
fis = new FileInputStream(aFile );
byte[] contents = new byte[(int)aFile.length() ];
fis.read( contents );
String document = new String(contents, "UTF-8");
document = document.trim();
//put document text in CAS
aCAS.setDocumentText(document);
//process
aAE.process(aCAS);
//print annotations to System.out
PrintAnnotations.printAnnotations(aCAS, out);
//reset the CAS to prepare it for processing the next
document
aCAS.reset();
}
finally
{
try
{
if ( fis != null )
fis.close();
}
catch( Exception ex )
{
ex.printStackTrace();
}
}
}
}
package com.iton.uima.Clases;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import com.ibm.uima.UIMAFramework;
import com.ibm.uima.analysis_engine.AnalysisEngine;
import com.ibm.uima.analysis_engine.AnalysisEngineProcessException;
import com.ibm.uima.cas.CAS;
import com.ibm.uima.resource.ResourceSpecifier;
import com.ibm.uima.util.XMLInputSource;
import com.ibm.uima.examples.PrintAnnotations;
public class ExampleApplication
{
public static void main(String[] args) {
ExampleApplication ex = new ExampleApplication();
ex.testAnnotation(System.out);
}
public void testAnnotation(PrintStream out)
{
try
{
File inputDir = new File("C:\\tomcat\\input");
URL taeDescriptor = new
URL("http://192.168.0.126:8000/UIMAWeb/descriptor/webanalysis.xml");
// URL inputDir = new URL("input");
String file1 = "output.txt";
String file2 = "package.html";
System.out.println("file is:"+file1);
System.out.println("file 2 is :"+file2);
System.out.println("step :1");
//Read and validate command line arguments
boolean validArgs = false;
/*if (args.length == 2)
{
taeDescriptor = new File(file1);
inputDir = new File(file2);
validArgs = taeDescriptor.exists() && !taeDescriptor.isDirectory() &&
inputDir.isDirectory();
}*/
//System.out.println("length is:"+args.length);
{
//get Resource Specifier from XML file
XMLInputSource in = new XMLInputSource(taeDescriptor);
System.out.println("step :2");
ResourceSpecifier specifier =
UIMAFramework.getXMLParser().parseResourceSpecifier(in);
System.out.println("step :3");
//for debugging, output the Resource Specifier
//System.out.println(specifier);
//create Analysis Engine
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
System.out.println("step :1");
ae.setConfigParameterValue("StringsToAnnotate", new String[]
{"Michael","UIMA","Vijay"});
System.out.println("step :4");
//create a CAS
CAS cas = ae.newCAS();
System.out.println("step :1");
//get all files in the input directory
File[] files = inputDir.listFiles();
if (files == null)
{
System.out.println("No files to process");
}
else
{
//process documents
for(int i = 0; i < files.length; i++)
{
if (!files[i].isDirectory())
{
processFile(files[i], ae, cas, out);
}
}
}
//ae.reconfigure();
ae.destroy();
}
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("step :5");
}
/**
* Prints usage message.
*/
private static void printUsageMessage()
{
System.err.println("Usage: java com.ibm.uima.example.ExampleApplication "
+ "</exampleApplication/descriptor/AnalysisEngine.xml>
</exampleApplication/input> </exampleApplication/output>");
}
/**
* Processes a single XML file and prints annotations to System.out
*
* @param aFile file to process
* @param aAE Analysis Engine that will process the file
* @param aCAS CAS that will be used to hold analysis results
*/
private static void processFile( File aFile, AnalysisEngine aAE,
CAS aCAS, PrintStream out)
throws IOException, AnalysisEngineProcessException
{
System.out.println("Processing file " + aFile.getName());
FileInputStream fis = null;
try
{
//read file
fis = new FileInputStream(aFile );
byte[] contents = new byte[(int)aFile.length() ];
fis.read( contents );
String document = new String(contents, "UTF-8");
document = document.trim();
//put document text in CAS
aCAS.setDocumentText(document);
//process
aAE.process(aCAS);
//print annotations to System.out
PrintAnnotations.printAnnotations(aCAS, out);
//reset the CAS to prepare it for processing the next document
aCAS.reset();
}
finally
{
try
{
if ( fis != null )
fis.close();
}
catch( Exception ex )
{
ex.printStackTrace();
}
}
}
}