You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@opennlp.apache.org by Amal Elmah <am...@hotmail.com> on 2011/06/12 22:03:27 UTC

Opennlp API

I managed to download models from the website using different browser
when I tried to use models from my application I faced the problem that my program does not recognize bin files so it gives me the following 
error:
java.io.FileNotFoundException: en-token.bin (??????? ??? ?????? ?????? ??? ????? ??????)
	java.io.FileInputStream.open(Native Method)
	java.io.FileInputStream.<init>(FileInputStream.java:120)
	java.io.FileInputStream.<init>(FileInputStream.java:79)
	org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

The code I used is 

 InputStream modelIn = new FileInputStream("en-token.bin");
 TokenizerModel model = new TokenizerModel(modelIn);

I put en-token.bin file with the ****.jsp files I donot know what is the problem?

thanks guys,
Amal
 

 		 	   		  

Re: Opennlp API

Posted by Benson Margulies <bi...@gmail.com>.
You have to pass the result of getRealPath into the constructor of
FileInputStream.

On Mon, Jun 13, 2011 at 12:26 PM, Amal Elmah
<am...@hotmail.com> wrote:
>
> this is my java code in jsp file
> <%
> // loaded model
>  getServletContext().getRealPath("/WEB-INF/en-token.bin");
>  InputStream modelIn = new FileInputStream("en-token.bin");
>  TokenizerModel model = new TokenizerModel(modelIn);
>  if (modelIn != null) {
>    try {
>      modelIn.close();
>    }
>    catch (IOException e) {
>    }
>  }
> // TokenizerME can be instantiated
> Tokenizer tokenizer = new TokenizerME(model);
> String tokens[] = tokenizer.tokenize("An input sample sentence.");
> for (int i=0;i<tokens.length;i++)
>       {
>    %>
>
> I gives this error Stacktrace:
>        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
>        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:404)
>        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>
>> Date: Mon, 13 Jun 2011 12:07:23 -0400
>> Subject: Re: Opennlp API
>> From: bimargulies@gmail.com
>> To: opennlp-users@incubator.apache.org
>>
>> One option is to put the bin file in WEB-INF, and then call
>> getServletContext().getRealPath("/WEB-INF/whatever.bin") in your jsp
>> file.
>>
>>
>>
>>
>>
>> On Mon, Jun 13, 2011 at 12:02 PM, Amal Elmah
>> <am...@hotmail.com> wrote:
>> >
>> > thanks a lot for replying
>> >
>> > I have never used servlet I always use JSP when it comes to web development. So could you please tell me what do you mean by
>> > "you need to make the servlet API call to get a 'real' pathname for it", Give me a simple example or any link that could guide me?
>> > I also have another question you say
>> > " The .bin file is in the file system"
>> > where exactly should the file be?
>> >
>> >
>> >
>> >> Date: Sun, 12 Jun 2011 16:06:34 -0400
>> >> Subject: Re: Opennlp API
>> >> From: bimargulies@gmail.com
>> >> To: opennlp-users@incubator.apache.org
>> >>
>> >> That's not how Java works. The .bin file is in the file system, and
>> >> you need to make the servlet API call to get a 'real' pathname for it.
>> >> There's no concept of 'current directory' of files next to jsp files
>> >> in a webapp.
>> >>
>> >> On Sun, Jun 12, 2011 at 4:03 PM, Amal Elmah
>> >> <am...@hotmail.com> wrote:
>> >> >
>> >> > I managed to download models from the website using different browser
>> >> > when I tried to use models from my application I faced the problem that my program does not recognize bin files so it gives me the following
>> >> > error:
>> >> > java.io.FileNotFoundException: en-token.bin (??????? ??? ?????? ?????? ??? ????? ??????)
>> >> >        java.io.FileInputStream.open(Native Method)
>> >> >        java.io.FileInputStream.<init>(FileInputStream.java:120)
>> >> >        java.io.FileInputStream.<init>(FileInputStream.java:79)
>> >> >        org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
>> >> >        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>> >> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>> >> >        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
>> >> >        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>> >> >        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>> >> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>> >> >
>> >> > The code I used is
>> >> >
>> >> >  InputStream modelIn = new FileInputStream("en-token.bin");
>> >> >  TokenizerModel model = new TokenizerModel(modelIn);
>> >> >
>> >> > I put en-token.bin file with the ****.jsp files I donot know what is the problem?
>> >> >
>> >> > thanks guys,
>> >> > Amal
>> >> >
>> >> >
>> >> >
>> >
>

RE: Opennlp API

Posted by Amal Elmah <am...@hotmail.com>.
this is my java code in jsp file
<%
// loaded model 
 getServletContext().getRealPath("/WEB-INF/en-token.bin");
 InputStream modelIn = new FileInputStream("en-token.bin");
 TokenizerModel model = new TokenizerModel(modelIn);
  if (modelIn != null) {
    try {
      modelIn.close();
    }
    catch (IOException e) {
    }
  }
// TokenizerME can be instantiated
Tokenizer tokenizer = new TokenizerME(model);
String tokens[] = tokenizer.tokenize("An input sample sentence.");
for (int i=0;i<tokens.length;i++)
       {
    %>

I gives this error Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:404)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 
> Date: Mon, 13 Jun 2011 12:07:23 -0400
> Subject: Re: Opennlp API
> From: bimargulies@gmail.com
> To: opennlp-users@incubator.apache.org
> 
> One option is to put the bin file in WEB-INF, and then call
> getServletContext().getRealPath("/WEB-INF/whatever.bin") in your jsp
> file.
> 
> 
> 
> 
> 
> On Mon, Jun 13, 2011 at 12:02 PM, Amal Elmah
> <am...@hotmail.com> wrote:
> >
> > thanks a lot for replying
> >
> > I have never used servlet I always use JSP when it comes to web development. So could you please tell me what do you mean by
> > "you need to make the servlet API call to get a 'real' pathname for it", Give me a simple example or any link that could guide me?
> > I also have another question you say
> > " The .bin file is in the file system"
> > where exactly should the file be?
> >
> >
> >
> >> Date: Sun, 12 Jun 2011 16:06:34 -0400
> >> Subject: Re: Opennlp API
> >> From: bimargulies@gmail.com
> >> To: opennlp-users@incubator.apache.org
> >>
> >> That's not how Java works. The .bin file is in the file system, and
> >> you need to make the servlet API call to get a 'real' pathname for it.
> >> There's no concept of 'current directory' of files next to jsp files
> >> in a webapp.
> >>
> >> On Sun, Jun 12, 2011 at 4:03 PM, Amal Elmah
> >> <am...@hotmail.com> wrote:
> >> >
> >> > I managed to download models from the website using different browser
> >> > when I tried to use models from my application I faced the problem that my program does not recognize bin files so it gives me the following
> >> > error:
> >> > java.io.FileNotFoundException: en-token.bin (??????? ??? ?????? ?????? ??? ????? ??????)
> >> >        java.io.FileInputStream.open(Native Method)
> >> >        java.io.FileInputStream.<init>(FileInputStream.java:120)
> >> >        java.io.FileInputStream.<init>(FileInputStream.java:79)
> >> >        org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
> >> >        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> >> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >> >        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
> >> >        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
> >> >        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
> >> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >> >
> >> > The code I used is
> >> >
> >> >  InputStream modelIn = new FileInputStream("en-token.bin");
> >> >  TokenizerModel model = new TokenizerModel(modelIn);
> >> >
> >> > I put en-token.bin file with the ****.jsp files I donot know what is the problem?
> >> >
> >> > thanks guys,
> >> > Amal
> >> >
> >> >
> >> >
> >
 		 	   		  

Re: Opennlp API

Posted by Benson Margulies <bi...@gmail.com>.
One option is to put the bin file in WEB-INF, and then call
getServletContext().getRealPath("/WEB-INF/whatever.bin") in your jsp
file.





