我有一串单词,我想从每个单词中删除一些后缀和前缀(位于数组中),然后将词干存储在字符串中.请问有什么建议吗?提前致谢.
后缀和前缀的总数超过100,表示它们的效果更好?阵列?正则表达式?请问有什么建议吗?
public static string RemoveFromEnd(this string str, string toRemove)
{
if (str.EndsWith(toRemove))
return str.Substring(0, str.Length - toRemove.Length);
else
return str;
}
Run Code Online (Sandbox Code Playgroud)
这可以使用后缀,前缀怎么样?有两种后缀和前缀的快速方法吗?我的字符串太长了.
浏览字典的更好方法是什么?当我有IDictionary时,我曾经使用下面的代码:
假设我有IDictionary命名 freq
IEnumerator enums = freq.GetEnumerator();
while (enums.MoveNext())
{
string word = (string)enums.Key;
int val = (int)enums.Value;
.......... and so on
}
Run Code Online (Sandbox Code Playgroud)
但现在,我想用字典做同样的事情
是否可以使用适应度值评估种群中的每个个体而不用如下伪代码找到概率
For all members of population
sum += fitness ( member)
End for
Loop until new population is full
Do this twice
Number = Random between 0 and sum
Currentfitness = 0.0
For each member in population
Currentfitness += fitness (member)
if Number > Currentfitness then select member
End for
End
Create offspring
End loop
Run Code Online (Sandbox Code Playgroud)
代码的以下部分是做什么的?
Do this twice
Run Code Online (Sandbox Code Playgroud)
我真的很困惑轮盘赌是如何选择一对父母的。有什么帮助吗?提前致谢
我使用以下代码来读取和组合一个字符串中的文本数:
foreach (string path in filePaths)
{
StreamReader singfile = new StreamReader(path);
string file_text = singfile.ReadToEnd();
combinetexts += file_text + "\n";
fs.Close();
}
Run Code Online (Sandbox Code Playgroud)
据我所知,字符串combinetexts将复制n次文件路径的数量.是否可以使用字符串生成器来执行此操作?我尝试过,但事实并非如此.提前致谢.
假设我有以下内容:
public static string testtok( string ss)
{
if ......
return ss=................;
return ss;
}
Run Code Online (Sandbox Code Playgroud)
我能做那样的事吗?
private string stemmingwords (List<string> wordstokens)
{
return string.Join(" ", wordstokens).Where(x => testtok(x));
}
Run Code Online (Sandbox Code Playgroud)
那为什么不起作用?请帮忙.