[英]How to add a Dictionary<string,List<string>> to a DataTable in C#?
[英]Add parsed string list to Dictionary wpf c#
我試圖將話語解析為單詞並將這些單詞保留在列表中。 我想用話語數字鍵將每個列表添加到字典中。 我想比較每個話語與其他話語的相似性。 我試過這個並沒有用。 誰能幫幫我嗎!
謝謝
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);
}
}
}
}
我這樣解決了這個問題,它現在有效:
for(int x = 0; x <36; x ++){
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;
}
只需改變幾件事:
像這樣聲明Disctionary
: Dictionary<string, List<string>>
並在最后,為每個句子添加tockens,如此wording.Add(utterance[w],Tokens);
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());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.