/// <summary> /// 分词 /// </summary> /// <param name="strSentence"></param> /// <returns></returns> public static List <string> GetTokenList(string strSentence) { AnalyzeRequest a = new AnalyzeRequest(); a.Text = new string[] { strSentence }; a.Tokenizer = TokenizerName; var result = client.Analyze(a); if (result.Tokens == null) { return(null); } return(result.Tokens.Select(x => x.Token).ToList <string>()); }
public List <AnalyzeResult> GetAnalyzeResults(ElasticClient client, string analyzeStr) { var analyzeResponse = client.Analyze(a => a .Analyzer("ik_smart") .Text(analyzeStr) ); List <AnalyzeResult> AnalyzeResult = new List <AnalyzeResult>(); foreach (var item in analyzeResponse.Tokens) { AnalyzeResult.Add(new AnalyzeResult(item.Token, item.StartOffset.ToString(), item.EndPostion.ToString())); } AnalyzeResult.Count(); return(AnalyzeResult); }
public static void Test() { ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200")); ElasticClient client = new ElasticClient(settings); var analyzeResponse = client.Analyze(a => a .Analyzer("vi_analyzer") //.Tokenizer("vi_tokenizer") .Text("nước hoa có khác nhau giữa người này với người khác") .Filter("lowercase") ); Console.OutputEncoding = UTF8Encoding.UTF8; foreach (var analyzeToken in analyzeResponse.Tokens) { Console.WriteLine($"{analyzeToken.Token}"); } }
public void BuildInBasicAnalyze() { var analyzeResponse = _client.Analyze(a => a.Analyzer("standard").Text("F# is THE SUPERIOR language :)")); PrintResponse(analyzeResponse); }