diff --git a/Doc/allclasses-frame.html b/Doc/allclasses-frame.html index b94ced6..00c0e8a 100644 --- a/Doc/allclasses-frame.html +++ b/Doc/allclasses-frame.html @@ -2,9 +2,9 @@ - + 所有类 - + @@ -24,6 +24,7 @@
  • ReloadConfigServlet
  • SqlHelper
  • UpdateServlet
  • +
  • UpdateSingleConfigServlet
  • UserInfo
  • diff --git a/Doc/allclasses-noframe.html b/Doc/allclasses-noframe.html index 49a1d02..6201711 100644 --- a/Doc/allclasses-noframe.html +++ b/Doc/allclasses-noframe.html @@ -2,9 +2,9 @@ - + 所有类 - + @@ -24,6 +24,7 @@
  • ReloadConfigServlet
  • SqlHelper
  • UpdateServlet
  • +
  • UpdateSingleConfigServlet
  • UserInfo
  • diff --git a/Doc/constant-values.html b/Doc/constant-values.html index 67a01b5..9e56457 100644 --- a/Doc/constant-values.html +++ b/Doc/constant-values.html @@ -2,9 +2,9 @@ - + 常量字段值 - + diff --git a/Doc/db/DB.html b/Doc/db/DB.html index dced64a..339b32f 100644 --- a/Doc/db/DB.html +++ b/Doc/db/DB.html @@ -2,9 +2,9 @@ - + DB - + diff --git a/Doc/db/DBCPUtils.html b/Doc/db/DBCPUtils.html index dbd86b1..b200193 100644 --- a/Doc/db/DBCPUtils.html +++ b/Doc/db/DBCPUtils.html @@ -2,9 +2,9 @@ - + DBCPUtils - + diff --git a/Doc/db/SqlHelper.html b/Doc/db/SqlHelper.html index 6fee303..4a73fae 100644 --- a/Doc/db/SqlHelper.html +++ b/Doc/db/SqlHelper.html @@ -2,9 +2,9 @@ - + SqlHelper - + diff --git a/Doc/db/package-frame.html b/Doc/db/package-frame.html index ecfeda4..3075f92 100644 --- a/Doc/db/package-frame.html +++ b/Doc/db/package-frame.html @@ -2,9 +2,9 @@ - + db - + diff --git a/Doc/db/package-summary.html b/Doc/db/package-summary.html index c31ba5c..0d26470 100644 --- a/Doc/db/package-summary.html +++ b/Doc/db/package-summary.html @@ -2,9 +2,9 @@ - + db - + diff --git a/Doc/db/package-tree.html b/Doc/db/package-tree.html index a64d06e..03c1e6e 100644 --- a/Doc/db/package-tree.html +++ b/Doc/db/package-tree.html @@ -2,9 +2,9 @@ - + db 类分层结构 - + diff --git a/Doc/deprecated-list.html b/Doc/deprecated-list.html index d68f0d3..4b670cb 100644 --- a/Doc/deprecated-list.html +++ b/Doc/deprecated-list.html @@ -2,9 +2,9 @@ - + 已过时的列表 - + diff --git a/Doc/entity/AnswerNextStep.html b/Doc/entity/AnswerNextStep.html index e1970a8..ed9c66a 100644 --- a/Doc/entity/AnswerNextStep.html +++ b/Doc/entity/AnswerNextStep.html @@ -2,9 +2,9 @@ - + AnswerNextStep - + diff --git a/Doc/entity/Condition.html b/Doc/entity/Condition.html index 52c1ff4..b7fa080 100644 --- a/Doc/entity/Condition.html +++ b/Doc/entity/Condition.html @@ -2,9 +2,9 @@ - + Condition - + @@ -124,8 +124,8 @@ extends java.lang.Object 字段和说明 -java.lang.String -Answer  +java.lang.String[] +answer  java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> @@ -140,18 +140,22 @@ extends java.lang.Object historyPremise  +int +id  + + java.lang.String indexName  - + java.util.HashSet<java.lang.String> keywordSet  - + java.lang.String nextStep  - + int priority  @@ -241,13 +245,13 @@ extends java.lang.Object
    public java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> currentPremise
    - + @@ -271,12 +275,21 @@ extends java.lang.Object - diff --git a/Doc/entity/QuestionKeyWord.html b/Doc/entity/QuestionKeyWord.html index 7157665..8a1442f 100644 --- a/Doc/entity/QuestionKeyWord.html +++ b/Doc/entity/QuestionKeyWord.html @@ -2,9 +2,9 @@ - + QuestionKeyWord - + diff --git a/Doc/entity/UserInfo.html b/Doc/entity/UserInfo.html index 2210f02..114193b 100644 --- a/Doc/entity/UserInfo.html +++ b/Doc/entity/UserInfo.html @@ -2,9 +2,9 @@ - + UserInfo - + @@ -132,6 +132,14 @@ extends java.lang.Object configStr  +java.util.HashMap<java.lang.String,java.lang.String> +extraInfo  + + +java.util.HashMap<java.lang.Integer,java.lang.String> +id2config  + + java.lang.String userName  @@ -203,12 +211,30 @@ extends java.lang.Object - diff --git a/Doc/entity/package-frame.html b/Doc/entity/package-frame.html index a6e46f4..73135b0 100644 --- a/Doc/entity/package-frame.html +++ b/Doc/entity/package-frame.html @@ -2,9 +2,9 @@ - + entity - + diff --git a/Doc/entity/package-summary.html b/Doc/entity/package-summary.html index 937a783..110c94a 100644 --- a/Doc/entity/package-summary.html +++ b/Doc/entity/package-summary.html @@ -2,9 +2,9 @@ - + entity - + diff --git a/Doc/entity/package-tree.html b/Doc/entity/package-tree.html index 5759749..acadbc5 100644 --- a/Doc/entity/package-tree.html +++ b/Doc/entity/package-tree.html @@ -2,9 +2,9 @@ - + entity 类分层结构 - + diff --git a/Doc/help-doc.html b/Doc/help-doc.html index 1d7e63f..f1ef6e1 100644 --- a/Doc/help-doc.html +++ b/Doc/help-doc.html @@ -2,9 +2,9 @@ - + API 帮助 - + diff --git a/Doc/index-files/index-1.html b/Doc/index-files/index-1.html index 1317f1b..2037752 100644 --- a/Doc/index-files/index-1.html +++ b/Doc/index-files/index-1.html @@ -2,9 +2,9 @@ - + A - 索引 - + @@ -68,12 +68,12 @@ -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    A

    -
    Answer - 类 中的变量entity.Condition
    +
    answer - 类 中的变量entity.Condition
     
    AnswerNextStep - entity中的类
    @@ -84,7 +84,7 @@
    AnswerNextStep() - 类 的构造器entity.AnswerNextStep
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-10.html b/Doc/index-files/index-10.html index a49f8ef..7d72d9a 100644 --- a/Doc/index-files/index-10.html +++ b/Doc/index-files/index-10.html @@ -2,9 +2,9 @@ - + K - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    K

    @@ -76,7 +76,7 @@
    keywordSet - 类 中的变量entity.Condition
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-11.html b/Doc/index-files/index-11.html index 7eb6458..4bf9f4c 100644 --- a/Doc/index-files/index-11.html +++ b/Doc/index-files/index-11.html @@ -2,9 +2,9 @@ - + M - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    M

    @@ -78,7 +78,7 @@
    MyFunc() - 类 的构造器processing.MyFunc
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-12.html b/Doc/index-files/index-12.html index 6dd9a1a..404dbd0 100644 --- a/Doc/index-files/index-12.html +++ b/Doc/index-files/index-12.html @@ -2,9 +2,9 @@ - + N - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    N

    @@ -76,7 +76,7 @@
    nextStep - 类 中的变量entity.Condition
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-13.html b/Doc/index-files/index-13.html index 0d8f235..2e179a3 100644 --- a/Doc/index-files/index-13.html +++ b/Doc/index-files/index-13.html @@ -2,9 +2,9 @@ - + P - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    P

    @@ -86,7 +86,7 @@
    ProcessQuestion() - 类 的构造器processing.ProcessQuestion
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-14.html b/Doc/index-files/index-14.html index d2d14d6..961eb39 100644 --- a/Doc/index-files/index-14.html +++ b/Doc/index-files/index-14.html @@ -2,9 +2,9 @@ - + Q - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    Q

    @@ -82,7 +82,7 @@
    QuestionKeyWord() - 类 的构造器entity.QuestionKeyWord
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-15.html b/Doc/index-files/index-15.html index 21879ca..d04712d 100644 --- a/Doc/index-files/index-15.html +++ b/Doc/index-files/index-15.html @@ -2,9 +2,9 @@ - + R - 索引 - + @@ -68,17 +68,19 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    R

    ReloadConfigServlet - servlet中的类
    -
     
    +
    +
    发请求从本地文件夹重新加载某用户的配置文件
    +
    ReloadConfigServlet() - 类 的构造器servlet.ReloadConfigServlet
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-16.html b/Doc/index-files/index-16.html index f2435dd..d66d36f 100644 --- a/Doc/index-files/index-16.html +++ b/Doc/index-files/index-16.html @@ -2,9 +2,9 @@ - + S - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    S

    @@ -96,7 +96,7 @@
    SqlHelper() - 类 的构造器db.SqlHelper
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-17.html b/Doc/index-files/index-17.html index 63524b2..88e725f 100644 --- a/Doc/index-files/index-17.html +++ b/Doc/index-files/index-17.html @@ -2,9 +2,9 @@ - + T - 索引 - + @@ -68,7 +68,7 @@
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    T

    @@ -77,8 +77,10 @@
    将后台返回的数据转成json格式
    +
    toJson(String) - 类 中的静态方法processing.MyFunc
    +
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index-files/index-18.html b/Doc/index-files/index-18.html index 2080925..93deace 100644 --- a/Doc/index-files/index-18.html +++ b/Doc/index-files/index-18.html @@ -2,9 +2,9 @@ - + U - 索引 - + @@ -43,7 +43,7 @@ -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    U

    @@ -81,6 +81,10 @@
    根据chatKey更新chatCache的数据,并修改最后更新时间
    +
    updateConfig(String, String, String, ServletContext) - 类 中的方法servlet.UpdateSingleConfigServlet
    +
     
    +
    updateExtraInfo(String, String, ServletContext) - 类 中的方法servlet.UpdateSingleConfigServlet
    +
     
    updateInfoGetBestMatch(Condition, Map<String, String[]>, Map<String, String>, ServletContext, UserInfo) - 类 中的方法processing.ProcessQuestion
    替换答案中相应的变量{xxx-1},并根据当前信息点更新历史信息点(当前在下一轮变成历史)。
    @@ -91,6 +95,12 @@
    UpdateServlet() - 类 的构造器servlet.UpdateServlet
     
    +
    UpdateSingleConfigServlet - servlet中的类
    +
     
    +
    UpdateSingleConfigServlet() - 类 的构造器servlet.UpdateSingleConfigServlet
    +
     
    +
    userConfigInit(String, ServletContext) - 类 中的静态方法processing.ProcessQuestion
    +
     
    UserInfo - entity中的类
    本地读取的用户配置文件(整个)和提交的用户配置文件的信息经过解析后保存在这里
    @@ -109,7 +119,7 @@
    userName - 类 中的变量entity.UserInfo
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    @@ -131,7 +141,7 @@ -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    B

    @@ -80,7 +80,7 @@
    逐行读取用户配置文件,并保存在userinfo.conditionTable中
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    C

    @@ -102,7 +102,7 @@
    currentPremise - 类 中的变量entity.Condition
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    D

    @@ -83,6 +83,8 @@
     
    DBCPUtils() - 类 的构造器db.DBCPUtils
     
    +
    deleteConfig(String, String, String, ServletContext) - 类 中的方法servlet.UpdateSingleConfigServlet
    +
     
    destroy() - 类 中的方法db.SqlHelper
     
    doGet(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.GetAnswerServlet
    @@ -91,14 +93,20 @@
     
    doGet(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.UpdateServlet
     
    -
    doPost(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.GetAnswerServlet
    +
    doGet(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.UpdateSingleConfigServlet
     
    +
    doPost(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.GetAnswerServlet
    +
    +
    GetAnswerServlet就是处理post请求并返回答案的入口
    +
    doPost(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.ReloadConfigServlet
     
    doPost(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.UpdateServlet
     
    +
    doPost(HttpServletRequest, HttpServletResponse) - 类 中的方法servlet.UpdateSingleConfigServlet
    +
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    E

    entity - 程序包 entity
     
    +
    extraInfo - 类 中的变量entity.UserInfo
    +
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    F

    feature - 类 中的变量entity.Condition
     
    +
    findNewNext(AnswerNextStep, Condition, Map<String, String[]>, Map<String, String>) - 类 中的方法processing.ProcessQuestion
    +
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    G

    @@ -82,9 +82,7 @@
    用迭代器迭代当前信息点中的非空关键字,由conditionName索引到状态表中保存包含conditionName这个条件的列表,并查询状态表中的条件是否满足及其优先级,满足条件且优先级更高就设为bestMatch
    GetAnswerServlet - servlet中的类
    -
    -
    GetAnswerServlet就是处理post请求并返回答案的入口
    -
    +
     
    GetAnswerServlet() - 类 的构造器servlet.GetAnswerServlet
     
    getChatCache(String, ServletContext) - 类 中的静态方法processing.ChatCacheController
    @@ -105,7 +103,7 @@
    getStatus() - 类 中的方法entity.AnswerNextStep
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    H

    @@ -76,7 +76,7 @@
    historyPremise - 类 中的变量entity.Condition
     
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    -
    A B C D E F G H I K M N P Q R S T U  +
    A B C D E F G H I K M N P Q R S T U W 

    I

    +
    id - 类 中的变量entity.Condition
    +
     
    +
    id2config - 类 中的变量entity.UserInfo
    +
     
    indexName - 类 中的变量entity.Condition
     
    +
    insertConfig(String, String, String, ServletContext) - 类 中的方法servlet.UpdateSingleConfigServlet
    +
     
    insertPremise(HashMap<String, HashSet<String>>, String[]) - 类 中的静态方法processing.ProcessQuestion
    通过split方法解析配置文件中的条件部分(如:xihuan=+dota+英雄联盟)
    -A B C D E F G H I K M N P Q R S T U 
    +A B C D E F G H I K M N P Q R S T U W 
    diff --git a/Doc/index.html b/Doc/index.html index fb7799c..ee7c62d 100644 --- a/Doc/index.html +++ b/Doc/index.html @@ -2,7 +2,7 @@ - + 生成的文档 (无标题) diff --git a/Doc/overview-summary.html b/Doc/overview-summary.html index a6febb1..5232c73 100644 --- a/Doc/overview-summary.html +++ b/Doc/overview-summary.html @@ -2,9 +2,9 @@ - + 概览 - + diff --git a/Doc/overview-tree.html b/Doc/overview-tree.html index 24fb3b1..560be42 100644 --- a/Doc/overview-tree.html +++ b/Doc/overview-tree.html @@ -2,9 +2,9 @@ - + 类分层结构 - + @@ -95,6 +95,7 @@
  • servlet.GetAnswerServlet
  • servlet.ReloadConfigServlet
  • servlet.UpdateServlet
  • +
  • servlet.UpdateSingleConfigServlet
  • diff --git a/Doc/processing/ChatCacheController.html b/Doc/processing/ChatCacheController.html index cf5ac02..dc85d82 100644 --- a/Doc/processing/ChatCacheController.html +++ b/Doc/processing/ChatCacheController.html @@ -2,9 +2,9 @@ - + ChatCacheController - + diff --git a/Doc/processing/MyFunc.html b/Doc/processing/MyFunc.html index 1e89f2a..73d29e9 100644 --- a/Doc/processing/MyFunc.html +++ b/Doc/processing/MyFunc.html @@ -2,9 +2,9 @@ - + MyFunc - + @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":9,"i1":9}; +var methods = {"i0":9,"i1":9,"i2":9}; var tabs = {65535:["t0","所有方法"],1:["t1","静态方法"],8:["t4","具体方法"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -157,6 +157,10 @@ extends java.lang.Object
    将后台返回的数据转成json格式
    + +static java.lang.String +toJson(java.lang.String returnStr)  + + + + +
      +
    • +

      toJson

      +
      public static java.lang.String toJson(java.lang.String returnStr)
      +
    • +
    diff --git a/Doc/processing/ProcessQuestion.html b/Doc/processing/ProcessQuestion.html index 82a5d8d..2a64c5d 100644 --- a/Doc/processing/ProcessQuestion.html +++ b/Doc/processing/ProcessQuestion.html @@ -2,9 +2,9 @@ - + ProcessQuestion - + @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":9,"i1":9,"i2":9,"i3":10,"i4":9,"i5":10,"i6":10,"i7":10,"i8":10}; +var methods = {"i0":9,"i1":9,"i2":9,"i3":10,"i4":10,"i5":9,"i6":10,"i7":10,"i8":10,"i9":9,"i10":10}; var tabs = {65535:["t0","所有方法"],1:["t1","静态方法"],2:["t2","实例方法"],8:["t4","具体方法"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -164,6 +164,13 @@ extends java.lang.Object +AnswerNextStep +findNewNext(AnswerNextStep ans, + Condition ansCondition, + java.util.Map<java.lang.String,java.lang.String[]> curInfoPoint, + java.util.Map<java.lang.String,java.lang.String> historyInfoPoint)  + + Condition getAnswer(java.util.Map<java.lang.String,java.lang.String[]> curInfoPoint, java.util.Map<java.lang.String,java.lang.String> historyInfoPoint, @@ -171,14 +178,14 @@ extends java.lang.Object
    用迭代器迭代当前信息点中的非空关键字,由conditionName索引到状态表中保存包含conditionName这个条件的列表,并查询状态表中的条件是否满足及其优先级,满足条件且优先级更高就设为bestMatch
    - + static void insertPremise(java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> premiseMap, java.lang.String[] premisesString)
    通过split方法解析配置文件中的条件部分(如:xihuan=+dota+英雄联盟)
    - + AnswerNextStep postToServer(AnswerNextStep ans, Condition ansCondition, @@ -187,7 +194,7 @@ extends java.lang.Object
    重新post到其他服务器读取数据,并根据这些数据修改返回给用户的信息,可能包括nextStep,和回答文本中的可变参数(用replace方法替换)
    - + boolean satisfy(java.util.Map<java.lang.String,java.lang.String[]> curInfoPoint, java.util.Map<java.lang.String,java.lang.String> historyInfoPoint, @@ -195,7 +202,7 @@ extends java.lang.Object
    根据当前信息点,历史信息点,判断是否满足该condition的条件,match关键字指引擎识别的关键字包含在condition相应的关键词列表中,这里可以根据特征添加其他操作。
    - + AnswerNextStep updateInfoGetBestMatch(Condition ansCondition, java.util.Map<java.lang.String,java.lang.String[]> curInfoPoint, @@ -205,7 +212,12 @@ extends java.lang.Object
    替换答案中相应的变量{xxx-1},并根据当前信息点更新历史信息点(当前在下一轮变成历史)。
    - + +static void +userConfigInit(java.lang.String userName, + javax.servlet.ServletContext context)  + + UserInfo userInfoQuery(java.lang.String bot_name, javax.servlet.ServletContext context) @@ -271,6 +283,21 @@ extends java.lang.Object + + + +
      +
    • +

      userConfigInit

      +
      public static void userConfigInit(java.lang.String userName,
      +                                  javax.servlet.ServletContext context)
      +                           throws java.io.IOException
      +
      +
      抛出:
      +
      java.io.IOException
      +
      +
    • +
    @@ -410,7 +437,7 @@ extends java.lang.Object -
      + + + + +
        +
      • +

        findNewNext

        +
        public AnswerNextStep findNewNext(AnswerNextStep ans,
        +                                  Condition ansCondition,
        +                                  java.util.Map<java.lang.String,java.lang.String[]> curInfoPoint,
        +                                  java.util.Map<java.lang.String,java.lang.String> historyInfoPoint)
        +
      • +
    diff --git a/Doc/processing/package-frame.html b/Doc/processing/package-frame.html index c16e527..951f6b8 100644 --- a/Doc/processing/package-frame.html +++ b/Doc/processing/package-frame.html @@ -2,9 +2,9 @@ - + processing - + diff --git a/Doc/processing/package-summary.html b/Doc/processing/package-summary.html index 562e148..73d1f9b 100644 --- a/Doc/processing/package-summary.html +++ b/Doc/processing/package-summary.html @@ -2,9 +2,9 @@ - + processing - + diff --git a/Doc/processing/package-tree.html b/Doc/processing/package-tree.html index ff04065..1608f4d 100644 --- a/Doc/processing/package-tree.html +++ b/Doc/processing/package-tree.html @@ -2,9 +2,9 @@ - + processing 类分层结构 - + diff --git a/Doc/serialized-form.html b/Doc/serialized-form.html index be5365b..87cdf33 100644 --- a/Doc/serialized-form.html +++ b/Doc/serialized-form.html @@ -2,9 +2,9 @@ - + 序列化表格 - + @@ -91,6 +91,11 @@

    类servlet.UpdateServlet扩展javax.servlet.http.HttpServlet实现可序列化

    +
  • + + +

    类servlet.UpdateSingleConfigServlet扩展javax.servlet.http.HttpServlet实现可序列化

    +
  • diff --git a/Doc/servlet/GetAnswerServlet.html b/Doc/servlet/GetAnswerServlet.html index f41b446..47628e8 100644 --- a/Doc/servlet/GetAnswerServlet.html +++ b/Doc/servlet/GetAnswerServlet.html @@ -2,9 +2,9 @@ - + GetAnswerServlet - + @@ -126,7 +126,6 @@ var activeTableTab = "activeTableTab"; urlPatterns={"/test","/test/"}) public class GetAnswerServlet extends javax.servlet.http.HttpServlet -
    GetAnswerServlet就是处理post请求并返回答案的入口
    另请参阅:
    序列化表格
    @@ -174,7 +173,9 @@ extends javax.servlet.http.HttpServlet protected void doPost(javax.servlet.http.HttpServletRequest request, - javax.servlet.http.HttpServletResponse response)  + javax.servlet.http.HttpServletResponse response)
    +
    GetAnswerServlet就是处理post请求并返回答案的入口
    +
      @@ -239,6 +240,7 @@ extends javax.servlet.http.HttpServlet javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException +
      GetAnswerServlet就是处理post请求并返回答案的入口
      覆盖:
      doPost 在类中 javax.servlet.http.HttpServlet
      diff --git a/Doc/servlet/ReloadConfigServlet.html b/Doc/servlet/ReloadConfigServlet.html index c3d4810..6e66851 100644 --- a/Doc/servlet/ReloadConfigServlet.html +++ b/Doc/servlet/ReloadConfigServlet.html @@ -2,9 +2,9 @@ - + ReloadConfigServlet - + @@ -126,6 +126,7 @@ var activeTableTab = "activeTableTab"; urlPatterns={"/reload","/reload/"}) public class ReloadConfigServlet extends javax.servlet.http.HttpServlet +
      发请求从本地文件夹重新加载某用户的配置文件
      另请参阅:
      序列化表格
      diff --git a/Doc/servlet/UpdateServlet.html b/Doc/servlet/UpdateServlet.html index 0b04668..247438f 100644 --- a/Doc/servlet/UpdateServlet.html +++ b/Doc/servlet/UpdateServlet.html @@ -2,9 +2,9 @@ - + UpdateServlet - + @@ -49,7 +49,7 @@ var activeTableTab = "activeTableTab";
    diff --git a/src/entity/UserInfo.java b/src/entity/UserInfo.java index 3c8e544..6f604a3 100644 --- a/src/entity/UserInfo.java +++ b/src/entity/UserInfo.java @@ -27,4 +27,6 @@ public class UserInfo { public HashMap extraInfo; public HashMap id2config; + + } diff --git a/src/processing/ChatCacheController.java b/src/processing/ChatCacheController.java index d87f238..4074a84 100644 --- a/src/processing/ChatCacheController.java +++ b/src/processing/ChatCacheController.java @@ -1,6 +1,7 @@ package processing; import javax.servlet.ServletContext; +import java.io.*; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -70,4 +71,58 @@ public class ChatCacheController { keyCache.put(curInfoPoint.get("chat_key")[0],historyInfoPoint); context.setAttribute("chatCache",keyCache); } + + public static boolean saveChatCache(String userName, HashMap infoPoints) throws IOException { + String fileDir = System.getProperty("user.dir")+"/ChatCache"; + String key; + boolean saveFlag = true; + try { + File dir = new File(fileDir); + if (!dir.exists()) + dir.mkdir(); + + File file = new File(fileDir + "/" + userName + ".txt"); + FileWriter fw = new FileWriter(file); + + Iterator infoIter = infoPoints.keySet().iterator(); + while (infoIter.hasNext()) { + key = infoIter.next(); + fw.write(key + "-----" + infoPoints.get(key) + "\n"); + } + fw.close(); + + }catch (Exception e){ + saveFlag = false; + } + + return saveFlag; + } + + public static boolean loadChatCache(String userName, ServletContext context){ + String fileDir = System.getProperty("user.dir")+"/ChatCache"; + String line,pair[]; + Map infoPoints = new HashMap(); + try{ + File file = new File(fileDir + "/" + userName + ".txt"); + if(!file.exists()) { + return false; + }else { + FileReader fr = new FileReader(file); + BufferedReader br = new BufferedReader(fr); + while ((line = br.readLine()) != null){ + pair = line.trim().split("-----"); + infoPoints.put(pair[0], pair[1]); + } + // context.setAttribute(userName, ); + + fr.close(); + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + return true; + } } diff --git a/src/processing/MyFunc.java b/src/processing/MyFunc.java index a6bbf18..50b3433 100644 --- a/src/processing/MyFunc.java +++ b/src/processing/MyFunc.java @@ -3,7 +3,12 @@ package processing; import entity.AnswerNextStep; import net.sf.json.JSONObject; +import java.io.FileWriter; import java.io.UnsupportedEncodingException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; public class MyFunc { @@ -37,4 +42,33 @@ public class MyFunc { } return s; } + + public static long transferToMillisecond(String keyword) throws ParseException { + long time; + + System.out.println(keyword); + + String timeSeries[] = {"时", "分", "秒"}; + for(String f : timeSeries){ + if (!keyword.contains(f)) + keyword += "0" + f; + } + + SimpleDateFormat format = new SimpleDateFormat("yyyy年M月d日H时m分s秒"); + time = format.parse(keyword).getTime(); + + return time; + } + public static String transferToStandardTime(long time) throws ParseException { + + SimpleDateFormat format = new SimpleDateFormat("yyyy年M月d日H时m分s秒"); + + Date date = new Date(time); + return format.format(date); + + } + + + + } diff --git a/src/processing/ProcessQuestion.java b/src/processing/ProcessQuestion.java index 6d760fd..4f6fa67 100644 --- a/src/processing/ProcessQuestion.java +++ b/src/processing/ProcessQuestion.java @@ -4,18 +4,23 @@ import entity.AnswerNextStep; import entity.Condition; import entity.UserInfo; import net.sf.json.JSONObject; +import org.apache.commons.lang.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; +import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import javax.servlet.ServletContext; import java.io.*; import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; @@ -105,7 +110,7 @@ public class ProcessQuestion { public static Condition buildCondition(Condition condition,String line){ //System.out.println("build condition"); //System.out.println("xxxxx"+line); - String feature,element[],pair[],next[],cur_premises[],history_premises[],premises[]; + String feature,element[],pair[],next[],cur_premises[],history_premises[],premises[],firstCnditionName; line = line.split("---")[0]; @@ -138,11 +143,11 @@ public class ProcessQuestion { condition.indexName.add(pair[0]); } */ - if(cur_premises[0].equals(" ")) + firstCnditionName = cur_premises[0]; + if(firstCnditionName.equals(" ")) condition.indexName = "emptySet"; else - condition.indexName = cur_premises[0].split("=")[0]; - + condition.indexName = firstCnditionName.split("=")[0].split("::")[0]; return condition; } @@ -234,6 +239,66 @@ public class ProcessQuestion { return userinfo; } + public boolean infoPointPreprocessing(Map curInfoPoint, Map historyInfoPoint, UserInfo userinfo, StringBuffer curInfoRecord){ + + String return_str = ""; + boolean debugFlag = false; + + //输出所有actionName的值 + Iterator iit = curInfoPoint.keySet().iterator(); + while(iit.hasNext()){ + String k = iit.next(); + // + System.out.print(k+": "); + + if(k.equals("debug_mode")) + debugFlag = true; + + String values[] = curInfoPoint.get(k); + + for(String v:values) { + System.out.print(v + " "); + } + System.out.println(); + } + + //如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown + iit = curInfoPoint.keySet().iterator(); + boolean unknown_flag = true; + while(iit.hasNext()){ + String k = iit.next(); + String values[] = curInfoPoint.get(k); + if(k.equals("chat_key") || k.equals("action_name") || k.equals("bot_name") || k.equals("emptySet")) + continue; + if(values != null && !values[0].equals("")) { + unknown_flag = false; + break; + } + } + + String currentAction = ""; + if(historyInfoPoint.containsKey("currentAction")) + currentAction = historyInfoPoint.get("currentAction"); + else if(userinfo.extraInfo.containsKey("activeAction")) { + currentAction = userinfo.extraInfo.get("activeAction"); + historyInfoPoint.put("currentAction", currentAction); + }else + currentAction = ""; + + + curInfoPoint.put("emptySet", new String[]{" ",}); + if(historyInfoPoint.get("activeList") == null){ + historyInfoPoint.put("activeList", currentAction); + } + + if(unknown_flag && !currentAction.equals("")){ + String i[] = {"unknown",}; + curInfoPoint.put(currentAction,i); + } + + return debugFlag; + } + /** * 用迭代器迭代当前信息点中的非空关键字,由conditionName索引到状态表中保存包含conditionName这个条件的列表,并查询状态表中的条件是否满足及其优先级,满足条件且优先级更高就设为bestMatch @@ -262,7 +327,7 @@ public class ProcessQuestion { if (keyword != null && conditionTable.get(conditionName) != null) { conditionList = conditionTable.get(conditionName); for (Condition condition : conditionList) { - if(condition.status.equals("waiting") && satisfy(curInfoPoint, historyInfoPoint, condition)){ + if(condition.status.equals("waiting") && conditionSatisfy(curInfoPoint, historyInfoPoint, condition)){ if(condition.feature.contains("activate")){ activateConfig(extraActivatedConfig, curInfoPoint.get("bot_name")[0], condition.priority, condition.nextStep, context); @@ -277,7 +342,7 @@ public class ProcessQuestion { while(extraConfigIter.hasNext()){ configId = extraConfigIter.next(); extraCondition = extraActivatedConfig.get(configId); - if(extraCondition.activePriority > bestMatch.activePriority && satisfy(curInfoPoint, historyInfoPoint, extraCondition)){ + if(extraCondition.activePriority > bestMatch.activePriority && conditionSatisfy(curInfoPoint, historyInfoPoint, extraCondition)){ bestMatch = extraCondition; } } @@ -293,46 +358,164 @@ public class ProcessQuestion { * @param condition 配置文件(状态表)的一行 * @return 满足条件就为True,不满足就为False */ - public boolean satisfy(Map curInfoPoint,Map historyInfoPoint,Condition condition){ + public boolean conditionSatisfy(Map curInfoPoint,Map historyInfoPoint,Condition condition){ boolean flag = true; - String actionName,keywords[],keyword; + String actionName,keywords[],keyword,comparePair[],cmpType,premiseStr; HashSet keywordSet = null; if(condition.feature.contains("match")){ Iterator it = condition.currentPremise.keySet().iterator(); while (flag && it.hasNext()) { - actionName = it.next(); - + premiseStr = it.next(); + comparePair = premiseStr.split("::"); + actionName = comparePair[0]; keywords = curInfoPoint.get(actionName); - - if (keywords == null){ + if (keywords == null || keywords[0].equals("")) { flag = false; break; } keyword = keywords[0]; - keywordSet = condition.currentPremise.get(actionName); - if (!keywordSet.contains(keyword)) { + if (comparePair.length == 1) + cmpType = "match"; + else + cmpType = comparePair[1]; + + keywordSet = condition.currentPremise.get(premiseStr); + if(!premiseSatisfy(keyword, cmpType, keywordSet)) flag = false; - } } it = condition.historyPremise.keySet().iterator(); while (flag && it.hasNext()) { - if (historyInfoPoint == null) { + premiseStr = it.next(); + comparePair = premiseStr.split("::"); + actionName = comparePair[0]; + keyword = historyInfoPoint.get(actionName); + + if(keyword == null || keyword.equals("")){ flag = false; break; } - actionName = it.next(); - keyword = historyInfoPoint.get(actionName); - keywordSet = condition.historyPremise.get(actionName); + + if (comparePair.length == 1) + cmpType = "match"; + else + cmpType = comparePair[1]; + + keywordSet = condition.historyPremise.get(premiseStr); + if(!premiseSatisfy(keyword, cmpType, keywordSet)) + flag = false; + } + } + + return flag; + + } + + public boolean premiseSatisfy(String keyword, String cmpType, HashSet keywordSet){ + boolean flag = true; + + + try { + if (cmpType.equals("match")) { if (!keywordSet.contains(keyword)) { flag = false; } + if (flag == false && keyword.contains(":")) { + String ks[] = keyword.split(":"); + for (String k : ks) { + if (keywordSet.contains(k)) + flag = true; + } + } + + } else if (cmpType.equals("numberBigger") && StringUtils.isNumeric(keyword)) { + int candidateA = 0; + int candidateB = 0; + candidateA = Integer.parseInt(keyword); + for(String k: keywordSet){ + if(!k.equals("")) { + candidateB = Integer.parseInt(k); + break; + } + } + flag = candidateA > candidateB; + + } else if (cmpType.equals("numberBiggerOrEqual") && StringUtils.isNumeric(keyword)) { + int candidateA = 0; + int candidateB = 0; + candidateA = Integer.parseInt(keyword); + for(String k: keywordSet){ + if(!k.equals("")) { + candidateB = Integer.parseInt(k); + break; + } + } + flag = candidateA >= candidateB; + + } else if (cmpType.equals("numberSmaller") && StringUtils.isNumeric(keyword)) { + int candidateA = 0; + int candidateB = 0; + candidateA = Integer.parseInt(keyword); + for(String k: keywordSet){ + if(!k.equals("")) { + candidateB = Integer.parseInt(k); + break; + } + } + flag = candidateA < candidateB; + + } else if (cmpType.equals("numberSmallerOrEqual") && StringUtils.isNumeric(keyword)) { + int candidateA = 0; + int candidateB = 0; + candidateA = Integer.parseInt(keyword); + for(String k: keywordSet){ + if(!k.equals("")) { + candidateB = Integer.parseInt(k); + break; + } + } + flag = candidateA <= candidateB; + + } else if (cmpType.equals("timeEarly")){ + long candidateA,candidateB = 0; + System.out.println("1这里是:"+keyword); + candidateA = MyFunc.transferToMillisecond(keyword); + + for(String k: keywordSet){ + if(!k.equals("")) { + candidateB = MyFunc.transferToMillisecond(k); + break; + } + } + flag = candidateA < candidateB; + + } else if (cmpType.equals("timeLater")){ + long candidateA,candidateB = 0; + System.out.println("1这里是:"+keyword); + candidateA = MyFunc.transferToMillisecond(keyword); + + for(String k: keywordSet){ + if(!k.equals("")) { + candidateB = MyFunc.transferToMillisecond(k); + break; + } + } + flag = candidateA > candidateB; + + } else if (cmpType.equals("any")){ + if(keyword.equals("")) //当前信息点中的关键词不为空即满足条件,为空则不满足 + flag = false; + + }else { + flag = false; } + }catch (Exception e){ + e.printStackTrace(); + flag = false; } return flag; - } /** @@ -341,7 +524,7 @@ public class ProcessQuestion { * @param historyInfoPoint 历史信息点,即引擎前几轮识别的conditionName和关键字 * @return 返回给引擎的数据 */ - public AnswerNextStep updateInfoGetBestMatch(Condition ansCondition,Map curInfoPoint,Map historyInfoPoint,ServletContext context,UserInfo userinfo) throws IOException { + public AnswerNextStep getBestMatch(Condition ansCondition,Map curInfoPoint,Map historyInfoPoint,ServletContext context,UserInfo userinfo) throws IOException, ParseException { Iterator it = curInfoPoint.keySet().iterator(); String actionName; @@ -353,10 +536,29 @@ public class ProcessQuestion { ans.setAnswer(ansCondition.answer[randNum]); //System.out.println(ans.getAnswer()); System.out.println("feature="+ansCondition.feature); + + //post关键字 if(ansCondition.feature.contains("post")){ ans = postToServer(ans,ansCondition,curInfoPoint,historyInfoPoint); + + //nextNext关键字 }else if(ansCondition.feature.contains("newNext")){ ans = findNewNext(ans, ansCondition, curInfoPoint, historyInfoPoint); + }else if (ansCondition.feature.contains("return-1")){ + String activeList[] = historyInfoPoint.get("activeList").split("\\|"); + if (activeList.length == 1) + ans.setNext("nextStep=" + activeList[activeList.length - 1]); + else { + ans.setNext("nextStep=" + activeList[activeList.length - 2]); + } + }else if (ansCondition.feature.contains("return-0")){ + String activeList[] = historyInfoPoint.get("activeList").split("\\|"); + ans.setNext("nextStep=" + activeList[activeList.length - 1]); + } + + //updateKnowledge关键字 + if (ansCondition.feature.contains("updateKnowledge")){ + updateKnowledge(ansCondition, historyInfoPoint); } if(ans.getNext().equals("")){ @@ -364,17 +566,8 @@ public class ProcessQuestion { } - //保存即将跳转的action名以供下一轮使用,nextStep的结构是nextStep=xxx - historyInfoPoint.put("currentAction",ans.getNext().split("=")[1]); - historyInfoPoint.put("activeList", historyInfoPoint.get("activeList") + "|" + ansCondition.nextStep); - - - //将当前信息点更新至历史信息点,并且替换答案中的相应变量,变量结构为{xxx-1}或者{xxx-2} try { - String keyword1, keyword2; - if (historyInfoPoint == null) - historyInfoPoint = new HashMap(); while (it.hasNext()) { actionName = it.next(); keyword1 = curInfoPoint.get(actionName)[0]; @@ -383,14 +576,41 @@ public class ProcessQuestion { ans.setAnswer(ans.getAnswer().replace("{" + actionName + "-2}", keyword2)); } if (keyword1 != null) { - if (keyword2 == null) - historyInfoPoint.put(actionName, keyword1); - else if (keyword2 != null && !keyword1.equals("")) - historyInfoPoint.put(actionName, keyword1); ans.setAnswer(ans.getAnswer().replace("{" + actionName + "-1}", keyword1));//这里 } } + }catch(Exception e){ + e.printStackTrace(); + } + + return ans; + } + + public void infoTransition(Map curInfoPoint,Map historyInfoPoint, AnswerNextStep ans, ServletContext context){ + //将当前信息点更新至历史信息点,并且替换答案中的相应变量,变量结构为{xxx-1}或者{xxx-2} + Iterator it = curInfoPoint.keySet().iterator(); + String actionName; + String next = ans.getNext().split("=")[1]; + + //保存即将跳转的action名以供下一轮使用,nextStep的结构是nextStep=xxx + historyInfoPoint.put("currentAction",next); + historyInfoPoint.put("activeList", historyInfoPoint.get("activeList") + "|" + next); + + try { + + String keyword1, keyword2; + while (it.hasNext()) { + actionName = it.next(); + keyword1 = curInfoPoint.get(actionName)[0]; + keyword2 = historyInfoPoint.get(actionName); + if (keyword2 == null) + historyInfoPoint.put(actionName, keyword1); + else if (keyword2 != null && !keyword1.equals("")) + historyInfoPoint.put(actionName, keyword1); + + } + ChatCacheController.updateChatCache4Insert(curInfoPoint, historyInfoPoint, context); //context.setAttribute("chat_key+"+userinfo.userName,historyInfoPoint); @@ -399,43 +619,124 @@ public class ProcessQuestion { }catch(Exception e){ e.printStackTrace(); } + } - return ans; + + + public void appendDebugInfo(AnswerNextStep ans,Map curInfoPoint,Map historyInfoPoint,ServletContext context) { + Iterator it = null; + String key, values[], value; + + HashSet skipSet = new HashSet(){ + { + add("activeList"); + add("currentAction"); + add("lastUpdateTime"); + add("bot_name"); + add("action_name"); + add("chat_key"); + } + }; + + it = curInfoPoint.keySet().iterator(); + String debugInfo = ""; + debugInfo += "(识别:"; + while(it.hasNext()) { + key = it.next(); + values = curInfoPoint.get(key); + if (values != null && !values[0].equals(" ") && !values[0].equals("") && !skipSet.contains(key)) + debugInfo += (" " + key + ":" + values[0] + " "); + } + debugInfo += ")(已知:"; + it = historyInfoPoint.keySet().iterator(); + while(it.hasNext()){ + + key = it.next(); + value = historyInfoPoint.get(key); + if(value != null && !value.equals(" ") && !value.equals("") && !skipSet.contains(key)) + debugInfo += (" " + key + ":" + value + " "); + + } + ans.setAnswer( debugInfo + ")" + ans.getAnswer()); } + /** * 重新post到其他服务器读取数据,并根据这些数据修改返回给用户的信息,可能包括nextStep,和回答文本中的可变参数(用replace方法替换) * @param ans 返回给用户的数据 * @param ansCondition 满足条件最多的condition(配置文件的某一行) */ public AnswerNextStep postToServer(AnswerNextStep ans, Condition ansCondition, Map curInfoPoint,Map historyInfoPoint) throws IOException { - String url = null,features[] = ansCondition.feature.trim().split(","),elem[], key; + String url = null,features[] = ansCondition.feature.trim().split(","),elem[], subElem[], key, postType = "all"; + Map infoMap = new HashMap(); + List pairList = new ArrayList(); + Iterator k_iter = null; + System.out.println("there"); for(String feature:features){ elem = feature.split("\\("); - if(elem[0].equals("post")){ + if(elem[0].contains("post")){ url = elem[elem.length-1]; url = url.substring(0,url.length()-1); - break; + + subElem = elem[0].split("::"); + if(subElem.length == 1) + postType = "all"; + else + postType = subElem[1]; + } + } + + if(postType.equals("all")){ + + k_iter = curInfoPoint.keySet().iterator(); + while(k_iter.hasNext()){ + key = k_iter.next(); + if(curInfoPoint.get(key)[0] != "") + //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); + pairList.add(new BasicNameValuePair(key , curInfoPoint.get(key)[0])); + } + k_iter = historyInfoPoint.keySet().iterator(); + while(k_iter.hasNext()){ + key = k_iter.next(); + if(historyInfoPoint.get(key) != "") + //infoMap.put(key + "_his", historyInfoPoint.get(key)); + pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); + } + + }else if(postType.equals("term")){ + + k_iter = ansCondition.currentPremise.keySet().iterator(); + while(k_iter.hasNext()){ + key = k_iter.next().split("::")[0]; + if(curInfoPoint.get(key)[0] != "") + pairList.add(new BasicNameValuePair(key , curInfoPoint.get(key)[0])); + + //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); + } + k_iter = ansCondition.historyPremise.keySet().iterator(); + while(k_iter.hasNext()){ + key = k_iter.next().split("::")[0]; + if(historyInfoPoint.get(key) != "") + pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); + //infoMap.put(key + "_his", historyInfoPoint.get(key)); + } + } HttpPost httpPost = new HttpPost(url); CloseableHttpClient client = HttpClients.createDefault(); String respContent = null; String keyName = null; - Map infoMap = new HashMap(); - Iterator k_iter = curInfoPoint.keySet().iterator(); - while(k_iter.hasNext()){ - key = k_iter.next(); - infoMap.put(key, curInfoPoint.get(key)[0]); - } - + /* JSONObject jsonParam = new JSONObject(); jsonParam.put("curInfoPoint", infoMap); jsonParam.put("historyInfoPoint", historyInfoPoint); StringEntity entity = new StringEntity(jsonParam.toString(),"utf-8");//解决中文乱码问题 entity.setContentEncoding("UTF-8"); + */ + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "utf-8"); entity.setContentType("application/x-www-form-urlencoded"); httpPost.setEntity(entity); @@ -457,12 +758,12 @@ public class ProcessQuestion { } } } else { - ans.setAnswer("api有误!"); + ans.setAnswer("api处理出错!"); } }catch (Exception e){ e.printStackTrace(); - - ans.setNext("提交失败了"); + + ans.setNext("提交失败了:"+url); } return ans; @@ -515,6 +816,70 @@ public class ProcessQuestion { } + public void updateKnowledge(Condition condition, Map historyInfoPoint) throws ParseException { + String features[] = condition.feature.split(","); + String pair[],keyword; + for(String feature: features){ + if (feature.contains("updateKnowledge")){ + for (String knowledge: feature.split("-<-")){ + pair = knowledge.split(":"); + System.out.println("knowledge"+knowledge); + System.out.println(pair.length); + keyword = historyInfoPoint.get(pair[0]); + + if(pair.length > 1) { + try { + if (pair[1].startsWith("+")) { + if(keyword == null || keyword.equals("")) + keyword = "0"; + if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { + System.out.println("这里是keyword:" + keyword); + long time = MyFunc.transferToMillisecond(keyword); + int offset = Integer.parseInt(pair[1].substring(1)); + pair[1] = MyFunc.transferToStandardTime(time + (1000 * offset)); + }else if (StringUtils.isNumeric(keyword)){ + int number = Integer.parseInt(keyword); + int offset = Integer.parseInt(pair[1].substring(1)); + pair[1] = String.valueOf(number + offset); + System.out.println("加一:"+pair[1]); + } + + } else if (pair[1].startsWith("-")) { + if(keyword == null || keyword.equals("")) + keyword = "0"; + if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { + System.out.println("这里是keyword:" + keyword); + long time = MyFunc.transferToMillisecond(keyword); + int offset = Integer.parseInt(pair[1].substring(1)); + pair[1] = MyFunc.transferToStandardTime(time - (1000 * offset)); + System.out.println("改变后:"+ pair[1]); + }else if (StringUtils.isNumeric(keyword)){ + int number = Integer.parseInt(keyword); + int offset = Integer.parseInt(pair[1].substring(1)); + pair[1] = String.valueOf(number - offset); + } + } else if (pair[1].startsWith("str+")) { + if(keyword == null || keyword.equals("")) + keyword = ""; + pair[1] = keyword + pair[1].substring(4); + } else if (pair[1].startsWith("str-")) { + if(keyword == null || keyword.equals("")) + keyword = ""; + System.out.println("aa"); + pair[1] = keyword.replace(pair[1].substring(4), ""); + System.out.println(pair[1]); + } + }catch (Exception e){ + e.printStackTrace(); + continue; + } + historyInfoPoint.put(pair[0], pair[1]); + } + } + } + } + } + public void activateConfig(HashMap extraActivatedConfig, String userName, int basePriority, String activateList, ServletContext context){ UserInfo userinfo = (UserInfo) context.getAttribute(userName); String configStr = ""; diff --git a/src/servlet/GetAnswerServlet.java b/src/servlet/GetAnswerServlet.java index 6a99ba2..b49ff3d 100644 --- a/src/servlet/GetAnswerServlet.java +++ b/src/servlet/GetAnswerServlet.java @@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.sql.SQLException; +import java.text.ParseException; import java.util.*; @@ -35,8 +36,11 @@ public class GetAnswerServlet extends HttpServlet { ProcessQuestion process = new ProcessQuestion(); OutputStream out = response.getOutputStream(); ServletContext context = this.getServletContext(); + boolean debugFlag = false; //获得用户历史信息 historyInfoPoint = ChatCacheController.getChatCache(chatKey,context); + StringBuffer curInfoRecord = new StringBuffer(); + StringBuffer hisInfoRecord = new StringBuffer(); @@ -61,58 +65,10 @@ public class GetAnswerServlet extends HttpServlet { historyInfoPoint.put(k,""); } } + //信息点预处理 + debugFlag = process.infoPointPreprocessing(curInfoPoint, historyInfoPoint, userinfo, curInfoRecord); - - //输出所有actionName的值 - Iterator iit = curInfoPoint.keySet().iterator(); - while(iit.hasNext()){ - String k = iit.next(); - // - System.out.print(k+": "); - - String values[] = curInfoPoint.get(k); - if(values != null && !values[0].equals(" ") && !values[0].equals("") && !k.equals("chat_key") && !k.equals("action_name") && !k.equals("bot_name")) - //return_str = return_str + " " + k + ":" + values[0] + " "; - for(String v:values) { - System.out.print(v + " "); - } - System.out.println(); - } - - //如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown - iit = curInfoPoint.keySet().iterator(); - boolean unknown_flag = true; - while(iit.hasNext()){ - String k = iit.next(); - String values[] = curInfoPoint.get(k); - if(k.equals("chat_key") || k.equals("action_name") || k.equals("bot_name") || k.equals("emptySet")) - continue; - if(values != null && !values[0].equals("")) { - unknown_flag = false; - break; - } - } - String currentAction = ""; - if(historyInfoPoint.containsKey("currentAction")) - currentAction = historyInfoPoint.get("currentAction"); - else if(userinfo.extraInfo.containsKey("activeAction")) { - currentAction = userinfo.extraInfo.get("activeAction"); - historyInfoPoint.put("currentAction", currentAction); - }else - currentAction = ""; - - curInfoPoint.put("emptySet", new String[]{" ",}); - if(historyInfoPoint.get("activeList") == null){ - historyInfoPoint.put("activeList", currentAction); - } - - - if(unknown_flag && !currentAction.equals("")){ - String i[] = {"unknown",}; - curInfoPoint.put(currentAction,i); - } - /*得到答案更新历史信息点&生成答案,,清楚超时chatkey_key,生成更新数据库,转成json,输出*/ //process.removeTimeoutChatkey(context); //System.out.println(userinfo.conditionTable); //测试 @@ -120,10 +76,11 @@ public class GetAnswerServlet extends HttpServlet { if (state.equals("") && ansCondition.priority == -1) state = "我不理解,"; if (state.equals("")) { - bestMatch = process.updateInfoGetBestMatch(ansCondition, curInfoPoint, historyInfoPoint, context, userinfo); - //process.updateDB(kw); - //System.out.println("Current time:" + System.currentTimeMillis()); - + try { + bestMatch = process.getBestMatch(ansCondition, curInfoPoint, historyInfoPoint, context, userinfo); + } catch (ParseException e) { + e.printStackTrace(); + } //清理超时的用户数据 if (context.getAttribute("cacheUpdateTime") == null) context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); @@ -131,11 +88,19 @@ public class GetAnswerServlet extends HttpServlet { ChatCacheController.updateChatCache4Delete(context); context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); } - bestMatch.setAnswer(" \n" + return_str + "\n " + bestMatch.getAnswer()); + //bestMatch.setAnswer(" \n" + return_str + "\n " + bestMatch.getAnswer()); }else{ - bestMatch = new AnswerNextStep(0,state,"nextStep=" + historyInfoPoint.get("currentAction")); + bestMatch = new AnswerNextStep(0," \n" + return_str + "\n " +state,"nextStep=" + historyInfoPoint.get("currentAction")); } + + if(debugFlag) { + process.appendDebugInfo(bestMatch, curInfoPoint, historyInfoPoint, context); + } + + process.infoTransition(curInfoPoint, historyInfoPoint, bestMatch, context); + + ansJ = MyFunc.toJson(bestMatch); System.out.println(ansJ); out.write(ansJ.getBytes()); diff --git a/src/servlet/UpdateSingleConfigServlet.java b/src/servlet/UpdateSingleConfigServlet.java index 761fc8c..2c1932b 100644 --- a/src/servlet/UpdateSingleConfigServlet.java +++ b/src/servlet/UpdateSingleConfigServlet.java @@ -27,30 +27,43 @@ public class UpdateSingleConfigServlet extends HttpServlet { String data = request.getParameter("configData"); System.out.println("userName:"+userName + " " + "type:" + processType + " " + "configId:" + "configId:" + configId + " " + "configData:" + data); - switch(processType){ - case "insert_config": - insertConfig(userName, configId, data, context); - break; - case "update_config": - deleteConfig(userName, configId, data, context); - insertConfig(userName, configId, data, context); - break; - case "delete_config": - deleteConfig(userName, configId, data, context); - break; - case "extra_info": - updateExtraInfo(userName, data, context); - break; - case "batch_update": - batchUpdate(userName, data, context); + if(context.getAttribute(userName) != null) { + System.out.println("11"); + switch (processType) { + case "insert_config": + insertConfig(userName, configId, data, context); + break; + case "update_config": + deleteConfig(userName, configId, data, context); + insertConfig(userName, configId, data, context); + break; + case "delete_config": + deleteConfig(userName, configId, data, context); + break; + case "extra_info": + updateExtraInfo(userName, data, context); + break; + case "batch_update": + batchUpdate(userName, data, context); + } + writeConfig(userName, context); + response.setStatus(200); + + }else if(processType.equals("batch_update")){ + System.out.println("22"); + batchUpdate(userName, data, context); + writeConfig(userName, context); + response.setStatus(200); + }else{ + System.out.println("33"); + response.setStatus(111); } - writeConfig(userName, context); + response.setCharacterEncoding("utf-8"); response.setContentType( "text/plain"); PrintWriter out = response.getWriter(); - System.out.println("cc"); out.write("success"); out.flush(); out.close(); @@ -137,14 +150,11 @@ public class UpdateSingleConfigServlet extends HttpServlet { } UserInfo userinfo = (UserInfo) context.getAttribute(userName); if (userinfo.id2config.containsKey(Integer.parseInt(configId))) { - String currentPremises[] = userinfo.id2config.get(Integer.parseInt(configId)).split("\\|")[0].split(","); + Condition oldCondition = new Condition(); + oldCondition = process.buildCondition(oldCondition, userinfo.id2config.get(Integer.parseInt(configId))); - - for (String premise : currentPremises) { - String conditionName = premise.split("=")[0]; - if (userinfo.conditionTable.get(conditionName) == null) { - continue; - } + String conditionName = oldCondition.indexName; + if (userinfo.conditionTable.get(conditionName) != null) { List conditionList = userinfo.conditionTable.get(conditionName); Iterator condIter = userinfo.conditionTable.get(conditionName).iterator(); while (condIter.hasNext()) { @@ -154,8 +164,12 @@ public class UpdateSingleConfigServlet extends HttpServlet { } } } + userinfo.id2config.remove(Integer.parseInt(configId)); + } else{ + System.out.println("未找到要删除的configId"); } + return true; } @@ -176,7 +190,6 @@ public class UpdateSingleConfigServlet extends HttpServlet { public String writeConfig(String userName, ServletContext context) throws IOException { - System.out.println("write"); UserInfo userinfo = (UserInfo) context.getAttribute(userName); String CONFIG_DIR = System.getProperty("user.dir")+"/config", configText; context.setAttribute(userName,userinfo); diff --git a/web/update.html b/web/update.html index adfc4b1..2d00dde 100644 --- a/web/update.html +++ b/web/update.html @@ -1,7 +1,7 @@ - 配置文件 + 配置文件 v2.2.4 @@ -13,8 +13,9 @@

    用户名:

    -

    内 容:

    -

     

    +

    内 容:

    +

     

    +

     

    @@ -53,6 +54,41 @@ }); } + function batch_update() { + var text = document.getElementById("config_string").value; + var macroMap = new Map(); + + if (document.getElementById("txtUserName").value == "") { + alert("用户名为必填项!"); + return false; + } + + + $.ajax({ + //几个参数需要注意一下 + type: "POST",//方法类型 + dataType: "text",//预期服务器返回的数据类型 + url: "http://qcloud-sh1.chewrobot.com:8081/bot/update2" ,//url + data:{ + "userName":document.getElementById("txtUserName").value, + "configData": text, + "type":"batch_update", + "configId":0 + }, + success: function (result) { + var list = result.split("---") + var str = ""; + for (var i = 0;i < list.length;i++){ + str += '
    '+list[i]+'
    ' + } + document.getElementById("returnInfo").innerHTML = str + }, + error : function(res) { + // document.getElementById("returnInfo").appendChild() = res; + } + }); + } + diff --git a/web/update3.html b/web/update3.html index 0dc0100..87c94ad 100644 --- a/web/update3.html +++ b/web/update3.html @@ -16,6 +16,7 @@

    内 容:

    关键词替换:

     

    + @@ -54,10 +55,12 @@ //几个参数需要注意一下 type: "POST",//方法类型 dataType: "text",//预期服务器返回的数据类型 - url: "getConfig" ,//url + url: "http://qcloud-sh1.chewrobot.com:8081/bot/update2" ,//url data:{ "userName":document.getElementById("txtUserName").value, - "config_string": text + "configData": text, + "type":"batch_update", + "configId":0 }, success: function (result) { var list = result.split("---")