Hi I am trying to read tags on a list of words, the list has words like (TMConnects(MEN) what(WP) happened(VB) to(TO) your(ADV) my(ADV) tm(N) website(N) i(N) can(ADV) access(N) to(TO) view(N) my(ADV) bills(N) ) I am trying to use if statements and regular expressions to read each tag so I can categorise the words appropriately.
Here is the code I tried
foreach (string word in tokensList)
{
//Verbs
Match match_verb = Regex.Match(word, @"[a-zA-Z]+\(vb\)");
if (match_verb.Success)
{
Console.WriteLine(word + "v");
Verbs.Add(word);
}
else
{
//Nouns
Match match_noun = Regex.Match(word, @"[a-zA-Z]+\(n\)");
if (match_noun.Success)
{
Console.WriteLine(word + "n");
Nouns.Add(word);
}
else
{
//Adverb(Ad)
Match match_adverb = Regex.Match(word, @"[a-zA-Z]+\(adv\)");
if (match_adverb.Success)
{
Console.WriteLine(word + "adv");
Adverbs.Add(word);
}
else
{
//Adjective(Adj)
Match match_adj = Regex.Match(word, @"[a-zA-Z]+\(adj\)");
if (match_adj.Success)
{
Console.WriteLine(word + "adj");
Adjectives.Add(word);
}
else
{
//Mention(Men)
Match match_men = Regex.Match(word, @"[a-zA-Z]+\(men\)");
if (match_men.Success)
{
Console.WriteLine(word + "men");
Mentions.Add(word);
}
else
{
//Object(KNK)
Match match_obj = Regex.Match(word, @"[a-zA-Z]+\(knk\)");
if (match_obj.Success)
{
Console.WriteLine(word + "obj");
Objects.Add(word);
}
else
{
//Features(KT)
Match match_feature = Regex.Match(word, @"[a-zA-Z]+\(kt\)");
if (match_feature.Success)
{
Console.WriteLine(word + "ft");
Features.Add(word);
}
else
{
//break;
}
}
}
}
}
}
Please help me.
Aucun commentaire:
Enregistrer un commentaire