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.