string originaltext = "A man meet a man";
string spintext ="A {man|Person} meet a {man|male}";
每个原文都可以有一些自旋选项,所以每个单词都是起始索引指向自旋选项单词...
例如:“man”的第一次出现有自旋选项“{man|Person}”。“man”的第二次出现有自旋选项“{man|male}”...
如果原文改变了,那么所有的词索引都在改变......所以我想指出新的索引......
public Dictionary<int, SpintaxMappedValue> SpintaxListDict
{
get
{
return _spintaxListDict;
}
set
{
_spintaxListDict = value;
}
}
internal static void AlterSpintaxList(string _NeworiginalText)
{
//Build new dictionary for current text
var _NeworiginalTextDict = Regex.Matches(_NeworiginalText, @"\b\w+\b").Cast<Match>().ToDictionary(m => m.Index, m => m.Value);
//Comparing old original value dict with new original value dict
bool dictionariesEqual =
_NeworiginalTextDict.Keys.Count == Init.SpintaxEditorPropertyMain.OriginalTextDict.Keys.Count &&
_NeworiginalTextDict.Keys.All(k => Init.SpintaxEditorPropertyMain.OriginalTextDict.ContainsKey(k) &&
object.Equals(Init.SpintaxEditorPropertyMain.OriginalTextDict[k], _NeworiginalTextDict[k]));
//do mapping if dictionaries are not Equal
if (dictionariesEqual == false)
{
Dictionary<int, SpintaxMappedValue> TempSpintaxDict = new Dictionary<int, SpintaxMappedValue>(Init.SpintaxEditorPropertyMain.SpintaxListDict);
Dictionary<int, SpintaxMappedValue> NewSpintaxListDict = new Dictionary<int, SpintaxMappedValue>();
foreach (KeyValuePair<int, SpintaxMappedValue> olditem in TempSpintaxDict)
{
foreach (KeyValuePair<int, string> newitem in _NeworiginalTextDict)
{
if (olditem.Key != newitem.Key)
{
if (olditem.Value.OriginalWord == newitem.Value)
{
//if (newitem.Key > olditem.Key)
//{
olditem.Value.OriginalWordStartingPosition = newitem.Key;
olditem.Value.SpinWordStartingPosition = newitem.Key;
NewSpintaxListDict.Add(newitem.Key, olditem.Value);
//}
break;
}
}
}
}
Init.SpintaxEditorPropertyMain.SpintaxListDict = new Dictionary<int, SpintaxMappedValue>(NewSpintaxListDict);
}
}
这就是我正在做的...
这个字典键是字符串中每个单词的索引
请帮助我提前谢谢!