# Conflicts: # app/src/main/java/com/example/cmknowledgegraph/LoginActivity.javaongbodev
commit
63ef8e80a4
@ -0,0 +1,46 @@
|
|||||||
|
package com.example.PersonalCenter;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.hankcs.hanlp.HanLP;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Search {
|
||||||
|
public String sickname;
|
||||||
|
public Search(String sickname){
|
||||||
|
this.sickname = sickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Set<String>> search(){
|
||||||
|
Log.i("search","sick执行了");
|
||||||
|
//找出对应的8个关键字
|
||||||
|
List<String> keywordList = HanLP.extractKeyword(sickname,8);
|
||||||
|
|
||||||
|
//针对每一个sickname来查找一下能不能够找到相应的名字
|
||||||
|
Set<String> mediciesSet = new HashSet<String>();
|
||||||
|
Set<String> reasonsSet = new HashSet<String>();
|
||||||
|
for(String i: keywordList){
|
||||||
|
Log.i("关键词提取",i+"ha");
|
||||||
|
String resq = SearchServiceGet.executeSearchGet(i,"/Search");
|
||||||
|
|
||||||
|
if(!resq.equals("fail")) {
|
||||||
|
String[] me_rea = resq.split("-");
|
||||||
|
String[] medicines = me_rea[0].split("\\|");
|
||||||
|
for(String j: medicines) mediciesSet.add(j);
|
||||||
|
String[] reasons = me_rea[1].split("\\|");
|
||||||
|
for(String j: reasons) reasonsSet.add(j);
|
||||||
|
List<Set<String>> a = new ArrayList<Set<String>>();
|
||||||
|
a.add(mediciesSet);
|
||||||
|
a.add(reasonsSet);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.example.PersonalCenter;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.ProtocolException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class SearchServiceGet {
|
||||||
|
public static String executeSearchGet(String sickname,String address){
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
InputStream in = null;
|
||||||
|
|
||||||
|
String Url = "http://106.54.210.208:8080/ChineseM"+address;
|
||||||
|
String path = Url + "?sickname="+sickname;
|
||||||
|
URL url = null;
|
||||||
|
try {
|
||||||
|
url = new URL(path);
|
||||||
|
connection = (HttpURLConnection)url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setConnectTimeout(100000);//建立连接超时
|
||||||
|
connection.setReadTimeout(80000);//传输数据超时
|
||||||
|
in = connection.getInputStream();
|
||||||
|
|
||||||
|
BufferedReader reader = null;//输入流
|
||||||
|
String line = "";//读取返回的每一行
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
while((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
//这时候response就是一个连续字符串了吧
|
||||||
|
Log.i("response+++++",response+"返回值");
|
||||||
|
return response.toString();
|
||||||
|
//
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
if(reader!=null){
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ProtocolException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue