|
|
|
@ -1,20 +1,17 @@
|
|
|
|
|
package com.example.cmknowledgegraph;
|
|
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
|
|
|
|
|
import com.example.PersonalCenter.Search;
|
|
|
|
|
import com.hankcs.hanlp.seg.common.Term;
|
|
|
|
|
import com.hankcs.hanlp.tokenizer.StandardTokenizer;
|
|
|
|
|
import com.example.PersonalCenter.SearchServiceGet;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
@ -23,49 +20,30 @@ public class SearchContent extends Fragment {
|
|
|
|
|
|
|
|
|
|
public static List<Set<String>> a;
|
|
|
|
|
public static int k=0;
|
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
|
// Inflate the layout for this fragment
|
|
|
|
|
return inflater.inflate( R.layout.activity_search, container, false ); //要加载的layout文件
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
EditText search_edit = getActivity().findViewById(R.id.search_edit);
|
|
|
|
|
|
|
|
|
|
ImageButton search_btn = (ImageButton) getActivity().findViewById(R.id.search_btn);
|
|
|
|
|
|
|
|
|
|
search_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
Log.i("haha","=======Oncli");
|
|
|
|
|
//查找逻辑
|
|
|
|
|
List<Term> termList = StandardTokenizer.segment("什么是糖尿病");
|
|
|
|
|
System.out.println(termList);
|
|
|
|
|
String sickname = search_edit.getText().toString();
|
|
|
|
|
Search search = new Search(sickname);
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
SearchContent.a = search.search();
|
|
|
|
|
SearchContent.k = 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
while(SearchContent.k==0) {Log.i("i","i");}
|
|
|
|
|
if(SearchContent.a!=null){
|
|
|
|
|
String[] medicines = a.get(0).toArray(new String[0]);
|
|
|
|
|
String[] reasons = a.get(1).toArray(new String[0]);
|
|
|
|
|
ListView lv = getActivity().findViewById(R.id.listView1);
|
|
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,medicines);
|
|
|
|
|
lv.setAdapter(adapter);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
SearchContent.k=0;
|
|
|
|
|
SearchContent.a=null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImageButton search_btn = (ImageButton) getActivity().findViewById(R.id.search_btn);
|
|
|
|
|
search_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
Log.i("haha", "=======Oncli");
|
|
|
|
|
//点击查找按钮之后,去除输入的句子,传给后台
|
|
|
|
|
String inputContent = search_edit.getText().toString();
|
|
|
|
|
SearchServiceGet.executeSearchGet(inputContent);
|
|
|
|
|
//执行到这里,已经把data里的数据取出来了或没有,但是都要跳转页面到SearchEntryActivity页面
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setClass(getActivity(), SearchEntryActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|