简体   繁体   English

如何在C#中的文本文件中嵌入变量

[英]how to embed variables in text file in C#

I have a text file that has score of about 14000 words like below, 我有一个文本文件,得分约为14000字,如下所示,

accomplished#a  0.28448
accomplishment#n    0.76255
accurate#a  0.60503
accurately#r    0.15754
achievable#a    0.15793
achievement#n   0.57006
acumen#n    0.17703
adaptable#a 0
adaptive#a  0.15793

currently I'm getting score of each word in query by matching each word in query with values in this text file that is external to program, for example, if sentence if "I accomplished it accurately" , it will retrieve score 0.28448 for accomplished and 0.15754 for accurately from text file. 目前,我通过将查询中的每个单词与程序外部的此文本文件中的值进行匹配来获取查询中每个单词的得分,例如,如果句子“我准确地完成了它”,它将检索得分0.28448以完成和0.15754,用于精确来自文本文件。 But I think this is not proper way to do this, and it will more fast if I could define this values somewhere in my c# code or embed this text file permanently in my project. 但是我认为这不是执行此操作的正确方法,如果我可以在c#代码中的某个位置定义此值或将该文本文件永久嵌入到我的项目中,它将更快。 How can do this? 怎么办呢?

Th proper way is to load this file once in a Dictionary<string, int> , possibly at the startup of the application. 正确的方法是在Dictionary<string, int>一次加载此文件,可能在应用程序启动时加载。

Then look up your words in the dictionary to retrieve their scores. 然后在字典中查找您的单词以检索其分数。 This will be very efficient, even for a large number of words. 即使对于大量单词,这也将非常有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM