我有很多短语,例如
"Nola jumped off the cliff"
"Loroy jumped off the cliff"
"Nola jumped off the couch"
"Leroy lept off the couch"
Run Code Online (Sandbox Code Playgroud)
我需要找到一个不同单词的短语中的每个点,并将该单词添加到节点,该节点是可以在短语中的该位置使用的单词列表.所以我们最终会结束.
"Node1(1) Node2(1) off the Node3(1)"
"Node1(2) Node2(1) off the Node3(1)"
...etc
Run Code Online (Sandbox Code Playgroud)
其中节点1表示名称列表(Nola,Leroy),node2表示动作列表(跳跃,lept),node3最终表示位置列表(悬崖,沙发)
我们的想法是获取短语列表,并让它自动创建节点,并用短语中可以在该节点上使用的单词填充它.
那么,我将如何生成短语节点列表?我无法弄清楚如何比较两个句子,看看它们是否完全相同,减去一个单词.
第二,一旦我设置了节点,比较所有节点组合以获得新匹配的最佳方法是什么?(希望有道理)
我试图找到一种比下面的代码更优雅的方法,以基于其中一个单词的索引获取句子列表。因此,例如,如果我给它一个单词列表,例如用户名,它会找到所有这些单词的索引(此操作已经完成,并且是GetWordsMatches方法),然后使用该单词的索引,我想抓住整个句子。
我有两个问题,一个,我无法弄清楚如何在单词上一个单词之前看一眼,只是结束一两个,我无法弄清楚如果最后一个单词匹配不包含单词,如何防止它崩溃文件结束前的句点。
public static List<string> GetSentencesFromWords(List<string> Words, string FileContents)
{
List<string> returnList = new List<string>();
MatchCollection mColl = GetWordsMatches(Words,FileContents);
foreach (Match ma in mColl)
{
int tmpInd = ma.Index;
int endInd = FileContents.IndexOf(".", tmpInd);
string tmp = FileContents.Substring(tmpInd,endInd);
returnList.Add(tmp);
}
return returnList;
}
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方法可以做到这一点?
试图转换一些代码,但对于我所有的谷歌搜索,我无法弄清楚如何转换这一点.
float fR = fHatRandom(fRadius);
float fQ = fLineRandom(fAngularSpread ) * (rand()&1 ? 1.0 : -1.0);
float fK = 1;
Run Code Online (Sandbox Code Playgroud)
这一点
(rand()&1 ? 1.0 : -1.0);
Run Code Online (Sandbox Code Playgroud)
我弄不清楚.