On Mon, Jun 13, 2011 at 12:02 PM, Amal Elmah
<am...@hotmail.com> wrote:
>
> thanks a lot for replying
>
> I have never used servlet I always use JSP when it comes to web development. So could you please tell me what do you mean by
> "you need to make the servlet API call to get a 'real' pathname for it", Give me a simple example or any link that could guide me?
> I also have another question you say
> " The .bin file is in the file system"
> where exactly should the file be?
>
>
>
>> Date: Sun, 12 Jun 2011 16:06:34 -0400
>> Subject: Re: Opennlp API
>> From: bimargulies@gmail.com
>> To: opennlp-users@incubator.apache.org
>>
>> That's not how Java works. The .bin file is in the file system, and
>> you need to make the servlet API call to get a 'real' pathname for it.
>> There's no concept of 'current directory' of files next to jsp files
>> in a webapp.
>>
>> On Sun, Jun 12, 2011 at 4:03 PM, Amal Elmah
>> <am...@hotmail.com> wrote:
>> >
>> > I managed to download models from the website using different browser
>> > when I tried to use models from my application I faced the problem that my program does not recognize bin files so it gives me the following
>> > error:
>> > java.io.FileNotFoundException: en-token.bin (??????? ??? ?????? ?????? ??? ????? ??????)
>> >        java.io.FileInputStream.open(Native Method)
>> >        java.io.FileInputStream.<init>(FileInputStream.java:120)
>> >        java.io.FileInputStream.<init>(FileInputStream.java:79)
>> >        org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
>> >        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>> >        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
>> >        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>> >        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>> >
>> > The code I used is
>> >
>> >  InputStream modelIn = new FileInputStream("en-token.bin");
>> >  TokenizerModel model = new TokenizerModel(modelIn);
>> >
>> > I put en-token.bin file with the ****.jsp files I donot know what is the problem?
>> >
>> > thanks guys,
>> > Amal
>> >
>> >
>> >
>

RE: Opennlp API

Posted by Amal Elmah <am...@hotmail.com>.
thanks a lot for replying 
 
I have never used servlet I always use JSP when it comes to web development. So could you please tell me what do you mean by 
"you need to make the servlet API call to get a 'real' pathname for it", Give me a simple example or any link that could guide me?
I also have another question you say
" The .bin file is in the file system" 
where exactly should the file be?
 

 
> Date: Sun, 12 Jun 2011 16:06:34 -0400
> Subject: Re: Opennlp API
> From: bimargulies@gmail.com
> To: opennlp-users@incubator.apache.org
> 
> That's not how Java works. The .bin file is in the file system, and
> you need to make the servlet API call to get a 'real' pathname for it.
> There's no concept of 'current directory' of files next to jsp files
> in a webapp.
> 
> On Sun, Jun 12, 2011 at 4:03 PM, Amal Elmah
> <am...@hotmail.com> wrote:
> >
> > I managed to download models from the website using different browser
> > when I tried to use models from my application I faced the problem that my program does not recognize bin files so it gives me the following
> > error:
> > java.io.FileNotFoundException: en-token.bin (??????? ??? ?????? ?????? ??? ????? ??????)
> >        java.io.FileInputStream.open(Native Method)
> >        java.io.FileInputStream.<init>(FileInputStream.java:120)
> >        java.io.FileInputStream.<init>(FileInputStream.java:79)
> >        org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
> >        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
> >        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
> >        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
> >        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> >
> > The code I used is
> >
> >  InputStream modelIn = new FileInputStream("en-token.bin");
> >  TokenizerModel model = new TokenizerModel(modelIn);
> >
> > I put en-token.bin file with the ****.jsp files I donot know what is the problem?
> >
> > thanks guys,
> > Amal
> >
> >
> >
 		 	   		  

Re: Opennlp API

Posted by Benson Margulies <bi...@gmail.com>.
That's not how Java works. The .bin file is in the file system, and
you need to make the servlet API call to get a 'real' pathname for it.
There's no concept of 'current directory' of files next to jsp files
in a webapp.

On Sun, Jun 12, 2011 at 4:03 PM, Amal Elmah
<am...@hotmail.com> wrote:
>
> I managed to download models from the website using different browser
> when I tried to use models from my application I faced the problem that my program does not recognize bin files so it gives me the following
> error:
> java.io.FileNotFoundException: en-token.bin (??????? ??? ?????? ?????? ??? ????? ??????)
>        java.io.FileInputStream.open(Native Method)
>        java.io.FileInputStream.<init>(FileInputStream.java:120)
>        java.io.FileInputStream.<init>(FileInputStream.java:79)
>        org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
>        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
>        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>
> The code I used is
>
>  InputStream modelIn = new FileInputStream("en-token.bin");
>  TokenizerModel model = new TokenizerModel(modelIn);
>
> I put en-token.bin file with the ****.jsp files I donot know what is the problem?
>
> thanks guys,
> Amal
>
>
>