> 아래예제는 "specifically", "analyses", "run" 가 포함된 문장을 반환합니다.
// 검색할 단어 Array
string[] wordsToMatch = { "specifically", "analyses", "run" };
> 텍스트를 문장으로 분할을 먼저 합니다.
// Split 구분자
string[] sentences = text.Split(new char[] { '.', '?', '!' });
> 문장을 각 단어가 포함된 문자열 배열로 분할합니다.
var sentenceQuery = from sentence in sentences
let w = sentence.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' },
StringSplitOptions.RemoveEmptyEntries)
where w.Distinct().Intersect(wordsToMatch).Count() == wordsToMatch.Count()
select sentence;
public class Example
{
public static void Main()
{
Console.Write("<< 특정 단어가 포함된 문장을 쿼리하는 방법 >> \n");
string text = @"Prism is specifically formatted for the analyses you want to run, " +
@"including analysis of quantitative and categorical data." +
@"This makes it easier to enter data correctly," +
@"choose suitable analyses, and create stunning graphs.";
// Split 구분자
string[] sentences = text.Split(new char[] { '.', '?', '!' });
// 검색할 단어 Array
string[] wordsToMatch = { "specifically", "analyses", "run" };
var sentenceQuery = from sentence in sentences
let w = sentence.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' },
StringSplitOptions.RemoveEmptyEntries)
where w.Distinct().Intersect(wordsToMatch).Count() == wordsToMatch.Count()
select sentence;
foreach (string str in sentenceQuery)
{
Console.WriteLine(str);
}
Console.WriteLine(System.Environment.NewLine);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}