From 581f8cbb1e9b309bf81c9406c52deb85b093fd2d Mon Sep 17 00:00:00 2001 From: hanxueqing <1045352474@qq.com> Date: Sat, 4 Jan 2020 18:17:38 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' # Conflicts: # app/src/main/res/layout/activity_main.xml --- .../PersonalCenter/SearchServiceGet.java | 35 ++++------ .../cmknowledgegraph/ConditionCode.java | 10 +++ .../example/cmknowledgegraph/ContentData.java | 17 +++++ .../cmknowledgegraph/SearchContent.java | 20 ++---- .../cmknowledgegraph/SearchEntryActivity.java | 68 ++++++------------- .../com/example/cmknowledgegraph/abcd.java | 44 ------------ .../res/layout/activity_search_content.xml | 15 ---- app/src/main/res/layout/cmkg_item.xml | 5 +- app/src/main/res/layout/cmkg_list_item.xml | 16 +++++ 9 files changed, 84 insertions(+), 146 deletions(-) create mode 100644 app/src/main/java/com/example/cmknowledgegraph/ConditionCode.java create mode 100644 app/src/main/java/com/example/cmknowledgegraph/ContentData.java delete mode 100644 app/src/main/java/com/example/cmknowledgegraph/abcd.java delete mode 100644 app/src/main/res/layout/activity_search_content.xml diff --git a/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java b/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java index 9aa4c29..d8df8e7 100644 --- a/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java +++ b/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java @@ -2,8 +2,7 @@ package com.example.PersonalCenter; import android.util.Log; -import com.alibaba.fastjson.JSON; - +import net.sf.json.JSONArray; import net.sf.json.JSONObject; import java.io.BufferedReader; @@ -15,16 +14,14 @@ import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.util.ArrayList; -import java.util.Map; public class SearchServiceGet { - public static ArrayList label=new ArrayList();//存储标签内容 public static ArrayList content=new ArrayList();//存储数据内容 - public static Map mapType; + public static String name_back; public static boolean SearchSuccess=false; - public static String executeSearchGet(String name){ + public static void executeSearchGet(String name){ HttpURLConnection connection = null; InputStream in = null; @@ -55,24 +52,20 @@ public class SearchServiceGet { //开始解析返回的数据 JSONObject jo=JSONObject.fromObject(response.toString()); - String message=jo.getString("message"); int code=jo.getInt("code"); - if((message.equals("病症查询成功")||message.equals("药品查询成功"))&&code==200){ - //查询成功,在开始解析数据 - //把data里的数据转换为Map,遍历map,打印键值对 - String data=jo.get("data").toString(); - mapType = JSON.parseObject(data,Map.class); - for (Object obj : mapType.keySet()) { - //把键值对放入队列中,前提是标签的内容不为空 - if(mapType.get(obj)!=null) { - label.add(obj.toString()); - content.add(mapType.get(obj).toString()); - System.out.println("key为:" + obj + "值为:" + mapType.get(obj)); - } + if(code!=0){ //查询成功,在开始解析数据 + name_back=jo.getString("message");//查询的主语 + //把data看作一个JSONObject,无论里面由多少元素,都转换为JSONArray,存在数组里 + JSONObject jo_data=jo.getJSONObject("data"); + JSONArray data_arr=null; + jo_data.toJSONArray(data_arr); + //遍历data_arr,把里面的数据放入ArrayList content里 + for(int i=0;i adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, SearchServiceGet.label); - * ArrayAdapter adapter_1 = new ArrayAdapter(this,android.R.layout.simple_list_item_1, SearchServiceGet.content); - * - * lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - * @Override - * public void onItemClick(AdapterView adapterView, View view, int i, long l) { - * //根据点击不同的item跳转到不同的页面 - * // switch (i){ - * // case 0: - * // intent.putExtra("label",SearchServiceGet.label.get(1)); - * // startActivity(intent); - * // break; - * // case 1: - * // intent.putExtra("label",SearchServiceGet.label.get(2)); - * // startActivity(intent); - * // break; - * // } - * - * //做个小测试,做隐藏动画 - * switch (listView.getVisibility()) { - * // 若显示,则隐藏 - * case 0: - * listView.setVisibility(View.GONE); - * break; - * // 若隐藏,则显示 - * case 8: - * listView.setVisibility(View.VISIBLE); - * break; - * default: - * break; - * } - * - * } - * }); - * lv.setAdapter(adapter); - * listView.setAdapter(adapter_1); - */ } public void onItemExpend(boolean expend) { @@ -82,6 +42,16 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV mCardStack.setAdapter(adapter); mCardStack.setItemExpendListener(this); + /** + * 这里分很多种情况,目前有四种模板,每种模板对应的标题内容可能有些不同 + * 为了方便我们先不删除原有模板的items,我们点开之后有几种情况 + * 病-症状:标题是名字,内容是症状 + * 病-治疗药品:标题是药的名字,内容是药的用法(暂时不做) + * 药-用法:标题是药的名字,内容是药的用法 + * 药-作用:标题是药的名字,内容是药的用法 + * + * 每种不同的情况对应不同的状态码,用接口实现状态码 + */ List> lists = new LinkedList<>(); for(int i = 0;i<4;i++) { @@ -94,8 +64,8 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV } adapter.updateData(Arrays.asList(color),lists); - //mCardStack.setAnimatorAdapter(new AllMoveDownAnimatorAdapter(mCardStack)); - //mCardStack.setAnimatorAdapter(new UpDownAnimatorAdapter(mCardStack)); - //mCardStack.setAnimatorAdapter(new UpDownStackAnimatorAdapter(mCardStack)); + mCardStack.setAnimatorAdapter(new AllMoveDownAnimatorAdapter(mCardStack)); + mCardStack.setAnimatorAdapter(new UpDownAnimatorAdapter(mCardStack)); + mCardStack.setAnimatorAdapter(new UpDownStackAnimatorAdapter(mCardStack)); } } diff --git a/app/src/main/java/com/example/cmknowledgegraph/abcd.java b/app/src/main/java/com/example/cmknowledgegraph/abcd.java deleted file mode 100644 index ed15d8f..0000000 --- a/app/src/main/java/com/example/cmknowledgegraph/abcd.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.example.cmknowledgegraph; - -import com.hankcs.hanlp.HanLP; -import com.hankcs.hanlp.suggest.Suggester; - -import java.util.List; - -public class abcd { - - public void init(){ - - - /** - * 查询逻辑 - * 一般来说,查询是 头痛+怎么办 胃+不+舒服 眼睛+痛 冷水喝多了,肚子痛(肚子痛,喝,冷水) - * 不会加主语 - * 大部分是 主体加动词 - * 选用 关键词提取和标准分词, - */ - String content = "我的胃不舒服"; - List keywordList = HanLP.extractKeyword(content, 5); - System.out.println(keywordList); - - - //关键词联想 - Suggester suggester = new Suggester(); - String[] titleArray = - ( - "威廉王子发表演说 呼吁保护野生动物\n" + - "《时代》年度人物最终入围名单出炉 普京马云入选\n" + - "“黑格比”横扫菲:菲吸取“海燕”经验及早疏散\n" + - "日本保密法将正式生效 日媒指其损害国民知情权\n" + - "英报告说空气污染带来“公共健康危机”" - ).split("\\n"); - for (String title : titleArray) - { - suggester.addSentence(title); - } - - System.out.println(suggester.suggest("发言", 1)); // 语义 - System.out.println(suggester.suggest("危机公共", 1)); // 字符 - System.out.println(suggester.suggest("mayun", 1)); // 拼音 - } -} diff --git a/app/src/main/res/layout/activity_search_content.xml b/app/src/main/res/layout/activity_search_content.xml deleted file mode 100644 index bacfcf8..0000000 --- a/app/src/main/res/layout/activity_search_content.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/cmkg_item.xml b/app/src/main/res/layout/cmkg_item.xml index 0ab89e9..efc4c7e 100644 --- a/app/src/main/res/layout/cmkg_item.xml +++ b/app/src/main/res/layout/cmkg_item.xml @@ -6,6 +6,9 @@ android:orientation="vertical" android:padding="16dp" > + + diff --git a/app/src/main/res/layout/cmkg_list_item.xml b/app/src/main/res/layout/cmkg_list_item.xml index 83f1b61..dde8225 100644 --- a/app/src/main/res/layout/cmkg_list_item.xml +++ b/app/src/main/res/layout/cmkg_list_item.xml @@ -88,6 +88,22 @@ android:layout_marginLeft="25dp" android:layout_marginStart="25dp" /> + + + \ No newline at end of file