简体   繁体   中英

how to embed variables in text file in C#

I have a text file that has score of about 14000 words like below,

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. 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. 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.

Then look up your words in the dictionary to retrieve their scores. This will be very efficient, even for a large number of words.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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