将解析后的字符串列表添加到字典wpf c#
我试图将话语解析成单词,并将这些单词保存在列表中。我想用话语编号键将每个列表添加到字典中。我想把每一种话语与其他话语进行相似性比较。我试过了,但没用。谁能帮帮我吗 谢谢将解析后的字符串列表添加到字典wpf c#,c#,wpf,list,dictionary,C#,Wpf,List,Dictionary,我试图将话语解析成单词,并将这些单词保存在列表中。我想用话语编号键将每个列表添加到字典中。我想把每一种话语与其他话语进行相似性比较。我试过了,但没用。谁能帮帮我吗 谢谢 public string[] utterance = new string[4]; Dictionary<string, List> wording = new Dictionary<string, List>(); public void splitit() {
public string[] utterance = new string[4];
Dictionary<string, List> wording = new Dictionary<string, List>();
public void splitit()
{
utterance[0] = "Fish attacked Nemo's parents";
utterance[1] = "Only one fish egg left after fish attacked Nemo's parents and that was Nemo.";
utterance[2] = "Nemo grow up and went to school.";
utterance[3] = "Nemo got bored during the lecture and went to ocean with his friends.";
for (int x=0; x < 4; x++)
{
string[] words = utterance[x].Split(' ');
List<string> Tokens = new List<string>();
foreach (string word in words)
{
Tokens.Add(word);
}
//string parsed = Tokens[1];
//foreach(string tok in Tokens)
//{
// List<string> listing = new List<string>();
// listing.Add (tok);
// wording.Add("utterance"+x, listing);
// //listBox1.Items.Add("utterance"+x+" : "+tok);
//}
for (int w = 0; w < 4; w++)
{
wording.Add("utterance"+x,Tokens);
}
}
}
}
只需改变几件事: 像这样声明
discitionary
:Dictionary
,最后,像这样为每个句子添加tockenswording.add(话语[w],标记)代码>
字典用语=新字典();
公共信息技术
{
话语[0]=“鱼袭击了尼莫的父母”;
话语[1]=“鱼攻击尼莫的父母后,只剩下一个鱼卵,那个就是尼莫。”;
话语[2]=“尼莫长大了,去上学了。”;
话语[3]=“尼莫在讲座中感到无聊,于是和他的朋友们去了海洋。”;
对于(int x=0;x<4;x++)
{
字符串[]单词=话语[x]。拆分(“”);
列表标记=新列表();
foreach(单词中的字符串)
{
添加(单词);
}
//已解析字符串=令牌[1];
//foreach(令牌中的字符串tok)
//{
//List listing=新列表();
//添加(tok);
//添加(“话语”+x,列表);
////listBox1.Items.Add(“话语”+x+:“+tok”);
//}
对于(int w=0;w<4;w++)
{
添加(话语[w],标记);
}
}
}
}公共字符串[]话语=新字符串[4];
字典用语=新字典();
公共信息技术
{
话语[0]=“鱼袭击了尼莫的父母”;
话语[1]=“鱼攻击尼莫的父母后,只剩下一个鱼卵,那个就是尼莫。”;
话语[2]=“尼莫长大了,去上学了。”;
话语[3]=“尼莫在讲座中感到无聊,于是和他的朋友们去了海洋。”;
对于(int x=0;x<4;x++)
{
添加(“话语”+x,话语[x].Split(“”).ToList());
}
}
请定义“它不起作用”
string[] words = utterance[x].Split(' ');
ArrayList Tokens = new ArrayList();
foreach (string word in words)
{
Tokens.Add(word);
}
ArrayList listing = new ArrayList();
foreach (string tok in Tokens)
{
listing.Add(tok);
}
wording.Add("utterance" + x, listing);
counting = wording["utterance0"].Count;
}
Dictionary<string, List<string>> wording = new Dictionary<string, List<string>>();
public void splitit()
{
utterance[0] = "Fish attacked Nemo's parents";
utterance[1] = "Only one fish egg left after fish attacked Nemo's parents and that was Nemo.";
utterance[2] = "Nemo grow up and went to school.";
utterance[3] = "Nemo got bored during the lecture and went to ocean with his friends.";
for (int x=0; x < 4; x++)
{
string[] words = utterance[x].Split(' ');
List<string> Tokens = new List<string>();
foreach (string word in words)
{
Tokens.Add(word);
}
//string parsed = Tokens[1];
//foreach(string tok in Tokens)
//{
// List<string> listing = new List<string>();
// listing.Add (tok);
// wording.Add("utterance"+x, listing);
// //listBox1.Items.Add("utterance"+x+" : "+tok);
//}
for (int w = 0; w < 4; w++)
{
wording.Add(utterance[w],Tokens);
}
}
}
public string[] utterance = new string[4];
Dictionary<string, List<string>> wording = new Dictionary<string, List<string>>();
public void splitit()
{
utterance[0] = "Fish attacked Nemo's parents";
utterance[1] = "Only one fish egg left after fish attacked Nemo's parents and that was Nemo.";
utterance[2] = "Nemo grow up and went to school.";
utterance[3] = "Nemo got bored during the lecture and went to ocean with his friends.";
for (int x=0; x < 4; x++)
{
wording.Add("utterance"+x,utterance[x].Split(' ').ToList());
}
}