【发布时间】:2014-10-26 07:55:18
【问题描述】:
基本上,
- 有一个句子列表。
- 有一个实体列表(基本上是特定的词)
- 以另一种方法插入数据库的 sql 查询
我正在寻找一种方法来遍历句子并检查是否在每个句子中找到了列表中声明的任何“实体”。如果将它们添加到可能的多维数组中,实体可以以句子的格式存储并将它们传递给 Sql 查询方法。
到目前为止,这就是我所拥有的:
List<string> sentenceList = new List<string>(new String[]
{"Gerald has a nice car", "Rachel has a cute cat"});
List<string> entityList = new List<string>(new String[]
{ "Gerald", "car", "Rachel", "cat" });
foreach (string sentence in sentenceList)
{
string currentSentence = sentence;
foreach(string entity in entityList)
if (currentSentence.Contains(entity))
{
This is where I need help with the code :)
//Add them as strings or an array and pass them to the method
//to be added in to table columns
}
基本喜欢:
杰拉德的车不错
瑞秋有一只可爱的猫
应存储为:
杰拉德,汽车
瑞秋,猫
有什么方法可以将句子中的每个实体添加到每个句子的列表或数组或一组字符串中,就像上面的输出示例中显示的那样? (连续)
“.Contains”可以工作,但也欢迎任何替代算法:) 提前谢谢你
【问题讨论】:
-
您的问题到底是什么?看起来您已经有了解决方案? (顺便说一句,不需要 currentSentence 变量)
-
我需要通过将它们添加到数组中来编写代码,以便可以将句子中的每个实体添加到每个句子的表条目中@Sayse
-
啊,所以你在为评论位挣扎?
标签: c# arrays list foreach find