您的位置:首页 > 编程语言 > Java开发

JavaBean中调用ICTCLAS的dll给Jsp

2006-10-29 17:18 337 查看
 中科院的分词系统是非常好的分词系统。

 我在做一个系统时用到了仅仅时研究,同时我参考了 北京师范大学陈天的Java版本。在其中进行部分改动满足自己的需求。

1 jsp文件调用bean。


<%@page contentType="text/html"%>


<%@page pageEncoding="UTF-8"%>


<%@page language="java"%>


<%@page import="java.util.*"%>


<%@page import="java.sql.*"%>


<%--


The taglib directive below imports the JSTL library. If you uncomment it,


you must also add the JSTL library to the project. The Add Library... action


on Libraries node in Projects view can be used to add the JSTL 1.1 library.


--%>


<%--


<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 


--%>




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


   "http://www.w3.org/TR/html4/loose.dtd">


<jsp:useBean id="user" scope="page" class="com.mrl.dbconn.db" />


<jsp:useBean id="ictclas" scope="page" class="com.xjt.nlp.word.ICTCLAS" />


<html>


    <head>


        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


        <title>过滤器首页</title>


    </head>


    <body>




    <h1>过滤器的测试页面欢迎您</h1>


    <%


 Connection con = user.getConn() ;


 Statement stmt = con.createStatement() ;


 String sql="select * from dlog_user";


 ResultSet rs=stmt.executeQuery(sql);


 String strTest="";


 String strTrans="";


 while(rs.next()) 




...{




  strTest=rs.getString("username");


    out.print(strTest);


 }


  ictclas.init(0,2);


strTrans=ictclas.paragraphProcess("巴拿马和美国都是国家地区,汉族是一个民族。/");


 out.print(strTrans);


 String str1="haha";


 String str2="";




 out.print(str2);


%>




    


    </body>


</html>



 

2


package com.xjt.nlp.word;






/** *//**


 * <p>Title: Java中文分词组件</p>


 * <p>Description: 本组件以中科院ICTCLAS系统为基础,在其基础之上改编,


 * 本组件仅供学习和研究用途,任何商业用途将自行承担法律后果,与组件编写人无关。</p>


 * <p>Copyright: Copyright (c) 2004</p>


 * <p>Company: 北京师范大学</p>


 * @author 陈天


 * @version 1.0


 */






public class ICTCLAS ...{


  public static ICTCLAS instance=null;




  public ICTCLAS() ...{


    //init(0,2);


  }






  public synchronized static ICTCLAS getInstance()...{




    if (instance==null)...{


      instance = new ICTCLAS();


    }


    return instance;


  }




  public synchronized native boolean init(int i, int j);


  public synchronized native String paragraphProcess(String sParagraph);


  public synchronized native boolean fileProcess(String source,String target);




  public static void main(String[] args) ...{


    ICTCLAS split1 = new ICTCLAS();


    for (int i=0;i<=100;i++)


      System.out.println(split1.paragraphProcess("巴拿马和美国都是国家地区,汉族是一个民族。/"));


     // System.out.println(split1.fileProcess("c:/1.txt","c:/2.txt"));


  }




  public static String test(String[] args) ...{


    ICTCLAS split1 = new ICTCLAS();


    


    String teststr="";


      teststr=split1.paragraphProcess("巴拿马和美国都是国家地区,汉族是一个民族。/");


   return(teststr);


  }




  static...{


    System.loadLibrary("ICTCLAS");


  }


}

 

3 在Tomcat的bin目录下添加ICTCLAS.dll和data文件夹。

调试通过。



最后发布时。用tomcat在bin目录下放dll文件。dat文件放于tomcat根目录。测试通过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jsp dll tomcat class java string