Use ictclas4j in JSP

Source: Internet
Author: User

I modified the ictclas4j Chinese word segmentation system a few days ago and called it in JSP. when loading the dictionary, the path problem occurs. The call method is to instantiate the Java class in JSP, call the Java class method to complete Chinese word segmentation. the JSP Code is as follows ::
<% @ page contenttype = "text/html; charset = gb2312" %>
<% @ page import = "bean. *, org. ictclas4j. segment. *, org. ictclas4j. bean. *, Java. io. *, Java. util. *, org. ictclas4j. utility. * "%>
<%
string PRM = new string ();
request. setcharacterencoding ("gb2312");
PRM = request. getparameter ("txt1 "). tostring ();
out. println ("before word segmentation:
");
out. println (PRM + "
");
segtag = new segtag (1 );
segresult seg_res = segtag. split (PRM);
string result = new string (seg_res.getfinalresult ();
out. println ("points later:
");
out. println (result);
%>
pay attention to the red code. when instantiating the segresult object, the code for loading the dictionary is as follows:
Public segtag (INT segpathcount) {
This. segpathcount = segpathcount;
coredict = New Dictionary (" E: \ nextspace \ data \ coredict. DCT ");

bigramdict = New Dictionary (" E: \ nextspace \ data \ bigramdict. DCT ");
persontagger = new postagger (utility. tag_type.tt_person, " E: \ nextspace \ data \ Nr ", coredict );
transpersontagger = new postagger (utility. tag_type.tt_trans_person, " E: \ nextspace \ data \ tr ", coredict);
placettings ER = new postagger (utility. tag_type.tt_trans_person, " E: \ nextspace \ data \ NS ", coredict );
lextagger = new postagger (utility. tag_type.tt_normal, " E: \ nextspace \ data \ lexical ", coredict );
}< br> note that the red code is the absolute path for loading the dictionary. In this way, Chinese word segmentation can be implemented, but problems may occur after being transferred to another machine, because this absolute path is relative to my computer, if his dictionary is not on the edisk after it is transferred to another computer, or is no longer in the E: \ nextspace \ data directory, the dictionary cannot be found. Exception. If you use the relative path, an exception will be reported. This problem has plagued me for two days. I hope you can help me with this problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.